From 315f8496b61db8347b694e2efadfe6ff9ccc7702 Mon Sep 17 00:00:00 2001 From: Jyrki Vesterinen Date: Tue, 6 Jun 2017 22:36:30 +0300 Subject: [PATCH] Allow widget::find_at() to return a scrollbar container If the pointer wasn't on top of any widget within a scrollbar container, when GUI2 queried the widget on which a UI event occurred, the answer was "no widget" and the whole event was discarded. That was problematic if the player was trying to scroll. It is desired that scrolling is possible even if the pointer isn't on a widget (as long as it's somewhere within the scrollbar container). Now the query will return "scrollbar container" and dispatch the event to it. That allows the player to scroll anywhere within a scrollbar container. Also, now the GUI2 event chain includes the target widget itself, not only its ancestors. Fixes #1632. --- src/gui/core/event/dispatcher_private.hpp | 6 +++--- src/gui/widgets/scrollbar_container.cpp | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/gui/core/event/dispatcher_private.hpp b/src/gui/core/event/dispatcher_private.hpp index 6db1cc5d2399..ad1e3c4c94cd 100644 --- a/src/gui/core/event/dispatcher_private.hpp +++ b/src/gui/core/event/dispatcher_private.hpp @@ -306,12 +306,12 @@ build_event_chain(const ui_event event, widget* dispatcher, widget* w) std::vector> result; while(w != dispatcher) { - w = w->parent(); - assert(w); - if(w->has_event(event, dispatcher::event_queue_type(dispatcher::pre | dispatcher::post))) { result.emplace_back(w, event); } + + w = w->parent(); + assert(w); } return result; diff --git a/src/gui/widgets/scrollbar_container.cpp b/src/gui/widgets/scrollbar_container.cpp index d311f9e45a9f..4dfa78318706 100644 --- a/src/gui/widgets/scrollbar_container.cpp +++ b/src/gui/widgets/scrollbar_container.cpp @@ -516,15 +516,23 @@ unsigned scrollbar_container::get_state() const widget* scrollbar_container::find_at(const point& coordinate, const bool must_be_active) { - return scrollbar_container_implementation::find_at( + widget* w = scrollbar_container_implementation::find_at( *this, coordinate, must_be_active); + if(w == nullptr) { + w = widget::find_at(coordinate, must_be_active); + } + return w; } const widget* scrollbar_container::find_at(const point& coordinate, const bool must_be_active) const { - return scrollbar_container_implementation::find_at( + const widget* w = scrollbar_container_implementation::find_at( *this, coordinate, must_be_active); + if(w == nullptr) { + w = widget::find_at(coordinate, must_be_active); + } + return w; } widget* scrollbar_container::find(const std::string& id,