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.

51 lines
1.3KB

  1. #pragma once
  2. #include <ui/common.hpp>
  3. #include <widget/OpaqueWidget.hpp>
  4. #include <ui/Scrollbar.hpp>
  5. namespace rack {
  6. namespace ui {
  7. /** Handles a container with Scrollbar */
  8. struct ScrollWidget : widget::OpaqueWidget {
  9. struct Internal;
  10. Internal* internal;
  11. widget::Widget* container;
  12. Scrollbar* horizontalScrollbar;
  13. Scrollbar* verticalScrollbar;
  14. math::Vec offset;
  15. math::Rect containerBox;
  16. bool hideScrollbars = false;
  17. ScrollWidget();
  18. ~ScrollWidget();
  19. math::Vec getScrollOffset() {
  20. return offset;
  21. }
  22. void scrollTo(math::Rect r);
  23. /** Returns the bound of allowed `offset` values in pixels. */
  24. math::Rect getContainerOffsetBound();
  25. /** Returns the handle position relative to the scrollbar. [0, 1]. */
  26. math::Vec getHandleOffset();
  27. /** Returns the handle size relative to the scrollbar. [0, 1]. */
  28. math::Vec getHandleSize();
  29. /** The user is considered scrolling with the wheel until the mouse is moved. */
  30. bool isScrolling();
  31. void draw(const DrawArgs& args) override;
  32. void step() override;
  33. void onHover(const HoverEvent& e) override;
  34. void onButton(const ButtonEvent& e) override;
  35. void onDragStart(const DragStartEvent& e) override;
  36. void onDragMove(const DragMoveEvent& e) override;
  37. void onHoverScroll(const HoverScrollEvent& e) override;
  38. void onHoverKey(const HoverKeyEvent& e) override;
  39. };
  40. } // namespace ui
  41. } // namespace rack