1 module nodes.size_lock;
2 
3 import fluid;
4 
5 @safe:
6 
7 @("sizeLock supports hspace")
8 unittest {
9 
10     assert(sizeLock!vspace().isHorizontal == false);
11     assert(sizeLock!hspace().isHorizontal == true);
12 
13 }
14 
15 @("SizeLock changes the size given to a node")
16 unittest {
17 
18     auto lock = sizeLock!vframe(
19         .layout!(1, "center", "fill"),
20         .sizeLimitX(400),
21         label("Hello, World!"),
22     );
23     auto root = sizeLock!testSpace(
24         .layout!"fill",
25         .sizeLimit(800, 600),
26         lock,
27     );
28 
29     with (Rule)
30     root.theme = nullTheme.derive(
31         rule!Frame(backgroundColor = color!"1c1c1c"),
32         rule!Label(textColor = color!"eee"),
33     );
34 
35     // The rectangle should display neatly in the middle of the display, limited to 400px
36     root.drawAndAssert(
37         lock.drawsRectangle(200, 0, 400, 600).ofColor("#1c1c1c"),
38     );
39 
40     // Try different layouts: it can also be placed on the left
41     lock.layout = layout!(1, "start", "fill");
42     root.updateSize();
43     root.drawAndAssert(
44         lock.drawsRectangle(0, 0, 400, 600).ofColor("#1c1c1c"),
45     );
46 
47     // Center, also vertically, with a square limit
48     lock.layout = layout!(1, "center");
49     lock.limit = sizeLimit(200, 200);
50     root.updateSize();
51     root.drawAndAssert(
52         lock.drawsRectangle(300, 200, 200, 200).ofColor("#1c1c1c"),
53     );
54 
55 }
56 
57 @("SizeLock can use floats as limit")
58 unittest {
59 
60     auto content = sizeLock!vframe(
61         .nullTheme,
62         .layout!(1, "start"),
63         .sizeLimit(50f, 50f),
64     );
65     auto root = testSpace(content);
66 
67     root.drawAndAssert(
68         content.isDrawn().at(0, 0, 50, 50)
69     );
70 
71 }
72 
73 @("Limits of SizeLock take priority over minSize")
74 unittest {
75 
76     auto content = sizeLock!vframe(
77         .nullTheme,
78         .layout!(1, "start"),
79         .sizeLimit(50, 50),
80         label("This label is NOT empty!"),
81     );
82     auto root = testSpace(content);
83 
84     root.drawAndAssert(
85         content.isDrawn().at(0, 0, 50, 50)
86     );
87 
88 }
89 
90 @("SizeLock doesn't affect areas it is not limited in")
91 unittest {
92 
93     auto content = sizeLock!vframe(
94         .nullTheme,
95         .layout!(1, "start"),
96         .sizeLimitX(100f),
97     );
98     auto root = testSpace(content);
99 
100     root.drawAndAssert(
101         content.isDrawn().at(0, 0, 100, 0),  // height MUST be 0
102     );
103 
104 }