1 module actions.filters;
2 
3 import fluid;
4 
5 @safe:
6 
7 class NoBeforeDraw : TreeAction {
8 
9     int afterDrawCalled;
10 
11     override bool filterBeforeDraw(Node node) {
12         super.filterBeforeDraw(node);
13         return false;
14     }
15 
16     override void beforeTree(Node, Rectangle) {
17         afterDrawCalled = 0;
18     }
19 
20     override void beforeDraw(Node, Rectangle) {
21         assert(false);
22     }
23 
24     override void afterDraw(Node, Rectangle) {
25         afterDrawCalled++;
26     }
27     
28 }
29 
30 class NoAfterDraw : TreeAction {
31 
32     int beforeDrawCalled;
33 
34     override bool filterAfterDraw(Node node) {
35         super.filterAfterDraw(node);
36         return false;
37     }
38 
39     override void beforeTree(Node, Rectangle) {
40         beforeDrawCalled = 0;
41     }
42 
43     override void beforeDraw(Node, Rectangle) {
44         beforeDrawCalled++;
45     }
46 
47     override void afterDraw(Node, Rectangle) {
48         assert(false);
49     }
50     
51 }
52 
53 @("`filterBeforeDraw` can be used to control when beforeDraw() is called")
54 unittest {
55 
56     auto subject = vspace();
57     auto root = vspace(subject);
58     auto action = new NoBeforeDraw;
59 
60     root.startAction(action);
61     root.draw();
62 
63     assert(action.afterDrawCalled == 2);
64 
65     subject.startAction(action);
66     root.draw();
67 
68     assert(action.afterDrawCalled == 1);
69 
70 }
71 
72 @("`filterAfterDraw` can be used to control when afterDraw() is called")
73 unittest {
74 
75     auto subject = vspace();
76     auto root = vspace(subject);
77     auto action = new NoAfterDraw;
78 
79     root.startAction(action);
80     root.draw();
81 
82     assert(action.beforeDrawCalled == 2);
83 
84     subject.startAction(action);
85     root.draw();
86 
87     assert(action.beforeDrawCalled == 1);
88 
89 }