column.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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <planet/debug/ui.hpp>
#include <planet/ostream.hpp>
#include <planet/ui/layout.column.hpp>
#include <felspar/test.hpp>


namespace {


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

    constexpr constrained_type screen{{100, 0, 100}, {100, 0, 100}};


    auto const suite = felspar::testsuite("column.layout");


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

                check(c.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
                check(std::get<0>(c.items).position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                auto c = planet::ui::column{
                        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},
                        {{13, 15}, planet::affine::extents2d{100, 100}});

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


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

                check(c.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
                check(std::get<0>(c.items).position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                auto c = planet::ui::column{
                        std::tuple{
                                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},
                        {{13, 15}, planet::affine::extents2d{100, 100}});

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


    auto const vrf1 = suite.test("reflow/vector", [](auto check, auto &log) {
        planet::affine::rectangle2d const size{
                {13, 15}, planet::affine::extents2d{100, 100}};
        auto c =
                planet::ui::column{std::vector<planet::debug::fixed_element>{}};
        check(c.items.size()) == 0u;

        c.reflow({.screen = screen}, screen);
        c.move_to({.screen = screen}, size);
        check(c.position().extents) == planet::affine::extents2d{};

        c.items.push_back(planet::debug::fixed_element{log, {4, 3}});
        c.reflow({.screen = screen}, screen);
        c.move_to({.screen = screen}, size);
        check(c.position().top_left) == planet::affine::point2d{13, 15};
        check(c.position().extents) == planet::affine::extents2d{4, 3};
        check(c.items[0].position().top_left)
                == planet::affine::point2d{13, 15};
        check(c.items[0].position().extents) == planet::affine::extents2d{4, 3};

        c.items.push_back({log, {4, 3}});
        c.reflow({.screen = screen}, screen);
        c.move_to({.screen = screen}, size);
        check(c.position().top_left) == planet::affine::point2d{13, 15};
        check(c.position().extents) == planet::affine::extents2d{4, 6};
        check(c.items[0].position().top_left)
                == planet::affine::point2d{13, 15};
        check(c.items[0].position().extents) == planet::affine::extents2d{4, 3};
        check(c.items[1].position().top_left)
                == planet::affine::point2d{13, 18};
        check(c.items[0].position().extents) == planet::affine::extents2d{4, 3};
    });


}