Compare commits
4 Commits
6a88ea55ec
...
8e39eee4af
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e39eee4af | |||
| da001601e5 | |||
| 665e10fa30 | |||
| 66acf8d4a3 |
@ -93,6 +93,7 @@ fn void? Ctx.input_window_size(&ctx, short width, short height)
|
||||
ctx.current_input.events.resize = ctx.width != width || ctx.height != height;
|
||||
ctx.width = width;
|
||||
ctx.height = height;
|
||||
if (ctx.current_input.events.resize) ctx.skip_frame = true;
|
||||
}
|
||||
|
||||
// Window gained/lost focus
|
||||
|
||||
@ -132,12 +132,6 @@ fn void update_parent_size(Elem* child, Elem* parent)
|
||||
}
|
||||
}
|
||||
|
||||
fn void update_children_bounds(Elem* child, Elem* parent)
|
||||
{
|
||||
if (child.layout.absolute) return;
|
||||
parent.children_bounds = containing_rect(child.bounds + parent.layout.scroll_offset, parent.bounds);
|
||||
}
|
||||
|
||||
macro Rect Elem.content_bounds(&elem) => elem.bounds.pad(elem.layout.content_offset);
|
||||
|
||||
// Assign the width and height of an element in the directions that it doesn't need to grow
|
||||
@ -205,7 +199,7 @@ fn void resolve_placement(Elem* c, Elem* p)
|
||||
// if the element has absolute position assign the origin and do not update the parent
|
||||
if (cl.absolute) {
|
||||
c.bounds.x = p.bounds.x + pl.content_offset.x + cl.origin.x;
|
||||
c.bounds.y = p.bounds.x + pl.content_offset.x + cl.origin.y;
|
||||
c.bounds.y = p.bounds.y + pl.content_offset.y + cl.origin.y;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -295,6 +289,23 @@ fn void resolve_placement(Elem* c, Elem* p)
|
||||
pl.origin.y += c.bounds.h;
|
||||
default: unreachable("unknown layout direction");
|
||||
}
|
||||
|
||||
// update the parent children_bounds
|
||||
// FIXME: this causes scollbars to flicker in/out during resize because the current frames children_bounds are updated
|
||||
// with the previous' frame child bounds. It would be better to implement another pass during layout.
|
||||
// FIXME: this long way around to compute the children bounds works and reduces flickering, but it is very ugly
|
||||
Rect ncb = c.children_bounds;
|
||||
ncb.x = c.bounds.x;
|
||||
ncb.y = c.bounds.y;
|
||||
Rect cb = containing_rect(c.bounds, ncb);
|
||||
Point o = p.layout.scroll_offset;
|
||||
p.children_bounds = containing_rect(cb + o, p.children_bounds);
|
||||
|
||||
// reset the children bounds
|
||||
c.children_bounds = {
|
||||
.x = c.bounds.x,
|
||||
.y = c.bounds.y
|
||||
};
|
||||
}
|
||||
|
||||
fn void? Ctx.layout_element_tree(&ctx)
|
||||
@ -330,10 +341,8 @@ fn void? Ctx.layout_element_tree(&ctx)
|
||||
Elem* c = ctx.find_elem(ctx.tree.get(ch))!;
|
||||
if (ctx.tree.is_root(ch)) {
|
||||
resolve_placement(p, &&{});
|
||||
update_children_bounds(p, &&{});
|
||||
} else {
|
||||
resolve_placement(c, p);
|
||||
update_children_bounds(c, p);
|
||||
}
|
||||
|
||||
// FIXME: this stuff would be better elsewhere but we are already iteraring through all
|
||||
|
||||
@ -105,8 +105,8 @@ fn void? Ctx.div_begin_id(&ctx,
|
||||
ctx.push_rect(elem.bounds.pad(style.margin), elem.z_index, style)!;
|
||||
|
||||
// update the ctx scissor, it HAS to be after drawing the background
|
||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset);
|
||||
ctx.push_scissor(elem.bounds.pad(elem.layout.content_offset), elem.z_index)!;
|
||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset).max({0,0,0,0});
|
||||
ctx.push_scissor(ctx.div_scissor, elem.z_index)!;
|
||||
|
||||
//elem.events = ctx.get_elem_events(elem);
|
||||
|
||||
@ -164,7 +164,7 @@ fn Id? Ctx.div_end(&ctx)
|
||||
// the active_div returns to the parent of the current one
|
||||
ctx.active_div = ctx.tree.parentof(ctx.active_div)!;
|
||||
Elem* parent = ctx.get_parent()!;
|
||||
ctx.div_scissor = parent.bounds.pad(parent.layout.content_offset);
|
||||
ctx.div_scissor = parent.bounds.pad(parent.layout.content_offset).max({0,0,0,0});
|
||||
ctx.reset_scissor(elem.z_index)!;
|
||||
|
||||
update_parent_size(elem, parent);
|
||||
@ -236,8 +236,8 @@ fn bool? Ctx.popup_begin_id(&ctx,
|
||||
ctx.push_rect(elem.bounds.pad(style.margin), elem.z_index, style)!;
|
||||
|
||||
// update the ctx scissor, it HAS to be after drawing the background
|
||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset);
|
||||
ctx.push_scissor(elem.bounds.pad(elem.layout.content_offset), elem.z_index)!;
|
||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset).max({0,0,0,0});
|
||||
ctx.push_scissor(ctx.div_scissor, elem.z_index)!;
|
||||
|
||||
//elem.events = ctx.get_elem_events(elem);
|
||||
|
||||
|
||||
@ -140,23 +140,22 @@ fn void? Ctx.scrollbar(&ctx, Id id, float *value, float handle_percent, bool ver
|
||||
Style* style = ctx.styles.get_style(@str_hash("scrollbar"));
|
||||
|
||||
Rect pb = parent.bounds.pad(parent.layout.content_offset);
|
||||
elem.bounds.x = vertical ? pb.bottom_right().x - style.size: pb.x;
|
||||
elem.bounds.y = vertical ? pb.y : pb.bottom_right().y - style.size;
|
||||
if (vertical) {
|
||||
elem.layout.w = @exact(style.size);
|
||||
elem.layout.h = @grow();
|
||||
elem.bounds.x -= style.margin.x + style.margin.w + style.border.x + style.border.w;
|
||||
elem.layout.origin.x = pb.w - style.size;
|
||||
elem.layout.origin.y = 0;
|
||||
} else {
|
||||
elem.layout.w = @grow();
|
||||
elem.layout.h = @exact(style.size);
|
||||
elem.bounds.y -= style.margin.y + style.margin.h + style.border.y + style.border.h;
|
||||
elem.layout.origin.x = 0;
|
||||
elem.layout.origin.y = pb.h - style.size;
|
||||
}
|
||||
elem.layout.content_offset = style.margin + style.border + style.padding;
|
||||
elem.layout.absolute = true;
|
||||
update_parent_size(elem, parent);
|
||||
|
||||
Rect content_bounds = elem.bounds.pad(elem.layout.content_offset);
|
||||
//elem.events = ctx.get_elem_events(elem);
|
||||
|
||||
short o = vertical ? content_bounds.y : content_bounds.x;
|
||||
short m = vertical ? ctx.input.mouse.pos.y : ctx.input.mouse.pos.x;
|
||||
|
||||
@ -21,8 +21,8 @@ fn void? Ctx.sprite_id(&ctx, Id id, String name, short size = 0)
|
||||
short height = sprite.h;
|
||||
if (size > 0) {
|
||||
if (sprite.w >= sprite.h) {
|
||||
width = size;
|
||||
height = (short)(size * (float)height/width);
|
||||
width = size;
|
||||
} else {
|
||||
width = (short)(size * (float)width/height);
|
||||
height = size;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user