On Sun, 19 May 2019 11:04:26 GMT, Ron Tarrant wrote:
On Sun, 19 May 2019 10:29:54 GMT, Ron Tarrant wrote:
I found a solution in an example on the D forum.
I won't outline the details of the changes I made, but here's the updated code for future reference. I will make this one cautionary note:
This is only a test. This code makes for one ugly demo. Use at your own risk. May cause disturbing nightmares or afterimages.
// Test Rig Foundation for Learning GtkD Coding
import std.stdio;
import gtk.MainWindow;
import gtk.Main;
import gtk.Box;
import gtk.Widget;
import gtk.Button;
import gtk.Label;
import gtk.CssProvider;
import gtk.StyleContext;
import gdk.Screen;
import gdk.Display;
void main(string[] args)
{
Main.init(args);
TestRigWindow myTestRig = new TestRigWindow("Test Rig");
Main.run();
} // main()
class TestRigWindow : MainWindow
{
AppBox appBox;
string cssName = "mywindow";
Screen screen;
CssProvider cssProvider;
string cssFile = "./theme.css";
StyleContext styleContext;
this(string title)
{
super(title);
setName(cssName);
writeln("window name: ", getName());
Display display = Display.getDefault();
Screen screen = display.getDefaultScreen();
cssProvider = new CssProvider();
cssProvider.loadFromPath(cssFile);
styleContext = new StyleContext();
styleContext.addProviderForScreen(screen, cssProvider, STYLE_PROVIDER_PRIORITY_APPLICATION);
addOnDestroy(&quitApp);
appBox = new AppBox();
add(appBox);
showAll();
} // this() CONSTRUCTOR
void quitApp(Widget widget)
{
writeln("Bye.");
Main.quit();
} // quitApp()
} // class myAppWindow
class AppBox : Box
{
CSSButton cssButton1, cssButton2;
CSSLabel cssLabel1, cssLabel2, cssLabel3;
string button1Text = "CSS Button 1", button2Text = "CSS Button 2";
string button1CSSName = "button1", button2CSSName = "button2";
string label1Text = "Hello 1", label2Text = "Hello 2 U", label3Text = "Hello 3";
string label1CSSName = "label1", label2CSSName = "label2",label3CSSName = "label3";
this()
{
super(Orientation.VERTICAL, 25);
cssButton1 = new CSSButton(button1Text, button1CSSName);
cssLabel1 = new CSSLabel(label1Text, label1CSSName);
cssLabel2 = new CSSLabel(label2Text, label2CSSName);
cssLabel3 = new CSSLabel(label3Text, label3CSSName);
cssButton2 = new CSSButton(button2Text, button2CSSName);
setHomogeneous(true);
// packStart(<child object>, false, false, 0); // LEFT justify
add(cssButton1);
add(cssLabel1);
add(cssLabel2);
add(cssLabel3);
add(cssButton2);
// packEnd(<child object>, false, false, 0); // RIGHT justify
} // this()
} // class AppBox
class CSSButton : Button
{
this(string textLabel, string cssName)
{
super(textLabel);
setName(cssName);
} // this()
} // class CSSButton
class CSSLabel : Label
{
this(string textLabel, string cssName)
{
super(textLabel);
setName(cssName);
} // this()
} // class CSSLabel
And the new theme.css file:
#mywindow
{
font-family: "Times New Roman";
font-size: 12px;
background-image: none;
background-color: blue;
}
button.text-button#button2
{
color: green;
background-image: none;
background-color: blue;
font-family: "Bodoni MT";
font-size: 20px;
text-decoration: underline;
}
button.text-button#button1
{
font-family: "Comic Sans MS";
font-size: 16px;
color: red;
background-image: none;
background-color: yellow;
}
label#label1
{
font-family: "Times New Roman";
color: red;
font-size: 26px;
background-color: yellow;
}
label#label2
{
color: green;
background-color: yellow;
}
label#label3
{
color: blue;
background-color: yellow;
}