1 ///
2 module fluid.onion_frame;
3 
4 import fluid.frame;
5 import fluid.utils;
6 import fluid.style;
7 import fluid.backend;
8 
9 
10 @safe:
11 
12 
13 /// An onion frame places its children as layers, drawing one on top of the other, instead of on the side.
14 ///
15 /// Children are placed in order of drawing — the last child will be drawn last, and so, will appear on top.
16 alias onionFrame = simpleConstructor!OnionFrame;
17 
18 /// ditto
19 class OnionFrame : Frame {
20 
21     mixin DefineStyles;
22 
23     this(T...)(T args) {
24 
25         super(args);
26 
27     }
28 
29     protected override void resizeImpl(Vector2 available) {
30 
31         import std.algorithm : max;
32 
33         minSize = Vector2(0, 0);
34 
35         // Check each child
36         foreach (child; children) {
37 
38             // Resize the child
39             child.resize(tree, theme, available);
40 
41             // Update minSize
42             minSize.x = max(minSize.x, child.minSize.x);
43             minSize.y = max(minSize.y, child.minSize.y);
44 
45         }
46 
47     }
48 
49     protected override void drawImpl(Rectangle outer, Rectangle inner) {
50 
51         const style = pickStyle();
52         style.drawBackground(tree.io, outer);
53 
54         foreach (child; filterChildren) {
55 
56             child.draw(inner);
57 
58         }
59 
60     }
61 
62 }
63 
64 ///
65 unittest {
66 
67     import fluid;
68 
69     auto myFrame = onionFrame(
70 
71         // Draw an image
72         imageView("logo.png"),
73 
74         // Draw a label in the middle of the frame
75         label(
76             layout!(1, "center"),
77             "Hello, Fluid!"
78         ),
79 
80     );
81 
82 }
83 
84 unittest {
85 
86     import fluid.label;
87     import fluid.structs;
88     import fluid.image_view;
89 
90     ImageView view;
91     Label[2] labels;
92 
93     auto io = new HeadlessBackend(Vector2(1000, 1000));
94     auto root = onionFrame(
95 
96         view = imageView("logo.png"),
97 
98         labels[0] = label(
99             "Hello, Fluid!"
100         ),
101 
102         labels[1] = label(
103             layout!(1, "center"),
104             "Hello, Fluid! This text should fit the image."
105         ),
106 
107     );
108 
109     root.theme = nullTheme.makeTheme!q{
110         Label.styleAdd.textColor = color!"000";
111     };
112     root.io = io;
113     root.draw();
114 
115     // imageView
116     io.assertTexture(view.texture, Vector2(0, 0), color!"fff");
117 
118     // First label
119     io.assertTexture(labels[0].text.texture, Vector2(0, 0), color!"000");
120 
121     // TODO onionFrame should perform shrink-expand ordering similarly to `space`. The last label should wrap.
122 
123 }