1 module nodes.checkbox;
2 
3 import fluid;
4 
5 @safe:
6 
7 @("Pressing the checkbox toggles its state")
8 unittest {
9 
10     int changed;
11 
12     auto root = checkbox(delegate {
13         changed++;
14     });
15 
16     root.runInputAction!(FluidInputAction.press);
17 
18     assert(changed == 1);
19     assert(root.isChecked);
20 
21     root.runInputAction!(FluidInputAction.press);
22 
23     assert(changed == 2);
24     assert(!root.isChecked);
25 
26 }
27 
28 @("Checkbox draws a checkmark when pressed")
29 unittest {
30 
31     auto theme = Theme(
32         rule!Checkbox(
33             Rule.margin = 0,
34             Rule.border = 1,
35             Rule.padding = 0,
36             Rule.borderStyle = colorBorder(color("#222")),
37         ),
38     );
39     auto input = checkbox();
40     auto test = testSpace(theme, input);
41     input.size = Vector2(10, 10);
42 
43     test.drawAndAssert(
44         input.drawsRectangle().ofColor("#222"),
45         input.drawsRectangle().ofColor("#222"),
46         input.drawsRectangle().ofColor("#222"),
47         input.drawsRectangle().ofColor("#222"),
48         input.drawsImage(Image.init),
49     );
50     assert(input.markImage == Image.init);
51 
52     input.toggle();
53     test.draw(),
54     test.drawAndAssert(
55         input.drawsRectangle().ofColor("#222"),
56         input.drawsImage(input.markImage),
57     );
58     assert(input.markImage != Image.init);
59 
60 }