On Wednesday, 15 June 2016 at 20:49:02 UTC, Gerald wrote:
On Wednesday, 15 June 2016 at 09:03:45 UTC, TheDGuy wrote:
Hello,
why does this code not work?
RGBA rgb = new RGBA(1,0.5,0.5,1.0);
Button btn_1 = new Button("Start");
btn_1.overrideBackgroundColor(StateFlags.NORMAL, rgb);
The color of btn_1 just doesn't change.
https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-background-color
Thanks for your reply, i now tried to use CSS instead:
import std.stdio;
import std.file;
import gtk.Main;
import gtk.MainWindow;
import gtk.CssProvider;
import gtk.Button;
import gdk.Display;
import gdk.Screen;
import gtk.StyleContext;
class Window : MainWindow{
this(int width, int height, string title){
super(title);
setDefaultSize(width, height);
Button btn = new Button("Test");
btn.setName("CssName");
string cssPath = "test.css";
CssProvider provider = new CssProvider();
provider.loadFromPath(cssPath);
Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
StyleContext.addProviderForScreen(screen, provider,
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
add(btn);
showAll();
}
}
void main(string[] args){
writeln(getcwd());
Main.init(args);
auto win = new Window(250,250,"Tutorial");
Main.run();
}
This is my CSS:
GtkWindow{
background-color:blue;
}
#CssName{
-GtkWidget-focus-line-width:0;
background-color:green;
color:green;
}
The text color is green but the button background color is still
default-gray!
I am also wondering how it is possible to change the button color
at runtime? In my opinion i don't think that CSS-based style has
alot of advantages over the commonly used object functions.