vertical and horizontal lines, @row and @column return their ids like @div

This commit is contained in:
Alessandro Mauri 2025-10-26 17:48:42 +01:00
parent 4f7fa7d50c
commit 18a86e8aab
2 changed files with 47 additions and 7 deletions

View File

@ -20,21 +20,21 @@ struct ElemDiv {
macro Ctx.@center(&ctx, LayoutDirection dir = ROW, ...; @body()) macro Ctx.@center(&ctx, LayoutDirection dir = ROW, ...; @body())
{ {
ctx.@div(@grow(), @grow(), dir, CENTER) { return ctx.@div(@grow(), @grow(), dir, CENTER) {
@body(); @body();
}!; }!;
} }
macro Ctx.@row(&ctx, Anchor anchor = TOP_LEFT, ...; @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(); @body();
}!; }!;
} }
macro Ctx.@column(&ctx, Anchor anchor = TOP_LEFT, ...; @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(); @body();
}!; }!;
} }

View File

@ -1,16 +1,56 @@
module ugui; 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); => 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)!; id = ctx.gen_id(id)!;
Elem* parent, elem; Elem* parent, elem;
ctx.get_elem(id, ETYPE_NONE)!.unpack(&elem, &parent); ctx.get_elem(id, ETYPE_NONE)!.unpack(&elem, &parent);
elem.layout.w = @exact((short)width); elem.layout.w = width;
elem.layout.h = @exact((short)height); elem.layout.h = height;
update_parent_size(elem, parent); 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)!;
} }