juce_GridItem.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. GridItem::Property::Property() noexcept : isAuto (true)
  22. {
  23. }
  24. GridItem::Property::Property (GridItem::Keyword keyword) noexcept : isAuto (keyword == GridItem::Keyword::autoValue)
  25. {
  26. jassert (keyword == GridItem::Keyword::autoValue);
  27. }
  28. GridItem::Property::Property (const char* lineNameToUse) noexcept : GridItem::Property (String (lineNameToUse))
  29. {
  30. }
  31. GridItem::Property::Property (const String& lineNameToUse) noexcept : name (lineNameToUse), number (1)
  32. {
  33. }
  34. GridItem::Property::Property (int numberToUse) noexcept : number (numberToUse)
  35. {
  36. }
  37. GridItem::Property::Property (int numberToUse, const String& lineNameToUse) noexcept
  38. : name (lineNameToUse), number (numberToUse)
  39. {
  40. }
  41. GridItem::Property::Property (Span spanToUse) noexcept
  42. : name (spanToUse.name), number (spanToUse.number), isSpan (true)
  43. {
  44. }
  45. //==============================================================================
  46. GridItem::Margin::Margin() noexcept : left(), right(), top(), bottom() {}
  47. GridItem::Margin::Margin (int v) noexcept : GridItem::Margin::Margin (static_cast<float> (v)) {}
  48. GridItem::Margin::Margin (float v) noexcept : left (v), right (v), top (v), bottom (v) {}
  49. GridItem::Margin::Margin (float t, float r, float b, float l) noexcept : left (l), right (r), top (t), bottom (b) {}
  50. //==============================================================================
  51. GridItem::GridItem() noexcept {}
  52. GridItem::~GridItem() noexcept {}
  53. GridItem::GridItem (Component& componentToUse) noexcept : associatedComponent (&componentToUse) {}
  54. GridItem::GridItem (Component* componentToUse) noexcept : associatedComponent (componentToUse) {}
  55. void GridItem::setArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd)
  56. {
  57. column.start = columnStart;
  58. column.end = columnEnd;
  59. row.start = rowStart;
  60. row.end = rowEnd;
  61. }
  62. void GridItem::setArea (Property rowStart, Property columnStart)
  63. {
  64. column.start = columnStart;
  65. row.start = rowStart;
  66. }
  67. void GridItem::setArea (const String& areaName)
  68. {
  69. area = areaName;
  70. }
  71. GridItem GridItem::withArea (Property rowStart, Property columnStart, Property rowEnd, Property columnEnd) const noexcept
  72. {
  73. auto gi = *this;
  74. gi.setArea (rowStart, columnStart, rowEnd, columnEnd);
  75. return gi;
  76. }
  77. GridItem GridItem::withArea (Property rowStart, Property columnStart) const noexcept
  78. {
  79. auto gi = *this;
  80. gi.setArea (rowStart, columnStart);
  81. return gi;
  82. }
  83. GridItem GridItem::withArea (const String& areaName) const noexcept
  84. {
  85. auto gi = *this;
  86. gi.setArea (areaName);
  87. return gi;
  88. }
  89. GridItem GridItem::withRow (StartAndEndProperty newRow) const noexcept
  90. {
  91. auto gi = *this;
  92. gi.row = newRow;
  93. return gi;
  94. }
  95. GridItem GridItem::withColumn (StartAndEndProperty newColumn) const noexcept
  96. {
  97. auto gi = *this;
  98. gi.column = newColumn;
  99. return gi;
  100. }
  101. GridItem GridItem::withAlignSelf (AlignSelf newAlignSelf) const noexcept
  102. {
  103. auto gi = *this;
  104. gi.alignSelf = newAlignSelf;
  105. return gi;
  106. }
  107. GridItem GridItem::withJustifySelf (JustifySelf newJustifySelf) const noexcept
  108. {
  109. auto gi = *this;
  110. gi.justifySelf = newJustifySelf;
  111. return gi;
  112. }
  113. GridItem GridItem::withWidth (float newWidth) const noexcept
  114. {
  115. auto gi = *this;
  116. gi.width = newWidth;
  117. return gi;
  118. }
  119. GridItem GridItem::withHeight (float newHeight) const noexcept
  120. {
  121. auto gi = *this;
  122. gi.height = newHeight;
  123. return gi;
  124. }
  125. GridItem GridItem::withSize (float newWidth, float newHeight) const noexcept
  126. {
  127. auto gi = *this;
  128. gi.width = newWidth;
  129. gi.height = newHeight;
  130. return gi;
  131. }
  132. GridItem GridItem::withMargin (Margin newHeight) const noexcept
  133. {
  134. auto gi = *this;
  135. gi.margin = newHeight;
  136. return gi;
  137. }
  138. GridItem GridItem::withOrder (int newOrder) const noexcept
  139. {
  140. auto gi = *this;
  141. gi.order = newOrder;
  142. return gi;
  143. }
  144. } // namespace juce