optional anchor in text_box

This commit is contained in:
Alessandro Mauri 2025-09-27 12:43:21 +02:00
parent 63b3d05b19
commit f1b6321d3d
2 changed files with 6 additions and 5 deletions

View File

@ -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, ...) 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); => 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) fn ElemEvents? Ctx.text_box_id(&ctx, Id id, Size w, Size h, TextEdit* te, Anchor text_alignment)
{ {
id = ctx.gen_id(id)!; 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); Rect text_bounds = elem.bounds.pad(elem.layout.content_offset);
ctx.push_rect(bg_bounds, parent.div.z_index, style)!; ctx.push_rect(bg_bounds, parent.div.z_index, style)!;
Rect cur; 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 // draw the cursor if the element has focus
cur.w = 2; cur.w = 2;
cur.x -= 2;
if (elem.events.has_focus) { if (elem.events.has_focus) {
ctx.push_scissor(text_bounds, parent.div.z_index)!; ctx.push_scissor(text_bounds, parent.div.z_index)!;
ctx.push_rect(cur, parent.div.z_index, &&(Style){.bg = style.fg})!; ctx.push_rect(cur, parent.div.z_index, &&(Style){.bg = style.fg})!;

View File

@ -423,7 +423,7 @@ fn void calculator(ugui::Ctx* ui, TextEdit* te)
ui.slider_ver(ugui::@exact(20), ugui::@exact(100), &f)!!; ui.slider_ver(ugui::@exact(20), ugui::@exact(100), &f)!!;
}!!; }!!;
ui.@div(ugui::@grow(), ugui::@fit(), anchor: CENTER, scroll_y: true) { 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)!!;
}!!; }!!;
}!!; }!!; }!!; }!!;