You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpaqueWidget.hpp 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <widget/Widget.hpp>
  3. namespace rack {
  4. namespace widget {
  5. /** A Widget that stops propagation of all recursive PositionEvents but gives a chance for children to consume first.
  6. Also consumes Hover and Button for left-clicks.
  7. */
  8. struct OpaqueWidget : Widget {
  9. void onHover(const HoverEvent& e) override {
  10. Widget::onHover(e);
  11. e.stopPropagating();
  12. // Consume if not consumed by child
  13. if (!e.isConsumed())
  14. e.consume(this);
  15. }
  16. void onButton(const ButtonEvent& e) override {
  17. Widget::onButton(e);
  18. e.stopPropagating();
  19. if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
  20. // Consume if not consumed by child
  21. if (!e.isConsumed())
  22. e.consume(this);
  23. }
  24. }
  25. void onHoverKey(const HoverKeyEvent& e) override {
  26. Widget::onHoverKey(e);
  27. e.stopPropagating();
  28. }
  29. void onHoverText(const HoverTextEvent& e) override {
  30. Widget::onHoverText(e);
  31. e.stopPropagating();
  32. }
  33. void onHoverScroll(const HoverScrollEvent& e) override {
  34. Widget::onHoverScroll(e);
  35. e.stopPropagating();
  36. }
  37. void onDragHover(const DragHoverEvent& e) override {
  38. Widget::onDragHover(e);
  39. e.stopPropagating();
  40. // Consume if not consumed by child
  41. if (!e.isConsumed())
  42. e.consume(this);
  43. }
  44. void onPathDrop(const PathDropEvent& e) override {
  45. Widget::onPathDrop(e);
  46. e.stopPropagating();
  47. }
  48. };
  49. } // namespace widget
  50. } // namespace rack