implement operator overloading for rects

This commit is contained in:
Alessandro Mauri 2025-09-05 19:56:59 +02:00
parent 335624fcbe
commit 3d7be2a2df
3 changed files with 7 additions and 7 deletions

View File

@ -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;

View File

@ -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

View File

@ -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,