From f1b6321d3d41116ec5d06c61a3ee09ebcefeebb7 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 27 Sep 2025 12:43:21 +0200 Subject: [PATCH] optional anchor in text_box --- lib/ugui.c3l/src/widgets/ugui_text.c3 | 9 +++++---- src/main.c3 | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/ugui.c3l/src/widgets/ugui_text.c3 b/lib/ugui.c3l/src/widgets/ugui_text.c3 index 083b2d9..47a14f5 100644 --- a/lib/ugui.c3l/src/widgets/ugui_text.c3 +++ b/lib/ugui.c3l/src/widgets/ugui_text.c3 @@ -39,9 +39,9 @@ fn void? Ctx.text_id(&ctx, Id id, String text) } -macro Ctx.text_box(&ctx, Size w, Size h, TextEdit* te, ...) - => ctx.text_box_id(@compute_id($vasplat), w, h, te); -fn ElemEvents? Ctx.text_box_id(&ctx, Id id, Size w, Size h, TextEdit* te) +macro Ctx.text_box(&ctx, Size w, Size h, TextEdit* te, Anchor text_alignment = TOP_LEFT, ...) + => ctx.text_box_id(@compute_id($vasplat), w, h, te, text_alignment); +fn ElemEvents? Ctx.text_box_id(&ctx, Id id, Size w, Size h, TextEdit* te, Anchor text_alignment) { id = ctx.gen_id(id)!; @@ -77,10 +77,11 @@ fn ElemEvents? Ctx.text_box_id(&ctx, Id id, Size w, Size h, TextEdit* te) Rect text_bounds = elem.bounds.pad(elem.layout.content_offset); ctx.push_rect(bg_bounds, parent.div.z_index, style)!; Rect cur; - cur = ctx.layout_string(elem.text.te.to_string(), text_bounds, TOP_LEFT, parent.div.z_index, style.fg, elem.text.te.cursor)!; + cur = ctx.layout_string(elem.text.te.to_string(), text_bounds, text_alignment, parent.div.z_index, style.fg, elem.text.te.cursor)!; // draw the cursor if the element has focus cur.w = 2; + cur.x -= 2; if (elem.events.has_focus) { ctx.push_scissor(text_bounds, parent.div.z_index)!; ctx.push_rect(cur, parent.div.z_index, &&(Style){.bg = style.fg})!; diff --git a/src/main.c3 b/src/main.c3 index 9d89bc5..926d10c 100644 --- a/src/main.c3 +++ b/src/main.c3 @@ -423,7 +423,7 @@ fn void calculator(ugui::Ctx* ui, TextEdit* te) ui.slider_ver(ugui::@exact(20), ugui::@exact(100), &f)!!; }!!; ui.@div(ugui::@grow(), ugui::@fit(), anchor: CENTER, scroll_y: true) { - ui.text_box(ugui::@grow(), ugui::@exact(100), te)!!; + ui.text_box(ugui::@grow(), ugui::@exact(100), te, RIGHT)!!; }!!; }!!; }!!;