Browse Source

Add page up/down, home, and end key commands to ScrollWidget.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
3073bef995
2 changed files with 46 additions and 0 deletions
  1. +1
    -0
      include/ui/ScrollWidget.hpp
  2. +45
    -0
      src/ui/ScrollWidget.cpp

+ 1
- 0
include/ui/ScrollWidget.hpp View File

@@ -23,6 +23,7 @@ struct ScrollWidget : widget::OpaqueWidget {
void onDragStart(const event::DragStart& e) override; void onDragStart(const event::DragStart& e) override;
void onDragMove(const event::DragMove& e) override; void onDragMove(const event::DragMove& e) override;
void onHoverScroll(const event::HoverScroll& e) override; void onHoverScroll(const event::HoverScroll& e) override;
void onHoverKey(const event::HoverKey& e) override;
}; };






+ 45
- 0
src/ui/ScrollWidget.cpp View File

@@ -112,6 +112,51 @@ void ScrollWidget::onHoverScroll(const event::HoverScroll& e) {
e.consume(this); 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 ui
} // namespace rack } // namespace rack

Loading…
Cancel
Save