From 3d7be2a2df0d003735cde849e84d644fef4be30e Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Fri, 5 Sep 2025 19:56:59 +0200 Subject: [PATCH] implement operator overloading for rects --- lib/ugui.c3l/src/ugui_button.c3 | 6 +++--- lib/ugui.c3l/src/ugui_div.c3 | 2 +- lib/ugui.c3l/src/ugui_shapes.c3 | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ugui.c3l/src/ugui_button.c3 b/lib/ugui.c3l/src/ugui_button.c3 index b4175e1..e255476 100644 --- a/lib/ugui.c3l/src/ugui_button.c3 +++ b/lib/ugui.c3l/src/ugui_button.c3 @@ -49,7 +49,7 @@ fn ElemEvents? Ctx.button_id(&ctx, Id id, String label, String icon) .max = (short)max(min_size, left_pad + icon_size.w + text_size.height.max + right_pad), }; // add style border and padding - elem.layout.content_offset = style.margin.add(style.border).add(style.padding); + elem.layout.content_offset = style.margin + style.border + style.padding; elem.layout.children.w = elem.layout.w; elem.layout.children.h = elem.layout.h; @@ -83,12 +83,12 @@ fn ElemEvents? Ctx.button_id(&ctx, Id id, String label, String icon) s.bg = s.accent; } - Rect border_bounds = elem.bounds.pad(style.margin); - ctx.push_rect(border_bounds, parent.div.z_index, &s)!; + ctx.push_rect(elem.bounds.pad(style.margin), parent.div.z_index, &s)!; if (icon != "") { ctx.push_sprite(icon_bounds, sprite.uv(), ctx.sprite_atlas.id, parent.div.z_index, type: sprite.type)!; } if (label != "") { + ctx.push_rect(text_bounds, parent.div.z_index, &&{.bg=0xff0000abu.@to_rgba()})!; ctx.push_string(text_bounds, label, parent.div.z_index, style.fg)!; } return elem.events; diff --git a/lib/ugui.c3l/src/ugui_div.c3 b/lib/ugui.c3l/src/ugui_div.c3 index 09c1eec..a53cd0c 100644 --- a/lib/ugui.c3l/src/ugui_div.c3 +++ b/lib/ugui.c3l/src/ugui_div.c3 @@ -78,7 +78,7 @@ fn void? Ctx.div_begin_id(&ctx, .h = height, .dir = dir, .anchor = anchor, - .content_offset = style.margin.add(style.border).add(style.padding), + .content_offset = style.margin + style.border + style.padding, }; // update parent grow children diff --git a/lib/ugui.c3l/src/ugui_shapes.c3 b/lib/ugui.c3l/src/ugui_shapes.c3 index b134203..e3a6e81 100644 --- a/lib/ugui.c3l/src/ugui_shapes.c3 +++ b/lib/ugui.c3l/src/ugui_shapes.c3 @@ -55,7 +55,7 @@ macro Rect containing_rect(Rect a, Rect b) macro bool Rect.is_null(Rect r) => r.x == 0 && r.y == 0 && r.x == 0 && r.w == 0; // returns the element-wise addition of r1 and r2 -macro Rect Rect.add(Rect r1, Rect r2) +macro Rect Rect.add(Rect r1, Rect r2) @operator_s(+) { return { .x = r1.x + r2.x, @@ -66,7 +66,7 @@ macro Rect Rect.add(Rect r1, Rect r2) } // returns the element-wise subtraction of r1 and r2 -macro Rect Rect.sub(Rect r1, Rect r2) +macro Rect Rect.sub(Rect r1, Rect r2) @operator_s(-) { return { .x = r1.x - r2.x, @@ -77,7 +77,7 @@ macro Rect Rect.sub(Rect r1, Rect r2) } // returns the element-wise multiplication of r1 and r2 -macro Rect Rect.mul(Rect r1, Rect r2) +macro Rect Rect.mul(Rect r1, Rect r2) @operator_s(*) { return { .x = r1.x * r2.x,