Audio plugin host https://kx.studio/carla
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.

juce_FlexBox.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /**
  21. Represents a FlexBox container, which contains and manages the layout of a set
  22. of FlexItem objects.
  23. To use this class, set its parameters appropriately (you can search online for
  24. more help on exactly how the FlexBox protocol works!), then add your sub-items
  25. to the items array, and call performLayout() in the resized() function of your
  26. Component.
  27. @see FlexItem
  28. @tags{GUI}
  29. */
  30. class JUCE_API FlexBox final
  31. {
  32. public:
  33. /** Possible values for the flexDirection property. */
  34. enum class Direction
  35. {
  36. row, /**< Set the main axis direction from left to right. */
  37. rowReverse, /**< Set the main axis direction from right to left. */
  38. column, /**< Set the main axis direction from top to bottom. */
  39. columnReverse /**< Set the main axis direction from bottom to top. */
  40. };
  41. /** Possible values for the flexWrap property. */
  42. enum class Wrap
  43. {
  44. noWrap, /**< Items are forced into a single line. */
  45. wrap, /**< Items are wrapped onto multiple lines from top to bottom. */
  46. wrapReverse /**< Items are wrapped onto multiple lines from bottom to top. */
  47. };
  48. /** Possible values for the alignContent property. */
  49. enum class AlignContent
  50. {
  51. stretch, /**< Lines of items are stretched from start to end of the cross axis. */
  52. flexStart, /**< Lines of items are aligned towards the start of the cross axis. */
  53. flexEnd, /**< Lines of items are aligned towards the end of the cross axis. */
  54. center, /**< Lines of items are aligned towards the center of the cross axis. */
  55. spaceBetween, /**< Lines of items are evenly spaced along the cross axis with spaces between them. */
  56. spaceAround /**< Lines of items are evenly spaced along the cross axis with spaces around them. */
  57. };
  58. /** Possible values for the alignItems property. */
  59. enum class AlignItems
  60. {
  61. stretch, /**< Items are stretched from start to end of the cross axis. */
  62. flexStart, /**< Items are aligned towards the start of the cross axis. */
  63. flexEnd, /**< Items are aligned towards the end of the cross axis. */
  64. center /**< Items are aligned towards the center of the cross axis. */
  65. };
  66. /** Possible values for the justifyContent property. */
  67. enum class JustifyContent
  68. {
  69. flexStart, /**< Items are justified towards the start of the main axis. */
  70. flexEnd, /**< Items are justified towards the end of the main axis. */
  71. center, /**< Items are justified towards the center of the main axis. */
  72. spaceBetween, /**< Items are evenly spaced along the main axis with spaces between them. */
  73. spaceAround /**< Items are evenly spaced along the main axis with spaces around them. */
  74. };
  75. //==============================================================================
  76. /** Creates an empty FlexBox container with default parameters. */
  77. FlexBox() noexcept = default;
  78. /** Creates an empty FlexBox container with these parameters. */
  79. FlexBox (Direction, Wrap, AlignContent, AlignItems, JustifyContent) noexcept;
  80. /** Creates an empty FlexBox container with the given content-justification mode. */
  81. FlexBox (JustifyContent) noexcept;
  82. //==============================================================================
  83. /** Lays-out the box's items within the given rectangle. */
  84. void performLayout (Rectangle<float> targetArea);
  85. /** Lays-out the box's items within the given rectangle. */
  86. void performLayout (Rectangle<int> targetArea);
  87. //==============================================================================
  88. /** Specifies how flex items are placed in the flex container, and defines the
  89. direction of the main axis.
  90. */
  91. Direction flexDirection = Direction::row;
  92. /** Specifies whether items are forced into a single line or can be wrapped onto multiple lines.
  93. If wrapping is allowed, this property also controls the direction in which lines are stacked.
  94. */
  95. Wrap flexWrap = Wrap::noWrap;
  96. /** Specifies how a flex container's lines are placed within the flex container when
  97. there is extra space on the cross-axis.
  98. This property has no effect on single line layouts.
  99. */
  100. AlignContent alignContent = AlignContent::stretch;
  101. /** Specifies the alignment of flex items along the cross-axis of each line. */
  102. AlignItems alignItems = AlignItems::stretch;
  103. /** Defines how the container distributes space between and around items along the main-axis.
  104. The alignment is done after the lengths and auto margins are applied, so that if there is at
  105. least one flexible element, with flex-grow different from 0, it will have no effect as there
  106. won't be any available space.
  107. */
  108. JustifyContent justifyContent = JustifyContent::flexStart;
  109. /** The set of items to lay-out. */
  110. Array<FlexItem> items;
  111. private:
  112. JUCE_LEAK_DETECTOR (FlexBox)
  113. };
  114. } // namespace juce