1 ///
2 module actions.ordered_focus_action;
3 
4 import fluid;
5 import fluid.future.action;
6 
7 @safe:
8 
9 @("OrderedFocusAction can select the next focusable node (focusNext)")
10 unittest {
11 
12     auto target = button("", delegate { });
13     auto newTarget = button("Next", delegate { });
14     auto root = focusChain(
15         vspace(
16             button("First", delegate { }),
17             button("Previous", delegate { }),
18             target,
19             label("Obstacle"),
20             newTarget,
21             button("Last", delegate { }),
22         ),
23     );
24 
25     root.draw();
26     target.focusNext();
27     root.draw();
28     assert(root.isFocused(newTarget));
29 
30 }
31 
32 @("OrderedFocusAction can select the previous focusable node (focusPrevious)")
33 unittest {
34 
35     auto target = button("", delegate { });
36     auto newTarget = button("Previous", delegate { });
37     auto root = focusChain(
38         vspace(
39             button("First", delegate { }),
40             newTarget,
41             label("Obstacle"),
42             target,
43             button("Next", delegate { }),
44             button("Last", delegate { }),
45         ),
46     );
47 
48     root.draw();
49     target.focusPrevious();
50     root.draw();
51     assert(root.isFocused(newTarget));
52 
53 }
54 
55 @("OrderedFocusAction can optionally wrap (focusNext)")
56 unittest {
57 
58     auto newTarget = button("First", delegate { });
59     auto target = button("Last", delegate { });
60 
61     auto root = focusChain(
62         vspace(
63             label("Obstacle"),
64             newTarget,
65             button("Second", delegate { }),
66             label("Obstacle"),
67             button("Second to last", delegate { }),
68             target,
69             label("Obstacle"),
70         ),
71     );
72 
73     root.draw();
74     target.focusNext();
75     root.draw();
76     assert(root.isFocused(newTarget));
77 
78     // Clear focus and disable wrapping
79     root.currentFocus = target;
80     target.focusNext(false);
81     root.draw();
82     assert(root.isFocused(target));
83 
84 }
85 
86 @("OrderedFocusAction can optionally wrap (focusPrevious)")
87 unittest {
88 
89     auto newTarget = button("Last", delegate { });
90     auto target = button("First", delegate { });
91 
92     auto root = focusChain(
93         vspace(
94             label("Obstacle"),
95             target,
96             button("Second", delegate { }),
97             label("Obstacle"),
98             button("Second to last", delegate { }),
99             newTarget,
100             label("Obstacle"),
101         ),
102     );
103 
104     root.draw();
105     target.focusPrevious();
106     root.draw();
107     assert(root.isFocused(newTarget));
108 
109     // Clear focus and disable wrapping
110     root.currentFocus = target;
111     target.focusPrevious(false);
112     root.draw();
113     assert(root.isFocused(target));
114 
115 }