1 module nodes.label;
2 
3 import fluid;
4 
5 @safe:
6 
7 @("Label draws text, and updates it if written to")
8 unittest {
9 
10     import fluid.theme;
11 
12     auto node = label("Hello, World!");
13     auto root = testSpace(node);
14 
15     root.theme = nullTheme.derive(
16         rule!Label(textColor = color!"000"),
17     );
18 
19     root.draw();
20 
21     const initialTextArea = node.text.size.x * node.text.size.y;
22     auto firstImage = node.text.texture.chunks[0].image;
23 
24     root.drawAndAssert(
25         node.drawsHintedImage(firstImage).at(0, 0)
26     );
27 
28     node.text ~= " It's a nice day today!";
29     root.draw();
30 
31     const newTextArea = node.text.size.x * node.text.size.y;
32     auto secondImage = node.text.texture.chunks[0].image;
33 
34     root.drawAndAssert(
35         node.drawsHintedImage(secondImage).at(0, 0).withPalette(color("#000"))
36     );
37 
38     assert(firstImage != secondImage);
39     assert(newTextArea > initialTextArea);
40 
41 }
42 
43 @("Text is correctly drawn in different DPI settings")
44 unittest {
45 
46     auto content = label("Hello, World!");
47     auto root = testSpace(.nullTheme, content);
48 
49     root.drawAndAssert(
50         content.drawsHintedImage().at(0, 0, 109, 27).ofColor("#ffffff")
51             .sha256("e5b75b97f0894aeba0c17c078a7509ab0e9e652b89797817fac0063cc82055f4"),
52     );
53 
54     // TODO affected by https://git.samerion.com/Samerion/Fluid/issues/330
55     root.dpi = Vector2(120, 120);
56     root.drawAndAssert(
57         content.drawsHintedImage().at(0, 0, 107.2, 26.4).ofColor("#ffffff")
58             .sha256("700fa10edb2d15dd74b4232c0ff479ab8a0a099240f7597481365ec242c2229a"),
59     );
60 
61 }