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.

237 lines
8.4KB

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