Skip to content

Commit

Permalink
Allow widget::find_at() to return a scrollbar container
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jyrkive committed Jun 6, 2017
1 parent 5ba35e4 commit 315f849
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/gui/core/event/dispatcher_private.hpp
Expand Up @@ -306,12 +306,12 @@ build_event_chain(const ui_event event, widget* dispatcher, widget* w)
std::vector<std::pair<widget*, ui_event>> 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;
Expand Down
12 changes: 10 additions & 2 deletions src/gui/widgets/scrollbar_container.cpp
Expand Up @@ -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>(
widget* w = scrollbar_container_implementation::find_at<widget>(
*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>(
const widget* w = scrollbar_container_implementation::find_at<const widget>(
*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,
Expand Down

0 comments on commit 315f849

Please sign in to comment.