summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-10-24 15:22:43 -0600
committerAndreas Kling <kling@serenityos.org>2020-10-25 00:13:20 +0200
commit5f9906f1887752ea92e919347cc6ac31678b3cb4 (patch)
tree976df1a2bf12ea77a8329cc9d670f032a374d701
parent2adcabb6b3a8a4eba045a22b26723fe3ed544c25 (diff)
downloadserenity-5f9906f1887752ea92e919347cc6ac31678b3cb4.zip
LibGUI: Fix Splitter sometimes not working after widgets were resized
We need to skip over widgets that are not visible as the layout does not update their location. This fixes finding the correct widgets surrounding the splitter. Fixes #3491
-rw-r--r--Libraries/LibGUI/Splitter.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/Libraries/LibGUI/Splitter.cpp b/Libraries/LibGUI/Splitter.cpp
index caec8f06e5..b4ad00c6ea 100644
--- a/Libraries/LibGUI/Splitter.cpp
+++ b/Libraries/LibGUI/Splitter.cpp
@@ -86,23 +86,30 @@ void Splitter::leave_event(Core::Event&)
bool Splitter::get_resize_candidates_at(const Gfx::IntPoint& position, Widget*& first, Widget*& second)
{
int x_or_y = position.primary_offset_for_orientation(m_orientation);
+ Widget* previous_widget = nullptr;
+ bool found_candidates = false;
+ for_each_child_widget([&](auto& child_widget) {
+ if (!child_widget.is_visible()) {
+ // We need to skip over widgets that are not visible as they
+ // are not necessarily in the correct location (anymore)
+ return IterationDecision::Continue;
+ }
+ if (!previous_widget) {
+ previous_widget = &child_widget;
+ return IterationDecision::Continue;
+ }
- auto child_widgets = this->child_widgets();
- if (child_widgets.size() < 2)
- return false;
-
- for (size_t i = 0; i < child_widgets.size() - 1; ++i) {
- auto* first_candidate = child_widgets[i];
- auto* second_candidate = child_widgets[i + 1];
-
- if (x_or_y > first_candidate->content_rect().last_edge_for_orientation(m_orientation)
- && x_or_y <= second_candidate->content_rect().first_edge_for_orientation(m_orientation)) {
- first = first_candidate;
- second = second_candidate;
- return true;
+ if (x_or_y > previous_widget->content_rect().last_edge_for_orientation(m_orientation)
+ && x_or_y <= child_widget.content_rect().first_edge_for_orientation(m_orientation)) {
+ first = previous_widget;
+ second = &child_widget;
+ found_candidates = true;
+ return IterationDecision::Break;
}
- }
- return false;
+
+ return IterationDecision::Continue;
+ });
+ return found_candidates;
}
void Splitter::mousedown_event(MouseEvent& event)