1 module actions.scroll_into_view_action;
2 
3 import std.math;
4 import std.array;
5 import std.range;
6 import std.algorithm;
7 
8 import fluid;
9 
10 @safe:
11 
12 @("ScrollIntoViewAction works")
13 unittest {
14 
15     const viewportHeight = 10;
16 
17     Label[3] labels;
18 
19     auto frame = vscrollFrame(
20         .layout!(1, "fill"),
21         labels[0] = label("a"),
22         labels[1] = label("b"),
23         labels[2] = label("c"),
24     );
25     auto root = sizeLock!testSpace(
26         .nullTheme,
27         .sizeLimit(10, viewportHeight),
28         .cropViewport,
29         frame
30     );
31 
32     frame.scrollBar.width = 0;  // TODO replace this with scrollBar.hide()
33 
34     // Prepare scrolling
35     // Note: Changes made when scrolling will be visible during the next frame
36     frame.children[1].scrollIntoView;
37     root.draw();
38 
39     // No theme so everything is as compact as it can be: the first label should be at the very top
40     // It is reasonable to assume the text will be larger than 10 pixels (viewport height)
41     // Other text will not render, since it's offscreen
42     root.drawAndAssert(
43         labels[0].doesNotDrawImages(),
44         labels[1].drawsImage().at(0, viewportHeight - labels[1].text.size.y),
45         labels[2].doesNotDrawImages(),
46     );
47     // TODO Because the label was hidden below the viewport, Fluid will align the bottom of the selected node with the
48     // viewport which probably isn't appropriate in case *like this* where it should reveal the top of the node.
49 
50     // auto texture1 = io.textures.front;
51     // assert(isClose(texture1.position.y + texture1.height, viewportHeight));
52     assert(isClose(frame.scroll, (frame.scrollMax + 10) * 2/3 - 10));
53 
54     // TODO more tests. Scrolling while already in the viewport, scrolling while partially out of the view, etc.
55 
56 }