fix scolling for nested divs
This commit is contained in:
parent
da001601e5
commit
8e39eee4af
@ -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);
|
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
|
// Assign the width and height of an element in the directions that it doesn't need to grow
|
||||||
@ -295,6 +289,23 @@ fn void resolve_placement(Elem* c, Elem* p)
|
|||||||
pl.origin.y += c.bounds.h;
|
pl.origin.y += c.bounds.h;
|
||||||
default: unreachable("unknown layout direction");
|
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)
|
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))!;
|
Elem* c = ctx.find_elem(ctx.tree.get(ch))!;
|
||||||
if (ctx.tree.is_root(ch)) {
|
if (ctx.tree.is_root(ch)) {
|
||||||
resolve_placement(p, &&{});
|
resolve_placement(p, &&{});
|
||||||
update_children_bounds(p, &&{});
|
|
||||||
} else {
|
} else {
|
||||||
resolve_placement(c, p);
|
resolve_placement(c, p);
|
||||||
update_children_bounds(c, p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this stuff would be better elsewhere but we are already iteraring through all
|
// 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)!;
|
ctx.push_rect(elem.bounds.pad(style.margin), elem.z_index, style)!;
|
||||||
|
|
||||||
// update the ctx scissor, it HAS to be after drawing the background
|
// update the ctx scissor, it HAS to be after drawing the background
|
||||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset);
|
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset).max({0,0,0,0});
|
||||||
ctx.push_scissor(elem.bounds.pad(elem.layout.content_offset), elem.z_index)!;
|
ctx.push_scissor(ctx.div_scissor, elem.z_index)!;
|
||||||
|
|
||||||
//elem.events = ctx.get_elem_events(elem);
|
//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
|
// the active_div returns to the parent of the current one
|
||||||
ctx.active_div = ctx.tree.parentof(ctx.active_div)!;
|
ctx.active_div = ctx.tree.parentof(ctx.active_div)!;
|
||||||
Elem* parent = ctx.get_parent()!;
|
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)!;
|
ctx.reset_scissor(elem.z_index)!;
|
||||||
|
|
||||||
update_parent_size(elem, parent);
|
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)!;
|
ctx.push_rect(elem.bounds.pad(style.margin), elem.z_index, style)!;
|
||||||
|
|
||||||
// update the ctx scissor, it HAS to be after drawing the background
|
// update the ctx scissor, it HAS to be after drawing the background
|
||||||
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset);
|
ctx.div_scissor = elem.bounds.pad(elem.layout.content_offset).max({0,0,0,0});
|
||||||
ctx.push_scissor(elem.bounds.pad(elem.layout.content_offset), elem.z_index)!;
|
ctx.push_scissor(ctx.div_scissor, elem.z_index)!;
|
||||||
|
|
||||||
//elem.events = ctx.get_elem_events(elem);
|
//elem.events = ctx.get_elem_events(elem);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user