Browse Source

Don't scroll ScrollWidget with left-click but allow scrolling with Alt-click.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
3ad7445488
1 changed files with 18 additions and 19 deletions
  1. +18
    -19
      src/ui/ScrollWidget.cpp

+ 18
- 19
src/ui/ScrollWidget.cpp View File

@@ -89,38 +89,37 @@ void ScrollWidget::step() {




void ScrollWidget::onButton(const ButtonEvent& e) { 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()) if (e.isConsumed())
return; return;


// Check if scrollable // 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) { 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) { 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);
} }






Loading…
Cancel
Save