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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. /**
  22. Defines an item in a Grid
  23. @see Grid
  24. */
  25. class JUCE_API GridItem
  26. {
  27. public:
  28. enum class Keyword { autoValue };
  29. //==============================================================================
  30. /** */
  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 juce::String& nameToUse) : Span (numberToUse)
  39. {
  40. /* Name must not be empty */
  41. jassert (nameToUse.isNotEmpty());
  42. name = nameToUse;
  43. }
  44. explicit Span (const juce::String& nameToUse) : name (nameToUse)
  45. {
  46. /* Name must not be empty */
  47. jassert (nameToUse.isNotEmpty());
  48. }
  49. int number = 1;
  50. juce::String name;
  51. };
  52. //==============================================================================
  53. /** */
  54. struct Property
  55. {
  56. /** */
  57. Property() noexcept;
  58. /** */
  59. Property (Keyword keyword) noexcept;
  60. /** */
  61. Property (const char* lineNameToUse) noexcept;
  62. /** */
  63. Property (const juce::String& lineNameToUse) noexcept;
  64. /** */
  65. Property (int numberToUse) noexcept;
  66. /** */
  67. Property (int numberToUse, const juce::String& lineNameToUse) noexcept;
  68. /** */
  69. Property (Span spanToUse) noexcept;
  70. private:
  71. bool hasSpan() const noexcept { return isSpan && ! isAuto; }
  72. bool hasAbsolute() const noexcept { return ! (isSpan || isAuto); }
  73. bool hasAuto() const noexcept { return isAuto; }
  74. bool hasName() const noexcept { return name.isNotEmpty(); }
  75. friend class Grid;
  76. juce::String name;
  77. int number = 1; /** Either an absolute line number or number of lines to span across. */
  78. bool isSpan = false;
  79. bool isAuto = false;
  80. };
  81. //==============================================================================
  82. /** */
  83. struct StartAndEndProperty { Property start, end; };
  84. //==============================================================================
  85. /** */
  86. enum class JustifySelf : int { start = 0, end, center, stretch, autoValue };
  87. /** */
  88. enum class AlignSelf : int { start = 0, end, center, stretch, autoValue };
  89. /** */
  90. GridItem() noexcept;
  91. /** */
  92. GridItem (juce::Component& componentToUse) noexcept;
  93. /** */
  94. GridItem (juce::Component* componentToUse) noexcept;
  95. /** Destructor. */
  96. ~GridItem() noexcept;
  97. //==============================================================================
  98. /** */
  99. juce::Component* associatedComponent = nullptr;
  100. //==============================================================================
  101. /** */
  102. int order = 0;
  103. /** */
  104. JustifySelf justifySelf = JustifySelf::autoValue;
  105. /** */
  106. AlignSelf alignSelf = AlignSelf::autoValue;
  107. /** */
  108. StartAndEndProperty column = { Keyword::autoValue, Keyword::autoValue };
  109. /** */
  110. StartAndEndProperty row = { Keyword::autoValue, Keyword::autoValue };
  111. /** */
  112. juce::String area;
  113. //==============================================================================
  114. enum
  115. {
  116. useDefaultValue = -2, /* TODO: useDefaultValue should be named useAuto */
  117. notAssigned = -1
  118. };
  119. /* TODO: move all of this into a common class that is shared with the FlexItem */
  120. float width = notAssigned;
  121. float minWidth = 0;
  122. float maxWidth = notAssigned;
  123. float height = notAssigned;
  124. float minHeight = 0;
  125. float maxHeight = notAssigned;
  126. struct Margin
  127. {
  128. Margin() noexcept;
  129. Margin (int size) noexcept;
  130. Margin (float size) noexcept;
  131. Margin (float top, float right, float bottom, float left) noexcept; /**< Creates a margin with these sizes. */
  132. float left;
  133. float right;
  134. float top;
  135. float bottom;
  136. };
  137. /** */
  138. Margin margin;
  139. /** */
  140. juce::Rectangle<float> currentBounds;
  141. /** Short-hand */
  142. void setArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd);
  143. /** Short-hand, span of 1 by default */
  144. void setArea (Property rowStart, Property columnStart);
  145. /** Short-hand */
  146. void setArea (const juce::String& areaName);
  147. /** Short-hand */
  148. GridItem withArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd) const noexcept;
  149. /** Short-hand, span of 1 by default */
  150. GridItem withArea (Property rowStart, Property columnStart) const noexcept;
  151. /** Short-hand */
  152. GridItem withArea (const juce::String& areaName) const noexcept;
  153. /** */
  154. GridItem withRow (StartAndEndProperty row) const noexcept;
  155. /** */
  156. GridItem withColumn (StartAndEndProperty column) const noexcept;
  157. /** */
  158. GridItem withAlignSelf (AlignSelf newAlignSelf) const noexcept;
  159. /** */
  160. GridItem withJustifySelf (JustifySelf newJustifySelf) const noexcept;
  161. /** */
  162. GridItem withWidth (float newWidth) const noexcept;
  163. /** */
  164. GridItem withHeight (float newHeight) const noexcept;
  165. /** */
  166. GridItem withSize (float newWidth, float newHeight) const noexcept;
  167. /** */
  168. GridItem withMargin (Margin newMargin) const noexcept;
  169. /** Returns a copy of this object with a new order. */
  170. GridItem withOrder (int newOrder) const noexcept;
  171. };
  172. } // namespace juce