1 ///
2 module fluid.separator;
3 
4 import fluid.node;
5 import fluid.utils;
6 import fluid.backend;
7 import fluid.structs;
8 
9 
10 @safe:
11 
12 
13 /// A separator node creates a line, used to separate unrelated parts of content.
14 alias vseparator = simpleConstructor!(Separator, (a) {
15 
16     a.isHorizontal = false;
17     a.layout = .layout!("center", "fill");
18 
19 });
20 
21 /// ditto
22 alias hseparator = simpleConstructor!(Separator, (a) {
23 
24     a.isHorizontal = true;
25     a.layout = .layout!("fill", "center");
26 
27 });
28 
29 /// ditto
30 class Separator : Node {
31 
32     public {
33 
34         bool isHorizontal;
35 
36     }
37 
38     override void resizeImpl(Vector2) {
39 
40         minSize = Vector2(1, 1);
41 
42     }
43 
44     override void drawImpl(Rectangle outer, Rectangle inner) {
45 
46         auto style = pickStyle();
47 
48         style.drawBackground(io, outer);
49 
50         if (isHorizontal) {
51 
52             auto start = Vector2(start(inner).x, center(inner).y);
53             auto end = Vector2(end(inner).x, center(inner).y);
54 
55             style.drawLine(io, start, end);
56 
57         }
58 
59         else {
60 
61             auto start = Vector2(center(inner).x, start(inner).y);
62             auto end = Vector2(center(inner).x, end(inner).y);
63 
64             style.drawLine(io, start, end);
65 
66         }
67 
68     }
69 
70 }
71 
72 unittest {
73 
74     import fluid.theme;
75     import fluid.default_theme;
76 
77     auto io = new HeadlessBackend(Vector2(100, 100));
78     auto theme = nullTheme.derive(
79         rule!Separator(
80             lineColor = color("#000"),
81         ),
82     );
83 
84     // Vertical
85     auto root = vseparator(theme);
86 
87     root.backend = io;
88     root.draw();
89 
90     io.assertLine(Vector2(50, 0), Vector2(50, 100), color("#000"));
91 
92     // Horizontal
93     root = hseparator(theme);
94 
95     io.nextFrame;
96     root.backend = io;
97     root.draw();
98 
99     io.assertLine(Vector2(0, 50), Vector2(100, 50), color("#000"));
100 
101 }