The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

224 lines
6.5KB

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