DISTRHO Plugin Framework
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.

100 lines
3.4KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "../Layout.hpp"
  17. #include "../SubWidget.hpp"
  18. START_NAMESPACE_DGL
  19. typedef std::list<SubWidgetWithSizeHint>::iterator SubWidgetWithSizeHintIterator;
  20. typedef std::list<HorizontalLayout*>::iterator HorizontalLayoutIterator;
  21. // --------------------------------------------------------------------------------------------------------------------
  22. template<> // horizontal
  23. uint Layout<true>::setAbsolutePos(int x, const int y, const uint padding)
  24. {
  25. uint maxHeight = 0;
  26. for (SubWidgetWithSizeHintIterator it=widgets.begin(), end=widgets.end(); it != end; ++it)
  27. {
  28. SubWidgetWithSizeHint& s(*it);
  29. maxHeight = std::max(maxHeight, s.widget->getHeight());
  30. s.widget->setAbsolutePos(x, y);
  31. x += s.widget->getWidth();
  32. x += padding;
  33. }
  34. return maxHeight;
  35. }
  36. template<> // horizontal
  37. void Layout<true>::setSize(const uint width, const uint padding)
  38. {
  39. uint maxHeight = 0;
  40. uint nonFixedWidth = width;
  41. uint numDynamiclySizedWidgets = 0;
  42. for (SubWidgetWithSizeHintIterator it=widgets.begin(), end=widgets.end(); it != end; ++it)
  43. {
  44. SubWidgetWithSizeHint& s(*it);
  45. maxHeight = std::max(maxHeight, s.widget->getHeight());
  46. if (s.sizeHint == Fixed)
  47. nonFixedWidth -= s.widget->getWidth();
  48. else
  49. ++numDynamiclySizedWidgets;
  50. }
  51. const uint widthPerWidget = numDynamiclySizedWidgets != 0
  52. ? (nonFixedWidth - padding * numDynamiclySizedWidgets) / numDynamiclySizedWidgets
  53. : 0;
  54. for (SubWidgetWithSizeHintIterator it=widgets.begin(), end=widgets.end(); it != end; ++it)
  55. {
  56. SubWidgetWithSizeHint& s(*it);
  57. if (s.sizeHint != Fixed)
  58. s.widget->setSize(widthPerWidget, maxHeight);
  59. else
  60. s.widget->setHeight(maxHeight);
  61. }
  62. }
  63. // --------------------------------------------------------------------------------------------------------------------
  64. void VerticallyStackedHorizontalLayout::setAbsolutePos(const int x, int y, const uint padding)
  65. {
  66. for (HorizontalLayoutIterator it=items.begin(), end=items.end(); it != end; ++it)
  67. {
  68. HorizontalLayout* l(*it);
  69. y += l->setAbsolutePos(x, y, padding);
  70. y += padding;
  71. }
  72. }
  73. void VerticallyStackedHorizontalLayout::setWidth(const uint width, const uint padding)
  74. {
  75. for (HorizontalLayoutIterator it=items.begin(), end=items.end(); it != end; ++it)
  76. {
  77. HorizontalLayout* l(*it);
  78. l->setSize(width, padding);
  79. }
  80. }
  81. // --------------------------------------------------------------------------------------------------------------------
  82. END_NAMESPACE_DGL