From 849b267f9142884857e0614d7101b334c11e0ab3 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Tue, 1 Jul 2025 15:33:22 +0200 Subject: [PATCH] renamed get_element_by_tree_idx to get_active_div --- lib/ugui.c3l/src/ugui_core.c3 | 15 +++------------ lib/ugui.c3l/src/ugui_div.c3 | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/ugui.c3l/src/ugui_core.c3 b/lib/ugui.c3l/src/ugui_core.c3 index 24c90d2..cb64e8b 100644 --- a/lib/ugui.c3l/src/ugui_core.c3 +++ b/lib/ugui.c3l/src/ugui_core.c3 @@ -183,17 +183,7 @@ macro Elem* Ctx.find_elem(&ctx, Id id) return elem; } -// FIXME: Since ids are now keyed with the element's parent id, this function does not work -// outside of the element's div block. -// this searches an element in the cache by label, it does not create a new element -// if it does't find one -//macro Ctx.get_elem_by_label(&ctx, String label) -//{ -// Id id = ctx.get_id(label); -// return ctx.cache.search(id); -//} - -macro Ctx.get_elem_by_tree_idx(&ctx, isz idx) @private +fn Elem*? Ctx.get_active_div(&ctx) { Id id = ctx.tree.get(ctx.active_div)!; return ctx.cache.search(id); @@ -278,7 +268,8 @@ const int DEBUG = 1; fn void? Ctx.frame_end(&ctx) { - Elem* root = ctx.get_elem_by_tree_idx(0)!; + // FIXME: this is not guaranteed to be root. the user might forget to close a div or some other element + Elem* root = ctx.get_active_div()!; root.div.layout = LAYOUT_ROW; // 1. clear the tree diff --git a/lib/ugui.c3l/src/ugui_div.c3 b/lib/ugui.c3l/src/ugui_div.c3 index caa9e25..f259096 100644 --- a/lib/ugui.c3l/src/ugui_div.c3 +++ b/lib/ugui.c3l/src/ugui_div.c3 @@ -87,7 +87,7 @@ fn void? Ctx.div_end(&ctx) { // swap the children bounds Elem* parent = ctx.get_parent()!; - Elem* elem = ctx.get_elem_by_tree_idx(ctx.active_div)!; + Elem* elem = ctx.get_active_div()!; elem.div.pcb = elem.div.children_bounds; // FIXME: this causes all elements inside the div to loose focus since the mouse press happens