1 module nodes.radiobox;
2 
3 import fluid;
4 
5 @safe:
6 
7 @("Radiobox cannot be unchecked")
8 unittest {
9 
10     auto group = new RadioboxGroup;
11     auto root = radiobox(group);
12     assert(!root.isChecked);
13 
14     root.runInputAction!(FluidInputAction.press);
15     assert( root.isChecked);
16 
17     // Pressing again doesn't uncheck the radiobox
18     root.runInputAction!(FluidInputAction.press);
19     assert( root.isChecked);
20 
21 }
22 
23 @("Checkmarks in different radioboxes in the same group is mutually exclusive")
24 unittest {
25 
26     auto group = new RadioboxGroup;
27     auto r1 = radiobox(group);
28     auto r2 = radiobox(group);
29     assert(!r1.isChecked);
30     assert(!r2.isChecked);
31 
32     r1.runInputAction!(FluidInputAction.press);
33     assert( r1.isChecked);
34     assert(!r2.isChecked);
35 
36     // Pressing again has no effect
37     r1.runInputAction!(FluidInputAction.press);
38     assert( r1.isChecked);
39     assert(!r2.isChecked);
40 
41     r2.runInputAction!(FluidInputAction.press);
42     assert(!r1.isChecked);
43     assert( r2.isChecked);
44 
45     r1.runInputAction!(FluidInputAction.press);
46     assert( r1.isChecked);
47     assert(!r2.isChecked);
48 
49 }
50 
51 @("Different radiobox groups do not affect each other")
52 unittest {
53 
54     auto a = new RadioboxGroup;
55     auto a1 = radiobox(a);
56     auto a2 = radiobox(a);
57     auto b = new RadioboxGroup;
58     auto b1 = radiobox(b);
59     auto b2 = radiobox(b);
60     assert(!a1.isChecked);
61     assert(!a2.isChecked);
62     assert(!b1.isChecked);
63     assert(!b2.isChecked);
64 
65     a1.runInputAction!(FluidInputAction.press);
66     assert( a1.isChecked);
67     assert(!a2.isChecked);
68     assert(!b1.isChecked);
69     assert(!b2.isChecked);
70 
71     b2.runInputAction!(FluidInputAction.press);
72     assert( a1.isChecked);
73     assert(!a2.isChecked);
74     assert(!b1.isChecked);
75     assert( b2.isChecked);
76 
77     a2.runInputAction!(FluidInputAction.press);
78     assert(!a1.isChecked);
79     assert( a2.isChecked);
80     assert(!b1.isChecked);
81     assert( b2.isChecked);
82 
83 }
84 
85 @("Radiobox is represented with a circle")
86 unittest {
87 
88     auto theme = nullTheme.derive(
89         rule!Radiobox(
90             Rule.padding = 2,
91             Rule.extra = new Radiobox.Extra(1, color("#555"), color("#5552")),
92             when!"a.isChecked"(
93                 Rule.extra = new Radiobox.Extra(1, color("#555"), color("#000"))
94             ),
95         ),
96 
97     );
98     auto input = radiobox(new RadioboxGroup);
99     auto root = testSpace(theme, input);
100 
101     input.size = Vector2(16, 16);  // (20, 20) with padding
102     root.drawAndAssert(
103         input.drawsCircle()       .at(10, 10).ofRadius( 8).ofColor("#5552"),
104         input.drawsCircleOutline().at(10, 10).ofRadius(10).ofColor("#555"),
105     );
106 
107     input.select();
108     root.drawAndAssert(
109         input.drawsCircle()       .at(10, 10).ofRadius( 8).ofColor("#000"),
110         input.drawsCircleOutline().at(10, 10).ofRadius(10).ofColor("#555"),
111     );
112 
113 }