grid.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
#include <planet/debug/ui.hpp>
#include <planet/ostream.hpp>
#include <planet/ui/box.hpp>
#include <planet/ui/layout.grid.hpp>
#include <felspar/test.hpp>


namespace {


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

    constexpr planet::ui::reflowable::constrained_type screen_400{
            {400, 0, 400}, {300, 0, 300}};

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


    auto const rf1 = suite.test(
            "reflow",
            [](auto check, auto &log) {
                constexpr planet::affine::extents2d target_size{4, 3};
                auto g = planet::ui::grid{
                        std::tuple{
                                planet::debug::fixed_element{log, target_size}},
                        4};
                g.reflow({.screen = screen_400}, screen_400);
                g.move_to(
                        {.screen = screen_400},
                        {{0, 0}, planet::affine::extents2d{400, 300}});

                check(g.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
                check(std::get<0>(g.items).position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                constexpr planet::affine::extents2d target_size{4, 3};
                auto g = planet::ui::grid{
                        std::tuple{
                                planet::debug::fixed_element{log, target_size},
                                planet::debug::fixed_element{log, target_size}},
                        4};
                g.reflow({.screen = screen_400}, screen_400);
                g.move_to(
                        {.screen = screen_400},
                        {{0, 0}, planet::affine::extents2d{400, 300}});

                check(g.hpadding) == 4;
                check(g.vpadding) == 4;

                check(g.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{12, 3}};
                check(std::get<0>(g.items).position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
                check(std::get<1>(g.items).position())
                        == planet::affine::rectangle2d{
                                {8, 0}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                constexpr planet::affine::extents2d target_size{4, 3};
                auto g = planet::ui::grid{
                        std::tuple{
                                planet::debug::fixed_element{log, target_size},
                                planet::debug::fixed_element{log, target_size}},
                        4};
                static constexpr planet::ui::reflowable::constrained_type
                        screen_8{{8, 0, 8}, {300, 0, 300}};
                g.reflow({.screen = screen_8}, screen_8);
                g.move_to(
                        {.screen = screen_8},
                        {{0, 0}, planet::affine::extents2d{8, 300}});

                check(g.hpadding) == 4;
                check(g.vpadding) == 4;

                check(g.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 10}};
                check(std::get<0>(g.items).position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{4, 3}};
                check(std::get<1>(g.items).position())
                        == planet::affine::rectangle2d{
                                {0, 7}, planet::affine::extents2d{4, 3}};
            },
            [](auto check, auto &log) {
                constexpr planet::affine::extents2d target_size{4, 3};
                auto g = planet::ui::box{planet::ui::grid{
                        std::tuple{
                                planet::debug::fixed_element{log, target_size},
                                planet::debug::fixed_element{log, target_size}},
                        5}};
                g.reflow({.screen = screen_400}, screen_400);
                g.move_to(
                        {.screen = screen_400},
                        {{0, 0}, planet::affine::extents2d{400, 300}});

                check(g.position())
                        == planet::affine::rectangle2d{
                                {0, 0}, planet::affine::extents2d{400, 300}};
                check(g.content.position())
                        == planet::affine::rectangle2d{
                                {193.5f, 148.5f},
                                planet::affine::extents2d{13, 3}};
                check(std::get<0>(g.content.items).position())
                        == planet::affine::rectangle2d{
                                {193.5f, 148.5f},
                                planet::affine::extents2d{4, 3}};
                check(std::get<1>(g.content.items).position())
                        == planet::affine::rectangle2d{
                                {202.5f, 148.5f},
                                planet::affine::extents2d{4, 3}};
            });


}