LibGUI+Apps: Prevent Splitter children from being unresizable

Splitters could be resized in such an order that all their remaining
children were fixed size, leading to unfillable gaps on resize events.

HackStudio and TextEditor already had logic to handle this edge case,
so this patch factors it into a general solution for all Splitters.
At least one widget is now guaranteed to be resizeable after a child
is removed.
This commit is contained in:
thankyouverycool 2022-02-20 08:12:34 -05:00 committed by Idan Horowitz
commit fe864af0dc
Notes: sideshowbarker 2024-07-17 18:21:32 +09:00
4 changed files with 24 additions and 13 deletions

View file

@ -164,6 +164,7 @@ void Splitter::recompute_grabbables()
auto child_widgets = this->child_widgets();
child_widgets.remove_all_matching([&](auto& widget) { return !widget.is_visible(); });
m_last_child_count = child_widgets.size();
if (child_widgets.size() < 2)
return;
@ -236,6 +237,27 @@ void Splitter::did_layout()
recompute_grabbables();
}
void Splitter::custom_layout()
{
auto child_widgets = this->child_widgets();
child_widgets.remove_all_matching([&](auto& widget) { return !widget.is_visible(); });
if (!child_widgets.size())
return;
if (m_last_child_count > child_widgets.size()) {
bool has_child_to_fill_space = false;
for (auto& child : child_widgets) {
if (child.max_size() == Gfx::IntSize { -1, -1 }) {
has_child_to_fill_space = true;
break;
}
}
if (!has_child_to_fill_space)
child_widgets.last().set_fixed_size({ -1, -1 });
}
}
void Splitter::mouseup_event(MouseEvent& event)
{
if (event.button() != MouseButton::Primary)