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_FlexItem.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. Describes the properties of an item inside a FlexBox container.
  22. @see FlexBox
  23. @tags{GUI}
  24. */
  25. class JUCE_API FlexItem final
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates an item with default parameters, and zero size. */
  30. FlexItem() noexcept;
  31. /** Creates an item with the given size. */
  32. FlexItem (float width, float height) noexcept;
  33. /** Creates an item with the given size and target Component. */
  34. FlexItem (float width, float height, Component& targetComponent) noexcept;
  35. /** Creates an item that represents an embedded FlexBox with a given size. */
  36. FlexItem (float width, float height, FlexBox& flexBoxToControl) noexcept;
  37. /** Creates an item with a given target Component. */
  38. FlexItem (Component& componentToControl) noexcept;
  39. /** Creates an item that represents an embedded FlexBox. This class will not
  40. create a copy of the supplied flex box. You need to ensure that the
  41. life-time of flexBoxToControl is longer than the FlexItem. */
  42. FlexItem (FlexBox& flexBoxToControl) noexcept;
  43. //==============================================================================
  44. /** The item's current bounds. */
  45. Rectangle<float> currentBounds;
  46. /** If this is non-null, it represents a Component whose bounds are controlled by this item. */
  47. Component* associatedComponent = nullptr;
  48. /** If this is non-null, it represents a FlexBox whose bounds are controlled by this item. */
  49. FlexBox* associatedFlexBox = nullptr;
  50. /** Determines the order used to lay out items in their flex container.
  51. Elements are laid out in ascending order of thus order value. Elements with the same order value
  52. are laid out in the order in which they appear in the array.
  53. */
  54. int order = 0;
  55. /** Specifies the flex grow factor of this item.
  56. This indicates the amount of space inside the flex container the item should take up.
  57. */
  58. float flexGrow = 0.0f;
  59. /** Specifies the flex shrink factor of the item.
  60. This indicates the rate at which the item shrinks if there is insufficient space in
  61. the container.
  62. */
  63. float flexShrink = 1.0f;
  64. /** Specifies the flex-basis of the item.
  65. This is the initial main size of a flex item in the direction of flow. It determines the size
  66. of the content-box unless specified otherwise using box-sizing.
  67. */
  68. float flexBasis = 0.0f;
  69. /** Possible value for the alignSelf property */
  70. enum class AlignSelf
  71. {
  72. autoAlign, /**< Follows the FlexBox container's alignItems property. */
  73. flexStart, /**< Item is aligned towards the start of the cross axis. */
  74. flexEnd, /**< Item is aligned towards the end of the cross axis. */
  75. center, /**< Item is aligned towards the center of the cross axis. */
  76. stretch /**< Item is stretched from start to end of the cross axis. */
  77. };
  78. /** This is the align-self property of the item.
  79. This determines the alignment of the item along the cross-axis (perpendicular to the direction
  80. of flow).
  81. */
  82. AlignSelf alignSelf = AlignSelf::autoAlign;
  83. //==============================================================================
  84. /** This constant can be used for sizes to indicate that 'auto' mode should be used. */
  85. static const int autoValue = -2;
  86. /** This constant can be used for sizes to indicate that no value has been set. */
  87. static const int notAssigned = -1;
  88. float width = (float) notAssigned; /**< The item's width. */
  89. float minWidth = 0.0f; /**< The item's minimum width */
  90. float maxWidth = (float) notAssigned; /**< The item's maximum width */
  91. float height = (float) notAssigned; /**< The item's height */
  92. float minHeight = 0.0f; /**< The item's minimum height */
  93. float maxHeight = (float) notAssigned; /**< The item's maximum height */
  94. /** Represents a margin. */
  95. struct Margin final
  96. {
  97. Margin() noexcept; /**< Creates a margin of size zero. */
  98. Margin (float size) noexcept; /**< Creates a margin with this size on all sides. */
  99. Margin (float top, float right, float bottom, float left) noexcept; /**< Creates a margin with these sizes. */
  100. float left; /**< Left margin size */
  101. float right; /**< Right margin size */
  102. float top; /**< Top margin size */
  103. float bottom; /**< Bottom margin size */
  104. };
  105. /** The margin to leave around this item. */
  106. Margin margin;
  107. //==============================================================================
  108. /** Returns a copy of this object with a new flex-grow value. */
  109. FlexItem withFlex (float newFlexGrow) const noexcept;
  110. /** Returns a copy of this object with new flex-grow and flex-shrink values. */
  111. FlexItem withFlex (float newFlexGrow, float newFlexShrink) const noexcept;
  112. /** Returns a copy of this object with new flex-grow, flex-shrink and flex-basis values. */
  113. FlexItem withFlex (float newFlexGrow, float newFlexShrink, float newFlexBasis) const noexcept;
  114. /** Returns a copy of this object with a new width. */
  115. FlexItem withWidth (float newWidth) const noexcept;
  116. /** Returns a copy of this object with a new minimum width. */
  117. FlexItem withMinWidth (float newMinWidth) const noexcept;
  118. /** Returns a copy of this object with a new maximum width. */
  119. FlexItem withMaxWidth (float newMaxWidth) const noexcept;
  120. /** Returns a copy of this object with a new height. */
  121. FlexItem withHeight (float newHeight) const noexcept;
  122. /** Returns a copy of this object with a new minimum height. */
  123. FlexItem withMinHeight (float newMinHeight) const noexcept;
  124. /** Returns a copy of this object with a new maximum height. */
  125. FlexItem withMaxHeight (float newMaxHeight) const noexcept;
  126. /** Returns a copy of this object with a new margin. */
  127. FlexItem withMargin (Margin) const noexcept;
  128. /** Returns a copy of this object with a new order. */
  129. FlexItem withOrder (int newOrder) const noexcept;
  130. /** Returns a copy of this object with a new alignSelf value. */
  131. FlexItem withAlignSelf (AlignSelf newAlignSelf) const noexcept;
  132. };
  133. } // namespace juce