Skip to content

Commit

Permalink
Don't let invisible widgets participate in layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Kristian Arntzen committed Jun 24, 2019
1 parent 667f0ad commit 4a0bbf3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ui/horizontal_packing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)

unsigned fixed_children = 0;
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
fixed_children++;
}

if (!children.empty())
{
Expand All @@ -45,6 +50,9 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)
// Make sure we allocate the minimum.
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (child.widget->is_floating())
{
child.size = max(child.widget->get_minimum_geometry(), child.widget->get_target_geometry());
Expand All @@ -66,6 +74,9 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating() && (child.size.x < child.widget->get_target_geometry().x))
padding_targets++;
}
Expand All @@ -78,6 +89,9 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)
// If we have some slack room, use at most extra_height_per_object to pad from minimum to target.
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
{
float desired_padding = max(
Expand All @@ -95,8 +109,13 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)
unsigned padding_targets = 0;

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating() && child.widget->get_size_is_flexible())
padding_targets++;
}

if (padding_targets)
{
Expand All @@ -105,6 +124,9 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)
// If we have some slack room, use at most extra_height_per_object to pad from minimum to target.
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating() && child.widget->get_size_is_flexible())
child.size.x += extra_width_per_object;
slack_width -= extra_width_per_object;
Expand All @@ -114,6 +136,9 @@ void HorizontalPacking::reconfigure_to_canvas(vec2, vec2 size)

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
{
off.x += geometry.margin;
Expand Down Expand Up @@ -143,6 +168,9 @@ void HorizontalPacking::reconfigure()

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (child.widget->is_floating())
{
minimum = max(minimum,
Expand Down
25 changes: 25 additions & 0 deletions ui/vertical_packing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)

unsigned fixed_children = 0;
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
fixed_children++;
}

if (!children.empty())
{
Expand All @@ -45,6 +50,9 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)
// Make sure we allocate the minimum.
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (child.widget->is_floating())
{
child.size = max(child.widget->get_minimum_geometry(), child.widget->get_target_geometry());
Expand All @@ -66,6 +74,9 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating() && (child.size.y < child.widget->get_target_geometry().y))
padding_targets++;
}
Expand All @@ -78,6 +89,9 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)
// If we have some slack room, use at most extra_height_per_object to pad from minimum to target.
for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
{
float desired_padding = max(
Expand All @@ -95,8 +109,13 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)
unsigned padding_targets = 0;

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating() && child.widget->get_size_is_flexible())
padding_targets++;
}

if (padding_targets)
{
Expand All @@ -114,6 +133,9 @@ void VerticalPacking::reconfigure_to_canvas(vec2, vec2 size)

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (!child.widget->is_floating())
{
off.y += geometry.margin;
Expand Down Expand Up @@ -143,6 +165,9 @@ void VerticalPacking::reconfigure()

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (child.widget->is_floating())
{
minimum = max(minimum,
Expand Down
3 changes: 3 additions & 0 deletions ui/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Widget *Window::on_mouse_button_pressed(vec2 offset)

for (auto &child : children)
{
if (!child.widget->get_visible())
continue;

if (any(lessThan(offset, child.offset + vec2(0.0f, off_y))) ||
any(greaterThanEqual(offset, child.offset + vec2(0.0f, off_y) + child.size)))
continue;
Expand Down

0 comments on commit 4a0bbf3

Please sign in to comment.