From 3ad7445488f19f1331eb25013f471cb0eae7f3e7 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 21 Jun 2021 21:51:20 -0400 Subject: [PATCH] Don't scroll ScrollWidget with left-click but allow scrolling with Alt-click. --- src/ui/ScrollWidget.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index a5baaddd..9ca86d38 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -89,38 +89,37 @@ void ScrollWidget::step() { void ScrollWidget::onButton(const ButtonEvent& e) { - OpaqueWidget::onButton(e); + math::Rect offsetBound = getContainerOffsetBound(); + // Handle Alt-click before children, since most widgets consume Alt-click without needing to. + if (e.button == GLFW_MOUSE_BUTTON_LEFT && e.mods == GLFW_MOD_ALT) { + // Check if scrollable + if (offsetBound.size.x > 0.f || offsetBound.size.y > 0.f) { + e.consume(this); + return; + } + } + + Widget::onButton(e); if (e.isConsumed()) return; // Check if scrollable - math::Rect offsetBound = getContainerOffsetBound(); - if (offsetBound.size.x <= 0.f && offsetBound.size.y <= 0.f) - return; - - if (e.button == GLFW_MOUSE_BUTTON_MIDDLE) { - e.consume(this); + if (offsetBound.size.x > 0.f || offsetBound.size.y > 0.f) { + if (e.button == GLFW_MOUSE_BUTTON_MIDDLE) { + e.consume(this); + } } } void ScrollWidget::onDragStart(const DragStartEvent& e) { - // Check if scrollable - math::Rect offsetBound = getContainerOffsetBound(); - if (offsetBound.size.x <= 0.f && offsetBound.size.y <= 0.f) - return; - - if (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_MIDDLE) { - e.consume(this); - } + e.consume(this); } void ScrollWidget::onDragMove(const DragMoveEvent& e) { - if (e.button == GLFW_MOUSE_BUTTON_LEFT || e.button == GLFW_MOUSE_BUTTON_MIDDLE) { - math::Vec offsetDelta = e.mouseDelta.div(getAbsoluteZoom()); - offset = offset.minus(offsetDelta); - } + math::Vec offsetDelta = e.mouseDelta.div(getAbsoluteZoom()); + offset = offset.minus(offsetDelta); }