summaryrefslogtreecommitdiff
path: root/src/static-ui.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-05-20 21:08:19 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-05-20 21:08:19 -0400
commit40d69e7e40a18865a31af2f55efcde369d36dbbb (patch)
tree95a2cbbe40192183d13f846f3444b32d7e12b0e8 /src/static-ui.cpp
parentead9e484db969a880470d625b1884aced296e722 (diff)
pke: serialization overhaul + embedded assets
Diffstat (limited to 'src/static-ui.cpp')
-rw-r--r--src/static-ui.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp
index 823c015..2f2ce11 100644
--- a/src/static-ui.cpp
+++ b/src/static-ui.cpp
@@ -3,6 +3,7 @@
#include "dynamic-array.hpp"
#include "ecs.hpp"
+#include "font.hpp"
#include "game-settings.hpp"
#include "pk.h"
#include "static-plane.hpp"
@@ -100,14 +101,14 @@ void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
glm::vec2 parent_size_padded;
glm::vec2 parent_pos_and_offset;
- assert(box->pos_top_left_x >= 0.0);
- assert(box->pos_top_left_y >= 0.0);
- assert(box->max_width >= 0.0);
- assert(box->max_height >= 0.0);
- assert(box->min_width >= 0.0);
- assert(box->min_height >= 0.0);
- assert(box->min_width <= box->max_width);
- assert(box->min_height <= box->max_height);
+ assert(box->pos_top_left.x >= 0.0);
+ assert(box->pos_top_left.y >= 0.0);
+ assert(box->max_size.x >= 0.0);
+ assert(box->max_size.y >= 0.0);
+ assert(box->min_size.x >= 0.0);
+ assert(box->min_size.y >= 0.0);
+ assert(box->min_size.x <= box->max_size.x);
+ assert(box->min_size.y <= box->max_size.y);
if (box->internal.parent != nullptr) {
parent_pos_and_offset.x = box->internal.parent->internal.px_corner.x
@@ -128,16 +129,16 @@ void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
px_size = glm::vec2(Extent.width, Extent.height);
}
- px_min_size.x = box->min_width;
- px_min_size.y = box->min_height;
- px_max_size.x = box->max_width;
- px_max_size.y = box->max_height;
+ px_min_size.x = box->min_size.x;
+ px_min_size.y = box->min_size.y;
+ px_max_size.x = box->max_size.x;
+ px_max_size.y = box->max_size.y;
box->internal.px_corner.x = 0
+ parent_pos_and_offset.x
- + box->pos_top_left_x;
+ + box->pos_top_left.x;
box->internal.px_corner.y = 0
+ parent_pos_and_offset.y
- + box->pos_top_left_y;
+ + box->pos_top_left.y;
if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_FLEX)) {
assert(flex_params != nullptr);
@@ -148,23 +149,23 @@ void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
px_size.y = flex_params->px_per_unit * box->flex_weight;
}
} else if (PK_HAS_FLAG(box->flags, PKE_UI_BOX_FLAG_POSITION_TYPE_STATIC)) {
- px_size.x -= box->pos_top_left_x;
- px_size.y -= box->pos_top_left_y;
+ px_size.x -= box->pos_top_left.x;
+ px_size.y -= box->pos_top_left.y;
} else {
- assert(box->pos_top_left_x < 1.0);
- assert(box->pos_top_left_y < 1.0);
+ assert(box->pos_top_left.x < 1.0);
+ assert(box->pos_top_left.y < 1.0);
box->internal.px_corner.x = parent_pos_and_offset.x;
box->internal.px_corner.y = parent_pos_and_offset.y;
- float px_left = px_size.x * box->pos_top_left_x;
- float px_top = px_size.y * box->pos_top_left_y;
+ float px_left = px_size.x * box->pos_top_left.x;
+ float px_top = px_size.y * box->pos_top_left.y;
box->internal.px_corner.x += px_left;
box->internal.px_corner.y += px_top;
px_size.x -= px_left;
px_size.y -= px_top;
- px_min_size.x = box->min_width * parent_size_padded.x;
- px_min_size.y = box->min_height * parent_size_padded.y;
- px_max_size.x = box->max_width * parent_size_padded.x;
- px_max_size.y = box->max_height * parent_size_padded.y;
+ px_min_size.x = box->min_size.x * parent_size_padded.x;
+ px_min_size.y = box->min_size.y * parent_size_padded.y;
+ px_max_size.x = box->max_size.x * parent_size_padded.x;
+ px_max_size.y = box->max_size.y * parent_size_padded.y;
}
px_size = glm::clamp(px_size, px_min_size, px_max_size);
@@ -202,10 +203,11 @@ void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
if (box->type_data != nullptr) {
// type-specific changes
if (box->type == PKE_UI_BOX_TYPE_TEXT) {
- pke_ui_box_type_data_text *data_text = reinterpret_cast<pke_ui_box_type_data_text*>(box->type_data);
- data_text->font_render_settings.surface_area_pos = box->internal.px_corner;
- data_text->font_render_settings.surface_area_size = box->internal.px_size;
- FontType_UpdateStringRender(data_text->font_render_handle, &data_text->font_render_settings);
+ FontRender *fr = FontType_GetFontRender(box->type_data->text.font_render_handle);
+ FontRenderSettings frs = fr->settings;
+ frs.surface_area_pos = box->internal.px_corner;
+ frs.surface_area_size = box->internal.px_size;
+ FontType_UpdateStringRender(box->type_data->text.font_render_handle, &frs);
}
}
@@ -443,13 +445,19 @@ void pke_ui_teardown() {
pke_ui_master.bindings.deviceMemoryVert = VK_NULL_HANDLE;
}
+pke_ui_box **pke_ui_get_root_boxes(pke_ui_box_count_T *count) {
+ assert(count != nullptr);
+ *count = pke_ui_master.h_root_boxes;
+ return pke_ui_master.root_boxes;
+}
+
void pke_ui_internal_new_typed_box(pke_ui_box *box, const PKE_UI_BOX_TYPE type) {
assert(box->type == type);
switch (type) {
case PKE_UI_BOX_TYPE_STANDARD:
break;
case PKE_UI_BOX_TYPE_TEXT:
- box->type_data = pk_new<pke_ui_box_type_data_text>(pke_ui_master.bkt);
+ box->type_data = pk_new<pke_ui_box_type_data>(pke_ui_master.bkt);
box->flags |= PKE_UI_BOX_FLAG_VISIBILITY_INVISIBLE;
break;
case PKE_UI_BOX_TYPE_INPUT_TEXT: