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.

57 lines
1.3KB

  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 event::Hover& 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 event::Button& 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 event::HoverKey& e) override {
  26. Widget::onHoverKey(e);
  27. e.stopPropagating();
  28. }
  29. void onHoverText(const event::HoverText& e) override {
  30. Widget::onHoverText(e);
  31. e.stopPropagating();
  32. }
  33. void onHoverScroll(const event::HoverScroll& e) override {
  34. Widget::onHoverScroll(e);
  35. e.stopPropagating();
  36. }
  37. void onDragHover(const event::DragHover& 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 event::PathDrop& e) override {
  45. Widget::onPathDrop(e);
  46. e.stopPropagating();
  47. }
  48. };
  49. } // namespace widget
  50. } // namespace rack