initial work on scrollable divs

This commit is contained in:
Alessandro Mauri 2024-11-07 18:35:20 +01:00
parent 8bc38452b3
commit 250a0fb3b5
5 changed files with 104 additions and 83 deletions

View file

@ -81,7 +81,7 @@ fn void! Ctx.frame_begin(&ctx)
.h = ctx.height,
},
.div = {
.layout = LAYOUT_ROW,
.layout = LAYOUT_ROW,
},
.flags = c_elem.flags,
};
@ -120,60 +120,6 @@ $if 1:
$endif
}
fn void! Ctx.div_begin(&ctx, String label, Rect size)
{
Id id = hash(label);
Elem *parent = ctx.get_parent()!;
Elem* c_elem = ctx.get_elem(id)!;
isz div_node = ctx.tree.add(id, ctx.active_div)!;
ctx.active_div = div_node;
// 1. Fill the element fields
c_elem.type = ETYPE_DIV;
// do layout and update flags only if the element was updated
if (c_elem.flags.is_new || parent.flags.updated) {
// 2. layout the element
c_elem.bounds = ctx.position_element(parent, size);
// 3. Mark the element as updated
c_elem.flags.updated = true;
// 4. Fill the div fields
c_elem.div.layout = parent.div.layout;
c_elem.div.origin_c = Point{
.x = c_elem.bounds.x,
.y = c_elem.bounds.y,
};
c_elem.div.color_bg = uint_to_rgba(0xff0000ff);
c_elem.div.origin_r = c_elem.div.origin_c;
} else if (parent.flags.has_focus) {
if (point_in_rect(ctx.input.mouse.pos, c_elem.bounds)) {
c_elem.flags.has_focus = true;
}
} else {
// TODO: check active
// TODO: check scrollbars
// TODO: check resizeable
}
// Add the background to the draw stack
Cmd cmd = {
.type = CMD_RECT,
.rect = {
.rect = c_elem.bounds,
.color = c_elem.div.color_bg,
},
};
ctx.cmd_queue.enqueue(&cmd)!;
}
fn void! Ctx.div_end(&ctx)
{
// the active_div returns to the parent of the current one
ctx.active_div = ctx.tree.parentof(ctx.active_div)!;
}
/**
* @ensure elem != null
**/