From d47b835020468ebffc5c9d75fb512bc4867b9bc5 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 27 Sep 2025 12:43:38 +0200 Subject: [PATCH] fix cursor placement --- lib/ugui.c3l/src/ugui_font.c3 | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/ugui.c3l/src/ugui_font.c3 b/lib/ugui.c3l/src/ugui_font.c3 index f96a12e..eaf76ff 100644 --- a/lib/ugui.c3l/src/ugui_font.c3 +++ b/lib/ugui.c3l/src/ugui_font.c3 @@ -414,19 +414,12 @@ fn Rect? Ctx.layout_string(&ctx, String text, Rect bounds, Anchor anchor, int z_ next_line_x += bounds.w; } - // reset the cursor to the line if (line_start <= cursor && cursor <= line_end) { cursor_rect.x = origin.x; cursor_rect.y = origin.y; cursor_rect.w = 0; - if (cursor && text[cursor-1] == '\n') { - cursor_rect.x = next_line_x; - cursor_rect.y += line_height; - } } - Point line_origin = origin; - // see the fixme when measuring the height //ctx.push_rect({.x = origin.x,.y=origin.y,.w=(short)line_width,.h=(short)string_height}, z_index, &&(Style){.bg=0xff000042u.@to_rgba()})!; String line = text[line_start:line_end-line_start]; @@ -454,21 +447,25 @@ fn Rect? Ctx.layout_string(&ctx, String text, Rect bounds, Anchor anchor, int z_ }; ctx.push_sprite(b, uv, texture_id, z_index, hue)!; //ctx.push_rect(b, z_index, &&(Style){.bg=0x0000ff66u.@to_rgba()})!; - origin.x += gp.adv; } - - if (line_start + off < cursor && text[cursor-1] != '\n') { + + if (line_start + off + x == cursor) { cursor_rect.x = origin.x; - cursor_rect.y = origin.y; - cursor_rect.w = gp.adv; } } // done with the line line_start = line_end; origin.y += line_height + line_gap; + + if (cursor == text.len && text[^1] == '\n') { + cursor_rect.x = next_line_x; + cursor_rect.y = origin.y; + } + } while(line_end < text.len); + ctx.reset_scissor(z_index)!;