implemented adaptive size divs

This commit is contained in:
Alessandro Mauri 2024-12-26 22:58:24 +01:00
parent 16adfd7cc5
commit 78e2c64da6
7 changed files with 279 additions and 113 deletions

View file

@ -23,6 +23,11 @@ struct ElemDiv {
Point origin_r, origin_c;
}
// begin a widget container, or div, the size determines the offset (x,y) width and height.
// if the width or height are zero the width or height are set to the maximum available.
// if the width or height are negative the width or height will be calculated based on the children size
// sort similar to a flexbox, and the minimum size is set by the negative of the width or height
// FIXME: there is a bug if the size.w or size.h == -0
fn void! Ctx.div_begin(&ctx, String label, Rect size, bool scroll_x = false, bool scroll_y = false)
{
Id id = ctx.gen_id(label)!;
@ -43,7 +48,13 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size, bool scroll_x = false, boo
elem.div.scroll_y.enabled = scroll_y;
// 2. layout the element
elem.bounds = ctx.position_element(parent, size);
Rect wanted_size = {
.x = size.x,
.y = size.y,
.w = size.w < 0 ? max(elem.div.pcb.w, (short)-size.w) : size.w,
.h = size.h < 0 ? max(elem.div.pcb.h, (short)-size.h) : size.h,
};
elem.bounds = ctx.position_element(parent, wanted_size);
elem.div.children_bounds = elem.bounds;
// update the ctx scissor