diff options
Diffstat (limited to 'src/static-ui.cpp')
| -rw-r--r-- | src/static-ui.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp index f05a8dd..1c089b9 100644 --- a/src/static-ui.cpp +++ b/src/static-ui.cpp @@ -224,6 +224,17 @@ void pke_ui_calc_px(DynArray<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl buffer_item->px_scale.x = (2.0 / (float)Extent.width); buffer_item->px_scale.y = (2.0 / (float)Extent.height); buffer_item->depth = (float)box->layer; + + if (box->type_data == nullptr) return; + + // 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); + return; + } } void pke_ui_recalc_sizes_recursive(DynArray<pke_ui_box_instance_buffer_item> &arr, pke_ui_box *box, uint8_t depth = 0) { @@ -429,7 +440,22 @@ void pke_ui_teardown() { pke_ui_master.bindings.deviceMemoryVert = VK_NULL_HANDLE; } -pke_ui_box *pke_ui_box_new_root() { +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); + break; + case PKE_UI_BOX_TYPE_INPUT_TEXT: + break; + default: + break; + } +} + +pke_ui_box *pke_ui_box_new_root(const PKE_UI_BOX_TYPE type) { if (pke_ui_master.h_root_boxes == pke_ui_master.r_root_boxes) { pke_ui_box_count_T prev_r_root_boxes = pke_ui_master.r_root_boxes; pke_ui_master.r_root_boxes *= 1.5; @@ -445,11 +471,21 @@ pke_ui_box *pke_ui_box_new_root() { pke_ui_master.root_boxes[pke_ui_master.h_root_boxes] = box; pke_ui_master.h_root_boxes += 1; pke_ui_master.should_recalc_ui = true; + box->type = type; + pke_ui_internal_new_typed_box(box, type); return box; } -pke_ui_box *pke_ui_box_new_child(pke_ui_box *parent) { +pke_ui_box *pke_ui_box_new_child(pke_ui_box *parent, const PKE_UI_BOX_TYPE type) { assert(parent != nullptr); + + // validation + if (parent->type >= PKE_UI_BOX_TYPE_TEXT) { + // this might be too broad, alter if needed + fprintf(stdout, "[pke_ui_box_new_child] Validation error: PKE_UI_BOX_TYPE_TEXT cannot have children."); + return nullptr; + } + if (parent->internal.h_children == parent->internal.r_children) { pke_ui_box_count_T prev_r_children = parent->internal.r_children; parent->internal.r_children = PK_MAX(parent->internal.r_children * 1.5, 2); @@ -466,8 +502,10 @@ pke_ui_box *pke_ui_box_new_child(pke_ui_box *parent) { memset(box, 0, sizeof(pke_ui_box)); parent->internal.children[parent->internal.h_children] = box; parent->internal.h_children += 1; + box->type = type; box->internal.parent = parent; pke_ui_master.should_recalc_ui = true; + pke_ui_internal_new_typed_box(box, type); return box; } |
