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.

40 lines
1010B

  1. #include "ui.hpp"
  2. namespace rack {
  3. void SequentialLayout::step() {
  4. Widget::step();
  5. float offset = 0.0;
  6. for (Widget *child : children) {
  7. if (!child->visible)
  8. continue;
  9. // Set position
  10. (orientation == HORIZONTAL_ORIENTATION ? child->box.pos.x : child->box.pos.y) = offset;
  11. // Increment by size
  12. offset += (orientation == HORIZONTAL_ORIENTATION ? child->box.size.x : child->box.size.y);
  13. offset += spacing;
  14. }
  15. // We're done if left aligned
  16. if (alignment == LEFT_ALIGNMENT)
  17. return;
  18. // Adjust positions based on width of the layout itself
  19. offset -= spacing;
  20. if (alignment == RIGHT_ALIGNMENT)
  21. offset -= (orientation == HORIZONTAL_ORIENTATION ? box.size.x : box.size.y);
  22. else if (alignment == CENTER_ALIGNMENT)
  23. offset -= (orientation == HORIZONTAL_ORIENTATION ? box.size.x : box.size.y) / 2.0;
  24. for (Widget *child : children) {
  25. if (!child->visible)
  26. continue;
  27. (orientation == HORIZONTAL_ORIENTATION ? child->box.pos.x : child->box.pos.y) += offset;
  28. }
  29. }
  30. } // namespace rack