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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#include "./pke-test-static-ui.h"
#include "window.hpp"
#include "dynamic-array.hpp"
#include "vendor-glm-include.hpp"
struct pke_ui_box_instance_buffer_item {
glm::mat4 pos_scale;
glm::vec2 px_scale;
float depth;
float padding[1];
};
struct pke_ui_flex_params {
float px_per_unit;
float unit_total;
};
#define PKE_TEST_EXPOSE
#include "static-ui.hpp"
void pke_test_static_ui_setup() {
Extent.width = 1920;
Extent.height = 1080;
pke_ui_init();
}
void pke_test_static_ui_teardown() {
pke_ui_teardown();
}
// test static
int pke_test_static_ui_000() {
DynArray<pke_ui_box_instance_buffer_item> arr{};
float calculated_offset;
uint8_t err_index = 0;
pke_ui_box *ui_box = pke_ui_box_new_root();
ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC;
ui_box->pos_top_left_x = 10;
ui_box->pos_top_left_y = 10;
ui_box->max_width = 500;
ui_box->max_height = 500;
pke_ui_box *c_ui_box = pke_ui_box_new_child(ui_box);
c_ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC;
c_ui_box->pos_top_left_x = 10;
c_ui_box->pos_top_left_y = 10;
c_ui_box->max_width = 100;
c_ui_box->max_height = 100;
calculated_offset = ui_box->pos_top_left_x + c_ui_box->pos_top_left_x + built_in_offset;
pke_ui_calc_px(arr, nullptr, ui_box);
pke_ui_recalc_sizes_recursive(arr, ui_box, 0);
PKE_TEST_ASSERT(ui_box->internal.parent == nullptr, err_index);
PKE_TEST_ASSERT(ui_box->internal.h_children == 1, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.parent != nullptr, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.h_children == 0, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.r_children == 0, err_index);
PKE_TEST_ASSERT(ui_box->internal.px_corner_x == 10, err_index);
PKE_TEST_ASSERT(ui_box->internal.px_corner_y == 10, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.px_corner_x == calculated_offset, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.px_corner_y == calculated_offset, err_index);
return 0;
}
// test dynamic
int pke_test_static_ui_100() {
DynArray<pke_ui_box_instance_buffer_item> arr{};
float unit;
float calculated_offset_x, calculated_offset_y;
uint8_t err_index = 0;
pke_ui_box *ui_box = pke_ui_box_new_root();
ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
ui_box->pos_top_left_x = 0.1;
ui_box->pos_top_left_y = 0.1;
ui_box->max_width = 0.8;
ui_box->max_height = 0.8;
pke_ui_box *c_ui_box = pke_ui_box_new_child(ui_box);
c_ui_box->flags = PKE_UI_BOX_FLAG_POSITION_TYPE_DYNAMIC;
c_ui_box->pos_top_left_x = 0.1;
c_ui_box->pos_top_left_y = 0.1;
c_ui_box->max_width = 0.8;
c_ui_box->max_height = 0.8;
unit = Extent.width * 0.1;
calculated_offset_x = (unit * 8) - (built_in_offset * 2); // padded parent
calculated_offset_x = (calculated_offset_x * 0.1) + unit + built_in_offset;
unit = Extent.height * 0.1;
calculated_offset_y = (unit * 8) - (built_in_offset * 2); // padded parent
calculated_offset_y = (calculated_offset_y * 0.1) + unit + built_in_offset;
pke_ui_calc_px(arr, nullptr, ui_box);
pke_ui_recalc_sizes_recursive(arr, ui_box, 0);
PKE_TEST_ASSERT(ui_box->internal.parent == nullptr, err_index);
PKE_TEST_ASSERT(ui_box->internal.h_children == 1, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.parent != nullptr, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.h_children == 0, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.r_children == 0, err_index);
PKE_TEST_ASSERT(ui_box->internal.px_corner_x == Extent.width * 0.1, err_index);
PKE_TEST_ASSERT(ui_box->internal.px_corner_y == Extent.height * 0.1, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.px_corner_x == calculated_offset_x, err_index);
PKE_TEST_ASSERT(c_ui_box->internal.px_corner_y == calculated_offset_y, err_index);
return 0;
}
// test flex
int pke_test_static_ui_200() {
return 0;
}
pke_test_group *pke_test_static_ui_get_group() {
static const uint64_t test_count = 3;
static struct pke_test tests[test_count] = {
{
.title = "test 000",
.func = pke_test_static_ui_000,
.expected_result = 0,
},
{
.title = "test 100",
.func = pke_test_static_ui_100,
.expected_result = 0,
},
{
.title = "test 200",
.func = pke_test_static_ui_200,
.expected_result = 0,
},
};
static struct pke_test_group group = {};
group.title = "static_ui";
group.group_setup = NULL;
group.group_teardown = NULL;
group.test_setup = pke_test_static_ui_setup;
group.test_teardown = pke_test_static_ui_teardown;
group.tests = &tests[0];
group.n_tests = test_count;
return &group;
}
|