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.

241 lines
8.6KB

  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. Defines an item in a Grid
  22. @see Grid
  23. @tags{GUI}
  24. */
  25. class JUCE_API GridItem
  26. {
  27. public:
  28. enum class Keyword { autoValue };
  29. //==============================================================================
  30. /** Represents a span. */
  31. struct Span
  32. {
  33. explicit Span (int numberToUse) noexcept : number (numberToUse)
  34. {
  35. /* Span must be at least one and positive */
  36. jassert (numberToUse > 0);
  37. }
  38. explicit Span (int numberToUse, const String& nameToUse) : Span (numberToUse)
  39. {
  40. /* Name must not be empty */
  41. jassert (nameToUse.isNotEmpty());
  42. name = nameToUse;
  43. }
  44. explicit Span (const String& nameToUse) : name (nameToUse)
  45. {
  46. /* Name must not be empty */
  47. jassert (nameToUse.isNotEmpty());
  48. }
  49. int number = 1;
  50. String name;
  51. };
  52. //==============================================================================
  53. /** Represents a property. */
  54. struct Property
  55. {
  56. Property() noexcept;
  57. Property (Keyword keyword) noexcept;
  58. Property (const char* lineNameToUse) noexcept;
  59. Property (const String& lineNameToUse) noexcept;
  60. Property (int numberToUse) noexcept;
  61. Property (int numberToUse, const String& lineNameToUse) noexcept;
  62. Property (Span spanToUse) noexcept;
  63. bool hasSpan() const noexcept { return isSpan && ! isAuto; }
  64. bool hasAbsolute() const noexcept { return ! (isSpan || isAuto); }
  65. bool hasAuto() const noexcept { return isAuto; }
  66. bool hasName() const noexcept { return name.isNotEmpty(); }
  67. const String& getName() const noexcept { return name; }
  68. int getNumber() const noexcept { return number; }
  69. private:
  70. String name;
  71. int number = 1; /** Either an absolute line number or number of lines to span across. */
  72. bool isSpan = false;
  73. bool isAuto = false;
  74. };
  75. //==============================================================================
  76. /** Represents start and end properties. */
  77. struct StartAndEndProperty { Property start, end; };
  78. //==============================================================================
  79. /** Possible values for the justifySelf property. */
  80. enum class JustifySelf : int
  81. {
  82. start = 0, /**< Content inside the item is justified towards the left. */
  83. end, /**< Content inside the item is justified towards the right. */
  84. center, /**< Content inside the item is justified towards the center. */
  85. stretch, /**< Content inside the item is stretched from left to right. */
  86. autoValue /**< Follows the Grid container's justifyItems property. */
  87. };
  88. /** Possible values for the alignSelf property. */
  89. enum class AlignSelf : int
  90. {
  91. start = 0, /**< Content inside the item is aligned towards the top. */
  92. end, /**< Content inside the item is aligned towards the bottom. */
  93. center, /**< Content inside the item is aligned towards the center. */
  94. stretch, /**< Content inside the item is stretched from top to bottom. */
  95. autoValue /**< Follows the Grid container's alignItems property. */
  96. };
  97. /** Creates an item with default parameters. */
  98. GridItem() noexcept;
  99. /** Creates an item with a given Component to use. */
  100. GridItem (Component& componentToUse) noexcept;
  101. /** Creates an item with a given Component to use. */
  102. GridItem (Component* componentToUse) noexcept;
  103. //==============================================================================
  104. /** If this is non-null, it represents a Component whose bounds are controlled by this item. */
  105. Component* associatedComponent = nullptr;
  106. //==============================================================================
  107. /** Determines the order used to lay out items in their grid container. */
  108. int order = 0;
  109. /** This is the justify-self property of the item.
  110. This determines the alignment of the item along the row.
  111. */
  112. JustifySelf justifySelf = JustifySelf::autoValue;
  113. /** This is the align-self property of the item.
  114. This determines the alignment of the item along the column.
  115. */
  116. AlignSelf alignSelf = AlignSelf::autoValue;
  117. /** These are the start and end properties of the column. */
  118. StartAndEndProperty column = { Keyword::autoValue, Keyword::autoValue };
  119. /** These are the start and end properties of the row. */
  120. StartAndEndProperty row = { Keyword::autoValue, Keyword::autoValue };
  121. /** */
  122. String area;
  123. //==============================================================================
  124. enum
  125. {
  126. useDefaultValue = -2, /* TODO: useDefaultValue should be named useAuto */
  127. notAssigned = -1
  128. };
  129. /* TODO: move all of this into a common class that is shared with the FlexItem */
  130. float width = notAssigned;
  131. float minWidth = 0.0f;
  132. float maxWidth = notAssigned;
  133. float height = notAssigned;
  134. float minHeight = 0.0f;
  135. float maxHeight = notAssigned;
  136. /** Represents a margin. */
  137. struct Margin
  138. {
  139. Margin() noexcept;
  140. Margin (int size) noexcept;
  141. Margin (float size) noexcept;
  142. Margin (float top, float right, float bottom, float left) noexcept; /**< Creates a margin with these sizes. */
  143. float left;
  144. float right;
  145. float top;
  146. float bottom;
  147. };
  148. /** The margin to leave around this item. */
  149. Margin margin;
  150. /** The item's current bounds. */
  151. Rectangle<float> currentBounds;
  152. /** Short-hand */
  153. void setArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd);
  154. /** Short-hand, span of 1 by default */
  155. void setArea (Property rowStart, Property columnStart);
  156. /** Short-hand */
  157. void setArea (const String& areaName);
  158. /** Short-hand */
  159. GridItem withArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd) const noexcept;
  160. /** Short-hand, span of 1 by default */
  161. GridItem withArea (Property rowStart, Property columnStart) const noexcept;
  162. /** Short-hand */
  163. GridItem withArea (const String& areaName) const noexcept;
  164. /** Returns a copy of this object with a new row property. */
  165. GridItem withRow (StartAndEndProperty row) const noexcept;
  166. /** Returns a copy of this object with a new column property. */
  167. GridItem withColumn (StartAndEndProperty column) const noexcept;
  168. /** Returns a copy of this object with a new alignSelf property. */
  169. GridItem withAlignSelf (AlignSelf newAlignSelf) const noexcept;
  170. /** Returns a copy of this object with a new justifySelf property. */
  171. GridItem withJustifySelf (JustifySelf newJustifySelf) const noexcept;
  172. /** Returns a copy of this object with a new width. */
  173. GridItem withWidth (float newWidth) const noexcept;
  174. /** Returns a copy of this object with a new height. */
  175. GridItem withHeight (float newHeight) const noexcept;
  176. /** Returns a copy of this object with a new size. */
  177. GridItem withSize (float newWidth, float newHeight) const noexcept;
  178. /** Returns a copy of this object with a new margin. */
  179. GridItem withMargin (Margin newMargin) const noexcept;
  180. /** Returns a copy of this object with a new order. */
  181. GridItem withOrder (int newOrder) const noexcept;
  182. };
  183. } // namespace juce