diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-12 20:00:59 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-03-12 20:00:59 -0400 |
| commit | 14fa08a4a3ac34c10e9a8b754eb49778f60c2372 (patch) | |
| tree | a9dc2eb64452349e6983d493ea1de19f705d8b2c /tests | |
| parent | 85a2ba407b1ae285b4080e14f8a18ecf4ec7da2c (diff) | |
pke: static ui dynamic sizing test
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/pke-test-static-ui.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/pke-test-static-ui.cpp b/tests/pke-test-static-ui.cpp index 6e6fb4b..38528cf 100644 --- a/tests/pke-test-static-ui.cpp +++ b/tests/pke-test-static-ui.cpp @@ -53,7 +53,10 @@ int pke_test_static_ui_000() { 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); @@ -65,6 +68,47 @@ int pke_test_static_ui_000() { // 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; } |
