From 5dfbad23999946b60bd94eda2f5f744d5f68074a Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Mon, 13 Oct 2025 00:26:36 +0200 Subject: [PATCH] notes --- lib/ugui.c3l/src/font.c3 | 18 +++++++++++++++--- lib/ugui.c3l/src/string.c3 | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 lib/ugui.c3l/src/string.c3 diff --git a/lib/ugui.c3l/src/font.c3 b/lib/ugui.c3l/src/font.c3 index a68379d..fd2cab7 100644 --- a/lib/ugui.c3l/src/font.c3 +++ b/lib/ugui.c3l/src/font.c3 @@ -335,6 +335,18 @@ fn TextSize? Ctx.measure_string(&ctx, String text) // character's advance value // TODO: implement a "reflow" flag to toggle reflow if a character goes out of bounds // TODO: also return the total bounds of the laid out string +// TODO: Following improvements +// [ ] struct LineInfo which stores the line information, like offset, width and height, during +// the measurement stage each line is scanned and pushed to the list, then to layout +// simply pop each line. The LineInfo list can be stored on the stack with the tmem allocator +// [ ] if the alignment is TOP_LEFT we can simply skip measuring the string, opting to layout +// it directly +// [ ] implement a macro to fetch and layout each character, this can be used to reduce code +// repetition both here and in measure_string +// [ ] the cursor position can be determined by a separate function like get_cursor_position() +// this way the function can terminate early if the cursor position is found +// [ ] implement a function hit_test_string() to get the character position at point, this can +// be used to implement mouse interactions, like cursor movement and selection <* @param [&in] ctx @param [in] text @@ -484,7 +496,7 @@ fn Rect? Ctx.layout_string(&ctx, String text, Rect bounds, Anchor anchor, int z_ ctx.push_sprite(b, uv, texture_id, z_index, hue)!; origin.x += gp.adv; } - + if (line_start + off + x == cursor) { cursor_rect.x = origin.x; } @@ -493,14 +505,14 @@ fn Rect? Ctx.layout_string(&ctx, String text, Rect bounds, Anchor anchor, int z_ // 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)!; diff --git a/lib/ugui.c3l/src/string.c3 b/lib/ugui.c3l/src/string.c3 new file mode 100644 index 0000000..d7d9e1e --- /dev/null +++ b/lib/ugui.c3l/src/string.c3 @@ -0,0 +1,4 @@ +module ugui; + + +