/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "dusktest.h" #include "ui/frame/uiframe.h" static void test_uiFrameBuildSprites_layout(void **state) { UI_FRAME.tileset = (tileset_t){ .tileWidth = 1, .tileHeight = 1, .tileCount = 9, .columns = 3, .rows = 3, .uv = { 0.25f, 0.25f } }; const float_t x = 100.0f; const float_t y = 50.0f; const float_t width = 40.0f; const float_t height = 30.0f; const float_t tileW = (float_t)UI_FRAME_BORDER_WIDTH; const float_t tileH = (float_t)UI_FRAME_BORDER_HEIGHT; spritebatchsprite_t sprites[9]; uiFrameBuildSprites(sprites, x, y, width, height); // Top-left corner sits exactly at the rect's origin. assert_float_equal(sprites[0].min[0], x, 0.0001f); assert_float_equal(sprites[0].min[1], y, 0.0001f); assert_float_equal(sprites[0].max[0], x + tileW, 0.0001f); assert_float_equal(sprites[0].max[1], y + tileH, 0.0001f); assert_float_equal(sprites[0].uvMin[0], 0.0f, 0.0001f); assert_float_equal(sprites[0].uvMin[1], 0.0f, 0.0001f); assert_float_equal(sprites[0].uvMax[0], 0.25f, 0.0001f); assert_float_equal(sprites[0].uvMax[1], 0.25f, 0.0001f); // Top-middle edge stretches to fill the width minus both corners. assert_float_equal(sprites[1].min[0], x + tileW, 0.0001f); assert_float_equal(sprites[1].max[0], x + width - tileW, 0.0001f); assert_float_equal(sprites[1].max[1], y + tileH, 0.0001f); // Center tile fills the remaining interior on both axes. assert_float_equal(sprites[4].min[0], x + tileW, 0.0001f); assert_float_equal(sprites[4].min[1], y + tileH, 0.0001f); assert_float_equal(sprites[4].max[0], x + width - tileW, 0.0001f); assert_float_equal(sprites[4].max[1], y + height - tileH, 0.0001f); // Bottom-right corner sits exactly at the rect's far corner, sampling // tileset column 2, row 2. assert_float_equal(sprites[8].min[0], x + width - tileW, 0.0001f); assert_float_equal(sprites[8].min[1], y + height - tileH, 0.0001f); assert_float_equal(sprites[8].max[0], x + width, 0.0001f); assert_float_equal(sprites[8].max[1], y + height, 0.0001f); assert_float_equal(sprites[8].uvMin[0], 0.5f, 0.0001f); assert_float_equal(sprites[8].uvMin[1], 0.5f, 0.0001f); } int main(int argc, char **argv) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_uiFrameBuildSprites_layout), }; return cmocka_run_group_tests(tests, NULL, NULL); }