row.layout.tests.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <planet/debug/ui.hpp>
#include <planet/ostream.hpp>
#include <planet/ui/layout.row.hpp>
#include <felspar/test.hpp>


namespace {


    using constrained_type = planet::ui::constrained2d<float>;

    constexpr planet::ui::reflowable::constrained_type screen{
            {100, 0, 100}, {100, 0, 100}};


    auto const rsuite = felspar::testsuite("row.layout");


    auto const arf1 = rsuite.test(
            "reflow/array",
            [](auto check, auto &log) {
                auto c = planet::ui::row{
                        std::array{planet::debug::fixed_element{log, {4, 3}}},
                        2};
                c.reflow({.screen = screen}, screen);
                c.move_to(
                        {.screen = screen},
                        {{15, 20}, planet::affine::extents2d{100, 100}});

                check(c.position())
                        == planet::affine::rectangle2d{
                                {15, 20}, planet::affine::extents2d{4, 3}};
                check(c.items[0].position())
                        == planet::affine::rectangle2d{
                                {15, 20}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                auto c = planet::ui::row{
                        std::array{
                                planet::debug::fixed_element{log, {4, 3}},
                                planet::debug::fixed_element{log, {4, 3}}},
                        2};
                c.reflow({.screen = screen}, screen);
                c.move_to(
                        {.screen = screen},
                        {{15, 20}, planet::affine::extents2d{100, 100}});

                check(c.position())
                        == planet::affine::rectangle2d{
                                {15, 20}, planet::affine::extents2d{10, 3}};
                check(c.items[0].position())
                        == planet::affine::rectangle2d{
                                {15, 20}, planet::affine::extents2d{4, 3}};
                check(c.items[1].position())
                        == planet::affine::rectangle2d{
                                {21, 20}, planet::affine::extents2d{4, 3}};
            });


    auto const rf1 = rsuite.test("reflow/tuple", [](auto check, auto &log) {
        auto c = planet::ui::row{
                std::tuple{planet::debug::fixed_element{log, {4, 3}}}, 2};
        c.reflow({.screen = screen}, screen);
        c.move_to(
                {.screen = screen},
                {{15, 20}, planet::affine::extents2d{100, 100}});

        check(c.position())
                == planet::affine::rectangle2d{
                        {15, 20}, planet::affine::extents2d{4, 3}};
        check(std::get<0>(c.items).position())
                == planet::affine::rectangle2d{
                        {15, 20}, planet::affine::extents2d{4, 3}};
    });


}