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.

175 lines
5.8KB

  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. Container that handles geometry for grid layouts (fixed columns and rows) using a set of declarative rules.
  21. Implemented from the `CSS Grid Layout` specification as described at:
  22. https://css-tricks.com/snippets/css/complete-guide-grid/
  23. @see GridItem
  24. */
  25. class JUCE_API Grid
  26. {
  27. public:
  28. //==============================================================================
  29. /** A size in pixels */
  30. struct Px
  31. {
  32. explicit Px (float p) : pixels (static_cast<long double>(p)) { /*sta (p >= 0.0f);*/ }
  33. explicit Px (int p) : pixels (static_cast<long double>(p)) { /*sta (p >= 0.0f);*/ }
  34. explicit constexpr Px (long double p) : pixels (p) {}
  35. explicit constexpr Px (unsigned long long p) : pixels (static_cast<long double>(p)) {}
  36. long double pixels;
  37. };
  38. /** A fractional ratio integer */
  39. struct Fr
  40. {
  41. explicit Fr (int f) : fraction (static_cast<unsigned long long> (f)) {}
  42. explicit constexpr Fr (unsigned long long p) : fraction (p) {}
  43. unsigned long long fraction;
  44. };
  45. //==============================================================================
  46. /** */
  47. struct TrackInfo
  48. {
  49. /** Creates a track with auto dimension. */
  50. TrackInfo() noexcept;
  51. /** */
  52. TrackInfo (Px sizeInPixels) noexcept;
  53. /** */
  54. TrackInfo (Fr fractionOfFreeSpace) noexcept;
  55. /** */
  56. TrackInfo (Px sizeInPixels, const juce::String& endLineNameToUse) noexcept;
  57. /** */
  58. TrackInfo (Fr fractionOfFreeSpace, const juce::String& endLineNameToUse) noexcept;
  59. /** */
  60. TrackInfo (const juce::String& startLineNameToUse, Px sizeInPixels) noexcept;
  61. /** */
  62. TrackInfo (const juce::String& startLineNameToUse, Fr fractionOfFreeSpace) noexcept;
  63. /** */
  64. TrackInfo (const juce::String& startLineNameToUse, Px sizeInPixels, const juce::String& endLineNameToUse) noexcept;
  65. /** */
  66. TrackInfo (const juce::String& startLineNameToUse, Fr fractionOfFreeSpace, const juce::String& endLineNameToUse) noexcept;
  67. private:
  68. friend class Grid;
  69. friend class GridItem;
  70. float size = 0; // Either a fraction or an absolute size in pixels
  71. bool isFraction = false;
  72. bool hasKeyword = false;
  73. juce::String startLineName, endLineName;
  74. };
  75. //==============================================================================
  76. /** */
  77. enum class JustifyItems : int { start = 0, end, center, stretch };
  78. /** */
  79. enum class AlignItems : int { start = 0, end, center, stretch };
  80. /** */
  81. enum class JustifyContent { start, end, center, stretch, spaceAround, spaceBetween, spaceEvenly };
  82. /** */
  83. enum class AlignContent { start, end, center, stretch, spaceAround, spaceBetween, spaceEvenly };
  84. /** */
  85. enum class AutoFlow { row, column, rowDense, columnDense };
  86. //==============================================================================
  87. /** */
  88. Grid() noexcept;
  89. /** Destructor */
  90. ~Grid() noexcept;
  91. //==============================================================================
  92. /** */
  93. JustifyItems justifyItems = JustifyItems::stretch;
  94. /** */
  95. AlignItems alignItems = AlignItems::stretch;
  96. /** */
  97. JustifyContent justifyContent = JustifyContent::stretch;
  98. /** */
  99. AlignContent alignContent = AlignContent::stretch;
  100. /** */
  101. AutoFlow autoFlow = AutoFlow::row;
  102. //==============================================================================
  103. /** */
  104. juce::Array<TrackInfo> templateColumns;
  105. /** */
  106. juce::Array<TrackInfo> templateRows;
  107. /** Template areas */
  108. juce::StringArray templateAreas;
  109. /** */
  110. TrackInfo autoRows;
  111. /** */
  112. TrackInfo autoColumns;
  113. /** */
  114. Px columnGap { 0 };
  115. /** */
  116. Px rowGap { 0 };
  117. /** */
  118. void setGap (Px sizeInPixels) noexcept { rowGap = columnGap = sizeInPixels; }
  119. //==============================================================================
  120. /** */
  121. juce::Array<GridItem> items;
  122. //==============================================================================
  123. /** */
  124. void performLayout (juce::Rectangle<int>);
  125. //==============================================================================
  126. /** */
  127. int getNumberOfColumns() const noexcept { return templateColumns.size(); }
  128. /** */
  129. int getNumberOfRows() const noexcept { return templateRows.size(); }
  130. private:
  131. //==============================================================================
  132. struct SizeCalculation;
  133. struct PlacementHelpers;
  134. struct AutoPlacement;
  135. struct BoxAlignment;
  136. };