1 module fluid.default_theme;
2 
3 import fluid.node;
4 import fluid.frame;
5 import fluid.style;
6 import fluid.button;
7 import fluid.slider;
8 import fluid.backend;
9 import fluid.checkbox;
10 import fluid.radiobox;
11 import fluid.typeface;
12 import fluid.drag_slot;
13 import fluid.separator;
14 import fluid.file_input;
15 import fluid.text_input;
16 import fluid.popup_frame;
17 import fluid.number_input;
18 import fluid.scroll_input;
19 
20 /// Theme with no properties set.
21 ///
22 /// Unlike `Theme.init` or `null`, which will be replaced by fluidDefaultTheme or the parent's theme, this can be used as
23 /// a valid theme for any node. This makes it useful for automatic tests, since it has guaranteed no margins, padding,
24 /// or other properties that may confuse the tester.
25 Theme nullTheme;
26 
27 /// Default theme that Fluid will use if no theme is supplied. It is a very simple theme that does the minimum to make
28 /// the role of each node understandable.
29 Theme fluidDefaultTheme;
30 
31 static this() {
32 
33     Image loadBWImage(string filename)(int width, int height) @trusted {
34 
35         import std.array;
36         import std.format;
37         import std.algorithm;
38 
39         const area = width * height;
40 
41         auto file = cast(ubyte[]) import(filename);
42         auto data = file.map!(a => Color(0, 0, 0, a)).array;
43 
44         assert(data.length == area, format!"Wrong %s area %s, expected %s"(filename, data.length, area));
45 
46         // TODO use Format.alpha
47         return Image(data, width, height);
48 
49     }
50 
51     with (Rule) {
52 
53         nullTheme.add(
54             rule!Node(),
55         );
56 
57         fluidDefaultTheme.add(
58             rule!Node(
59                 typeface = Typeface.defaultTypeface,
60                 textColor = color("#000"),
61                 selectionBackgroundColor = color("#55b9ff"),
62             ),
63             rule!Frame(
64                 backgroundColor = color("#fff"),
65             ),
66             rule!Button(
67                 backgroundColor = color("#eee"),
68                 mouseCursor = FluidMouseCursor.pointer,
69                 margin.sideY = 2,
70                 padding.sideX = 6,
71 
72                 when!"a.isHovered"(backgroundColor = color("#ccc")),
73                 when!"a.isFocused"(backgroundColor = color("#ddd")),  // TODO use an outline for focus
74                 when!"a.isPressed"(backgroundColor = color("#aaa")),
75                 when!"a.isDisabled"(
76                     textColor = color("000a"),
77                     backgroundColor = color("eee5"),
78                     // TODO disabled should apply opacity, and should work for every node
79                 ),
80             ),
81             rule!TextInput(
82                 backgroundColor = color("#fff"),
83                 borderStyle = colorBorder(color("#aaa")),
84                 mouseCursor = FluidMouseCursor.text,
85 
86                 margin.sideY = 2,
87                 padding.sideX = 6,
88                 border.sideBottom = 2,
89 
90                 when!"a.isEmpty"(textColor = color("#000a")),
91                 when!"a.isFocused"(borderStyle = colorBorder(color("#555")))
92                     .otherwise(selectionBackgroundColor = color("#ccc")),
93                 when!"a.isDisabled"(
94                     textColor = color("#000a"),
95                     backgroundColor = color("#fff5"),
96                 ),
97             ),
98             rule!NumberInputSpinner(
99                 mouseCursor = FluidMouseCursor.pointer,
100                 extra = new NumberInputSpinner.Extra(loadBWImage!"arrows-alpha"(40, 64)),
101             ),
102             rule!AbstractSlider(
103                 backgroundColor = color("#ddd"),
104                 lineColor = color("#ddd"),
105             ),
106             rule!SliderHandle(
107                 backgroundColor = color("#aaa"),
108             ),
109             rule!ScrollInput(
110                 backgroundColor = color("#eee"),
111             ),
112             rule!ScrollInputHandle(
113                 backgroundColor = color("#aaa"),
114 
115                 when!"a.isHovered"(backgroundColor = color("#888")),
116                 when!"a.isFocused"(backgroundColor = color("#777")),
117                 when!"a.isPressed"(backgroundColor = color("#555")),
118                 when!"a.isDisabled"(backgroundColor = color("#aaa5")),
119             ),
120             rule!PopupFrame(
121                 border = 1,
122                 borderStyle = colorBorder(color("#555a")),
123             ),
124             /*rule!FileInputSuggestion(
125                 margin = 0,
126                 backgroundColor = color("#fff"),
127                 when!"a.isSelected"(backgroundColor = color("#55b9ff"))
128             ),*/
129             rule!Checkbox(
130                 margin.sideX = 8,
131                 margin.sideY = 4,
132                 border = 1,
133                 padding = 1,
134                 borderStyle = colorBorder(color("#555")),
135                 mouseCursor = FluidMouseCursor.pointer,
136 
137                 when!"a.isFocused"(backgroundColor = color("#ddd")),
138                 when!"a.isChecked"(
139                     extra = new Checkbox.Extra(loadBWImage!"checkmark-alpha"(64, 50)),
140                 ),
141             ),
142             rule!Radiobox(
143                 margin.sideX = 8,
144                 margin.sideY = 4,
145                 border = 0,
146                 borderStyle = null,
147                 padding = 2,
148                 extra = new Radiobox.Extra(1, color("#555"), color("#5550")),
149 
150                 when!"a.isFocused"(backgroundColor = color("#ddd")),
151                 when!"a.isChecked"(
152                     extra = new Radiobox.Extra(1, color("#555"), color("#000"))
153                 ),
154             ),
155             rule!Separator(
156                 padding = 4,
157                 lineColor = color("#ccc"),
158             ),
159             rule!DragSlot(
160                 padding.sideX = 6,
161                 padding.sideY = 0,
162                 border = 1,
163                 borderStyle = colorBorder(color("#555a")),
164                 backgroundColor = color("#fff"),
165                 margin = 4,  // for testing
166             ),
167             rule!DragHandle(
168                 lineColor = color("#ccc"),
169                 padding.sideX = 8,
170                 padding.sideY = 6,
171                 extra = new DragHandle.Extra(5),
172             ),
173         );
174 
175     }
176 
177 }