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_GridItem.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. /** Destructor. */
  104. ~GridItem() noexcept;
  105. //==============================================================================
  106. /** If this is non-null, it represents a Component whose bounds are controlled by this item. */
  107. Component* associatedComponent = nullptr;
  108. //==============================================================================
  109. /** Determines the order used to lay out items in their grid container. */
  110. int order = 0;
  111. /** This is the justify-self property of the item.
  112. This determines the alignment of the item along the row.
  113. */
  114. JustifySelf justifySelf = JustifySelf::autoValue;
  115. /** This is the align-self property of the item.
  116. This determines the alignment of the item along the column.
  117. */
  118. AlignSelf alignSelf = AlignSelf::autoValue;
  119. /** These are the start and end properties of the column. */
  120. StartAndEndProperty column = { Keyword::autoValue, Keyword::autoValue };
  121. /** These are the start and end properties of the row. */
  122. StartAndEndProperty row = { Keyword::autoValue, Keyword::autoValue };
  123. /** */
  124. String area;
  125. //==============================================================================
  126. enum
  127. {
  128. useDefaultValue = -2, /* TODO: useDefaultValue should be named useAuto */
  129. notAssigned = -1
  130. };
  131. /* TODO: move all of this into a common class that is shared with the FlexItem */
  132. float width = notAssigned;
  133. float minWidth = 0.0f;
  134. float maxWidth = notAssigned;
  135. float height = notAssigned;
  136. float minHeight = 0.0f;
  137. float maxHeight = notAssigned;
  138. /** Represents a margin. */
  139. struct Margin
  140. {
  141. Margin() noexcept;
  142. Margin (int size) noexcept;
  143. Margin (float size) noexcept;
  144. Margin (float top, float right, float bottom, float left) noexcept; /**< Creates a margin with these sizes. */
  145. float left;
  146. float right;
  147. float top;
  148. float bottom;
  149. };
  150. /** The margin to leave around this item. */
  151. Margin margin;
  152. /** The item's current bounds. */
  153. Rectangle<float> currentBounds;
  154. /** Short-hand */
  155. void setArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd);
  156. /** Short-hand, span of 1 by default */
  157. void setArea (Property rowStart, Property columnStart);
  158. /** Short-hand */
  159. void setArea (const String& areaName);
  160. /** Short-hand */
  161. GridItem withArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd) const noexcept;
  162. /** Short-hand, span of 1 by default */
  163. GridItem withArea (Property rowStart, Property columnStart) const noexcept;
  164. /** Short-hand */
  165. GridItem withArea (const String& areaName) const noexcept;
  166. /** Returns a copy of this object with a new row property. */
  167. GridItem withRow (StartAndEndProperty row) const noexcept;
  168. /** Returns a copy of this object with a new column property. */
  169. GridItem withColumn (StartAndEndProperty column) const noexcept;
  170. /** Returns a copy of this object with a new alignSelf property. */
  171. GridItem withAlignSelf (AlignSelf newAlignSelf) const noexcept;
  172. /** Returns a copy of this object with a new justifySelf property. */
  173. GridItem withJustifySelf (JustifySelf newJustifySelf) const noexcept;
  174. /** Returns a copy of this object with a new width. */
  175. GridItem withWidth (float newWidth) const noexcept;
  176. /** Returns a copy of this object with a new height. */
  177. GridItem withHeight (float newHeight) const noexcept;
  178. /** Returns a copy of this object with a new size. */
  179. GridItem withSize (float newWidth, float newHeight) const noexcept;
  180. /** Returns a copy of this object with a new margin. */
  181. GridItem withMargin (Margin newMargin) const noexcept;
  182. /** Returns a copy of this object with a new order. */
  183. GridItem withOrder (int newOrder) const noexcept;
  184. };
  185. } // namespace juce