From 3073bef99576048359d228cc7f29442f45e50648 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 14 Nov 2019 09:16:43 -0500 Subject: [PATCH] Add page up/down, home, and end key commands to ScrollWidget. --- include/ui/ScrollWidget.hpp | 1 + src/ui/ScrollWidget.cpp | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/ui/ScrollWidget.hpp b/include/ui/ScrollWidget.hpp index 1a40bf8a..48fb147c 100644 --- a/include/ui/ScrollWidget.hpp +++ b/include/ui/ScrollWidget.hpp @@ -23,6 +23,7 @@ struct ScrollWidget : widget::OpaqueWidget { void onDragStart(const event::DragStart& e) override; void onDragMove(const event::DragMove& e) override; void onHoverScroll(const event::HoverScroll& e) override; + void onHoverKey(const event::HoverKey& e) override; }; diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index ce691871..85e38c86 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -112,6 +112,51 @@ void ScrollWidget::onHoverScroll(const event::HoverScroll& e) { e.consume(this); } +void ScrollWidget::onHoverKey(const event::HoverKey& e) { + OpaqueWidget::onHoverKey(e); + if (e.isConsumed()) + return; + + if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { + if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == 0) { + offset.y -= box.size.y * 0.5; + e.consume(this); + } + else if (e.key == GLFW_KEY_PAGE_UP && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + offset.x -= box.size.x * 0.5; + e.consume(this); + } + else if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == 0) { + offset.y += box.size.y * 0.5; + e.consume(this); + } + else if (e.key == GLFW_KEY_PAGE_DOWN && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + offset.x += box.size.x * 0.5; + e.consume(this); + } + else if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == 0) { + math::Rect containerBox = container->getChildrenBoundingBox(); + offset.y = containerBox.getTop(); + e.consume(this); + } + else if (e.key == GLFW_KEY_HOME && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + math::Rect containerBox = container->getChildrenBoundingBox(); + offset.x = containerBox.getLeft(); + e.consume(this); + } + else if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == 0) { + math::Rect containerBox = container->getChildrenBoundingBox(); + offset.y = containerBox.getBottom(); + e.consume(this); + } + else if (e.key == GLFW_KEY_END && (e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { + math::Rect containerBox = container->getChildrenBoundingBox(); + offset.x = containerBox.getRight(); + e.consume(this); + } + } +} + } // namespace ui } // namespace rack