mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
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:
parent
c3ce562240
commit
fe864af0dc
4 changed files with 24 additions and 13 deletions
|
@ -753,7 +753,6 @@ void MainWidget::set_preview_mode(PreviewMode mode)
|
|||
update_markdown_preview();
|
||||
} else {
|
||||
m_no_preview_action->set_checked(true);
|
||||
m_editor->set_fixed_width(-1);
|
||||
set_web_view_visible(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -693,18 +693,6 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action
|
|||
auto wrapper = m_current_editor_wrapper;
|
||||
m_switch_to_next_editor->activate();
|
||||
m_editors_splitter->remove_child(*wrapper);
|
||||
|
||||
auto child_editors = m_editors_splitter->child_widgets();
|
||||
bool has_child_to_fill_space = false;
|
||||
for (auto& editor : child_editors) {
|
||||
if (editor.max_height() == -1) {
|
||||
has_child_to_fill_space = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has_child_to_fill_space)
|
||||
child_editors.last().set_max_height(-1);
|
||||
|
||||
m_all_editor_wrappers.remove_first_matching([&wrapper](auto& entry) { return entry == wrapper.ptr(); });
|
||||
update_actions();
|
||||
});
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
|||
virtual void leave_event(Core::Event&) override;
|
||||
|
||||
virtual void did_layout() override;
|
||||
virtual void custom_layout() override;
|
||||
|
||||
FixedResizee fixed_resizee() const { return m_fixed_resizee; }
|
||||
void set_fixed_resizee(FixedResizee resizee) { m_fixed_resizee = resizee; }
|
||||
|
@ -56,6 +57,7 @@ private:
|
|||
int m_first_resizee_minimum_size { 0 };
|
||||
int m_second_resizee_minimum_size { 0 };
|
||||
FixedResizee m_fixed_resizee { FixedResizee::First };
|
||||
size_t m_last_child_count { 0 };
|
||||
|
||||
void recompute_grabbables();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue