From 18a86e8aaba6b6bb26343c80bb98df63fd9dcec5 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sun, 26 Oct 2025 17:48:42 +0100 Subject: [PATCH] vertical and horizontal lines, @row and @column return their ids like @div --- src/widgets/div.c3 | 6 ++--- src/widgets/separator.c3 | 48 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/widgets/div.c3 b/src/widgets/div.c3 index cd74c23..4d03129 100644 --- a/src/widgets/div.c3 +++ b/src/widgets/div.c3 @@ -20,21 +20,21 @@ struct ElemDiv { macro Ctx.@center(&ctx, LayoutDirection dir = ROW, ...; @body()) { - ctx.@div(@grow(), @grow(), dir, CENTER) { + return ctx.@div(@grow(), @grow(), dir, CENTER) { @body(); }!; } macro Ctx.@row(&ctx, Anchor anchor = TOP_LEFT, ...; @body()) { - ctx.@div(@fit(), @fit(), ROW, anchor: anchor) { + return ctx.@div(@fit(), @fit(), ROW, anchor: anchor) { @body(); }!; } macro Ctx.@column(&ctx, Anchor anchor = TOP_LEFT, ...; @body()) { - ctx.@div(@fit(), @fit(), COLUMN, anchor: anchor) { + return ctx.@div(@fit(), @fit(), COLUMN, anchor: anchor) { @body(); }!; } diff --git a/src/widgets/separator.c3 b/src/widgets/separator.c3 index 1c1adae..505245f 100644 --- a/src/widgets/separator.c3 +++ b/src/widgets/separator.c3 @@ -1,16 +1,56 @@ module ugui; -macro Ctx.separator(&ctx, int width, int height, ...) +macro Ctx.separator(&ctx, Size width, Size height, ...) => ctx.separator_id(@compute_id($vasplat), width, height); -fn void? Ctx.separator_id(&ctx, Id id, int width, int height) +fn void? Ctx.separator_id(&ctx, Id id, Size width, Size height) { id = ctx.gen_id(id)!; Elem* parent, elem; ctx.get_elem(id, ETYPE_NONE)!.unpack(&elem, &parent); - elem.layout.w = @exact((short)width); - elem.layout.h = @exact((short)height); + elem.layout.w = width; + elem.layout.h = height; update_parent_size(elem, parent); +} + + +macro Ctx.hor_line(&ctx, ...) + => ctx.hor_line_id(@compute_id($vasplat)); +fn void? Ctx.hor_line_id(&ctx, Id id) +{ + id = ctx.gen_id(id)!; + Elem* parent, elem; + ctx.get_elem(id, ETYPE_NONE)!.unpack(&elem, &parent); + Style* style = ctx.styles.get_style(@str_hash("separator")); + + elem.layout.w = @grow(); + elem.layout.h = @exact(style.size); + elem.layout.content_offset = style.margin + style.border + style.padding; + + update_parent_size(elem, parent); + + Rect r = elem.bounds.pad(elem.layout.content_offset); + ctx.push_rect(r, elem.z_index, style)!; +} + + +macro Ctx.ver_line(&ctx, ...) + => ctx.ver_line_id(@compute_id($vasplat)); +fn void? Ctx.ver_line_id(&ctx, Id id) +{ + id = ctx.gen_id(id)!; + Elem* parent, elem; + ctx.get_elem(id, ETYPE_NONE)!.unpack(&elem, &parent); + Style* style = ctx.styles.get_style(@str_hash("separator")); + + elem.layout.w = @exact(style.size); + elem.layout.h = @grow(); + elem.layout.content_offset = style.margin + style.border + style.padding; + + update_parent_size(elem, parent); + + Rect r = elem.bounds.pad(elem.layout.content_offset); + ctx.push_rect(r, elem.z_index, style)!; } \ No newline at end of file