JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Grid.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
39class JUCE_API Grid final
40{
41public:
42 //==============================================================================
44 struct Px final
45 {
46 explicit Px (float p) : pixels (static_cast<long double> (p)) { /*sta (p >= 0.0f);*/ }
47 explicit Px (int p) : pixels (static_cast<long double> (p)) { /*sta (p >= 0.0f);*/ }
48 explicit constexpr Px (long double p) : pixels (p) {}
49 explicit constexpr Px (unsigned long long p) : pixels (static_cast<long double> (p)) {}
50
51 long double pixels;
52 };
53
55 struct Fr final
56 {
57 explicit Fr (int f) : fraction (static_cast<unsigned long long> (f)) {}
58 explicit constexpr Fr (unsigned long long p) : fraction (p) {}
59
60 unsigned long long fraction;
61 };
62
63 //==============================================================================
65 struct TrackInfo final
66 {
68 TrackInfo() noexcept;
69
70 TrackInfo (Px sizeInPixels) noexcept;
71 TrackInfo (Fr fractionOfFreeSpace) noexcept;
72
73 TrackInfo (Px sizeInPixels, const String& endLineNameToUse) noexcept;
74 TrackInfo (Fr fractionOfFreeSpace, const String& endLineNameToUse) noexcept;
75
76 TrackInfo (const String& startLineNameToUse, Px sizeInPixels) noexcept;
77 TrackInfo (const String& startLineNameToUse, Fr fractionOfFreeSpace) noexcept;
78
79 TrackInfo (const String& startLineNameToUse, Px sizeInPixels, const String& endLineNameToUse) noexcept;
80 TrackInfo (const String& startLineNameToUse, Fr fractionOfFreeSpace, const String& endLineNameToUse) noexcept;
81
82 bool isAuto() const noexcept { return hasKeyword; }
83 bool isFractional() const noexcept { return isFraction; }
84 bool isPixels() const noexcept { return ! isFraction; }
85 const String& getStartLineName() const noexcept { return startLineName; }
86 const String& getEndLineName() const noexcept { return endLineName; }
87
89 float getSize() const noexcept { return size; }
90
91 private:
92 friend class Grid;
93 float getAbsoluteSize (float relativeFractionalUnit) const;
94
95 float size = 0; // Either a fraction or an absolute size in pixels
96 bool isFraction = false;
97 bool hasKeyword = false;
98
99 String startLineName, endLineName;
100 };
101
102 //==============================================================================
104 enum class JustifyItems : int
105 {
106 start = 0,
107 end,
108 center,
109 stretch
110 };
111
113 enum class AlignItems : int
114 {
115 start = 0,
116 end,
117 center,
118 stretch
119 };
120
122 enum class JustifyContent
123 {
124 start,
125 end,
126 center,
127 stretch,
128 spaceAround,
129 spaceBetween,
130 spaceEvenly
131 };
132
134 enum class AlignContent
135 {
136 start,
137 end,
138 center,
139 stretch,
140 spaceAround,
141 spaceBetween,
142 spaceEvenly
143 };
144
146 enum class AutoFlow
147 {
148 row,
149 column,
150 rowDense,
151 columnDense
152 };
153
154
155 //==============================================================================
157 Grid() = default;
158
159 //==============================================================================
161 JustifyItems justifyItems = JustifyItems::stretch;
162
164 AlignItems alignItems = AlignItems::stretch;
165
167 JustifyContent justifyContent = JustifyContent::stretch;
168
170 AlignContent alignContent = AlignContent::stretch;
171
173 AutoFlow autoFlow = AutoFlow::row;
174
175
176 //==============================================================================
179
182
185
188
191
193 Px columnGap { 0 };
195 Px rowGap { 0 };
196
198 void setGap (Px sizeInPixels) noexcept { rowGap = columnGap = sizeInPixels; }
199
200 //==============================================================================
203
204 //==============================================================================
206 void performLayout (Rectangle<int>);
207
208 //==============================================================================
210 int getNumberOfColumns() const noexcept { return templateColumns.size(); }
212 int getNumberOfRows() const noexcept { return templateRows.size(); }
213
214private:
215 //==============================================================================
216 struct Helpers;
217};
218
219constexpr Grid::Px operator""_px (long double px) { return Grid::Px { px }; }
220constexpr Grid::Px operator""_px (unsigned long long px) { return Grid::Px { px }; }
221constexpr Grid::Fr operator""_fr (unsigned long long fr) { return Grid::Fr { fr }; }
222
223} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:56
int size() const noexcept
Returns the current number of elements in the array.
Definition juce_Array.h:215
Container that handles geometry for grid layouts (fixed columns and rows) using a set of declarative ...
Definition juce_Grid.h:40
TrackInfo autoColumns
The column track for auto dimension.
Definition juce_Grid.h:190
Grid()=default
Creates an empty Grid container with default parameters.
JustifyItems
Possible values for the justifyItems property.
Definition juce_Grid.h:105
TrackInfo autoRows
The row track for auto dimension.
Definition juce_Grid.h:187
Array< TrackInfo > templateRows
The set of row tracks to lay out.
Definition juce_Grid.h:181
void setGap(Px sizeInPixels) noexcept
Sets the gap between rows and columns in pixels.
Definition juce_Grid.h:198
JustifyContent
Possible values for the justifyContent property.
Definition juce_Grid.h:123
int getNumberOfColumns() const noexcept
Returns the number of columns.
Definition juce_Grid.h:210
StringArray templateAreas
Template areas.
Definition juce_Grid.h:184
AlignContent
Possible values for the alignContent property.
Definition juce_Grid.h:135
Array< TrackInfo > templateColumns
The set of column tracks to lay out.
Definition juce_Grid.h:178
AlignItems
Possible values for the alignItems property.
Definition juce_Grid.h:114
AutoFlow
Possible values for the autoFlow property.
Definition juce_Grid.h:147
Array< GridItem > items
The set of items to lay-out.
Definition juce_Grid.h:202
int getNumberOfRows() const noexcept
Returns the number of rows.
Definition juce_Grid.h:212
Manages a rectangle and allows geometric operations to be performed on it.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
A fractional ratio integer.
Definition juce_Grid.h:56
A size in pixels.
Definition juce_Grid.h:45
Represents a track.
Definition juce_Grid.h:66
float getSize() const noexcept
Get the track's size - which might mean an absolute pixels value or a fractional ratio.
Definition juce_Grid.h:89