Skip to content

Commit 6c9602c

Browse files
committed
Moved menu
1 parent 6c39595 commit 6c9602c

File tree

10 files changed

+599
-140
lines changed

10 files changed

+599
-140
lines changed

examples/graphics/source/examples/PopupMenu.h

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ class PopupMenuDemo : public yup::Component
136136

137137
void showBasicMenu()
138138
{
139-
auto menu = yup::PopupMenu::create();
139+
auto options = yup::PopupMenu::Options{}
140+
.withParentComponent(&basicMenuButton);
141+
142+
auto menu = yup::PopupMenu::create (options);
140143

141144
menu->addItem ("New File", newFile, true, false, "Cmd+N");
142145
menu->addItem ("Open File", openFile, true, false, "Cmd+O");
@@ -154,7 +157,7 @@ class PopupMenuDemo : public yup::Component
154157
handleMenuSelection (selectedID);
155158
};
156159

157-
menu->showAt (&basicMenuButton);
160+
menu->show();
158161
}
159162

160163
void showSubMenu()
@@ -168,7 +171,9 @@ class PopupMenuDemo : public yup::Component
168171
colorMenu->addItem ("Green", colorGreen);
169172
colorMenu->addItem ("Blue", colorBlue);
170173

171-
auto menu = yup::PopupMenu::create();
174+
auto options = yup::PopupMenu::Options{}
175+
.withParentComponent(&subMenuButton);
176+
auto menu = yup::PopupMenu::create (options);
172177
menu->addItem ("New", newFile);
173178
menu->addItem ("Open", openFile);
174179
menu->addSubMenu ("Recent Files", recentFilesMenu);
@@ -182,12 +187,14 @@ class PopupMenuDemo : public yup::Component
182187
handleMenuSelection (selectedID);
183188
};
184189

185-
menu->showAt (&subMenuButton);
190+
menu->show();
186191
}
187192

188193
void showCustomMenu()
189194
{
190-
auto menu = yup::PopupMenu::create();
195+
auto options = yup::PopupMenu::Options{}
196+
.withParentComponent(&customMenuButton);
197+
auto menu = yup::PopupMenu::create (options);
191198

192199
menu->addItem ("Regular Item", 1);
193200
menu->addSeparator();
@@ -218,12 +225,17 @@ class PopupMenuDemo : public yup::Component
218225
handleMenuSelection (selectedID);
219226
};
220227

221-
menu->showAt (&customMenuButton);
228+
menu->show();
222229
}
223230

224231
void showNativeMenu()
225232
{
226-
auto menu = yup::PopupMenu::create();
233+
auto options = yup::PopupMenu::Options{}
234+
.withNativeMenus(true)
235+
.withJustification(yup::Justification::topLeft)
236+
.withParentComponent(this);
237+
238+
auto menu = yup::PopupMenu::create (options);
227239

228240
menu->addItem ("Native Item 1", 1);
229241
menu->addItem ("Native Item 2", 2);
@@ -235,19 +247,20 @@ class PopupMenuDemo : public yup::Component
235247
handleMenuSelection (selectedID);
236248
};
237249

238-
yup::PopupMenu::Options options;
239-
options.useNativeMenus = true;
240-
options.parentComponent = this;
241-
242-
menu->show (options, [this] (int selectedID)
250+
menu->show ([this] (int selectedID)
243251
{
244252
handleMenuSelection (selectedID);
245253
});
246254
}
247255

248256
void showContextMenu (yup::Point<float> position)
249257
{
250-
auto contextMenu = yup::PopupMenu::create();
258+
auto options = yup::PopupMenu::Options{}
259+
// .withTargetScreenPosition(position.to<int>()) // TODO: doesn't seem to work
260+
.withParentComponent(this)
261+
.withAsChildToTopmost(true);
262+
263+
auto contextMenu = yup::PopupMenu::create (options);
251264

252265
contextMenu->addItem ("Copy", editCopy);
253266
contextMenu->addItem ("Paste", editPaste);
@@ -261,11 +274,7 @@ class PopupMenuDemo : public yup::Component
261274
handleMenuSelection (selectedID);
262275
};
263276

264-
yup::PopupMenu::Options options;
265-
options.parentComponent = this;
266-
options.targetScreenPosition = position.to<int>();
267-
268-
contextMenu->show (options, [this] (int selectedID)
277+
contextMenu->show ([this] (int selectedID)
269278
{
270279
handleMenuSelection (selectedID);
271280
});
@@ -280,39 +289,51 @@ class PopupMenuDemo : public yup::Component
280289
case newFile:
281290
message = "New File selected";
282291
break;
292+
283293
case openFile:
284294
message = "Open File selected";
285295
break;
296+
286297
case saveFile:
287298
message = "Save File selected";
288299
break;
300+
289301
case saveAsFile:
290302
message = "Save As selected";
291303
break;
304+
292305
case exitApp:
293306
message = "Exit selected";
294307
break;
308+
295309
case editCopy:
296310
message = "Copy selected";
297311
break;
312+
298313
case editPaste:
299314
message = "Paste selected";
300315
break;
316+
301317
case colorRed:
302318
message = "Red color selected";
303319
break;
320+
304321
case colorGreen:
305322
message = "Green color selected";
306323
break;
324+
307325
case colorBlue:
308326
message = "Blue color selected";
309327
break;
328+
310329
case customSlider:
311330
message = "Custom slider interacted";
312331
break;
332+
313333
case customButton:
314334
message = "Custom button clicked";
315335
break;
336+
316337
default:
317338
break;
318339
}

modules/yup_graphics/fonts/yup_Font.h

Lines changed: 123 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ namespace yup
2323
{
2424

2525
//==============================================================================
26+
/** Font.
2627
28+
This class represents a font.
29+
*/
2730
class YUP_API Font
2831
{
2932
public:
3033
//==============================================================================
34+
/** Creates an empty font. */
3135
Font() = default;
3236

3337
//==============================================================================
@@ -38,18 +42,39 @@ class YUP_API Font
3842
Font& operator= (Font&& other) noexcept = default;
3943

4044
//==============================================================================
45+
/** Loads a font from a memory block.
46+
47+
@param fontBytes The memory block containing the font data.
48+
@return The result of the operation.
49+
*/
4150
Result loadFromData (const MemoryBlock& fontBytes);
4251

4352
//==============================================================================
53+
/** Loads a font from a file.
54+
55+
@param fontFile The file containing the font data.
56+
@return The result of the operation.
57+
*/
4458
Result loadFromFile (const File& fontFile);
4559

4660
//==============================================================================
61+
/** Returns the ascent of the font. */
4762
float getAscent() const;
63+
64+
/** Returns the descent of the font. */
4865
float getDescent() const;
66+
67+
/** Returns the weight of the font. */
4968
int getWeight() const;
69+
70+
/** Returns true if the font is italic. */
5071
bool isItalic() const;
5172

5273
//==============================================================================
74+
/** Axis.
75+
76+
This struct represents an axis of the font.
77+
*/
5378
struct Axis
5479
{
5580
Axis() = default;
@@ -60,19 +85,102 @@ class YUP_API Font
6085
float defaultValue = 0.0f;
6186
};
6287

88+
/** Returns the number of axes in the font.
89+
90+
@return The number of axes in the font.
91+
*/
6392
int getNumAxis() const;
93+
94+
/** Returns the description of the axis at the given index.
95+
96+
@param index The index of the axis.
97+
98+
@return The description of the axis.
99+
*/
64100
std::optional<Font::Axis> getAxisDescription (int index) const;
101+
102+
/** Returns the description of the axis with the given tag name.
103+
104+
@param tagName The tag name of the axis.
105+
106+
@return The description of the axis.
107+
*/
65108
std::optional<Font::Axis> getAxisDescription (StringRef tagName) const;
66109

110+
//==============================================================================
111+
/** Returns the value of the axis at the given index.
112+
113+
@param index The index of the axis.
114+
115+
@return The value of the axis.
116+
*/
67117
float getAxisValue (int index) const;
68-
float getAxisValue (StringRef tagName) const;
69118

119+
/** Sets the value of the axis at the given index.
120+
121+
@param index The index of the axis.
122+
@param value The value of the axis.
123+
*/
70124
void setAxisValue (int index, float value);
71-
void setAxisValue (StringRef tagName, float value);
72125

126+
/** Returns a new font with the value of the axis at the given index.
127+
128+
@param index The index of the axis.
129+
@param value The value of the axis.
130+
131+
@return A new font with the value of the axis at the given index.
132+
*/
73133
Font withAxisValue (int index, float value) const;
134+
135+
/** Resets the value of the axis at the given index.
136+
137+
@param index The index of the axis.
138+
*/
139+
void resetAxisValue (int index);
140+
141+
//==============================================================================
142+
/** Returns the value of the axis with the given tag name.
143+
144+
@param tagName The tag name of the axis.
145+
146+
@return The value of the axis.
147+
*/
148+
float getAxisValue (StringRef tagName) const;
149+
150+
/** Sets the value of the axis with the given tag name.
151+
152+
@param tagName The tag name of the axis.
153+
@param value The value of the axis.
154+
*/
155+
void setAxisValue (StringRef tagName, float value);
156+
157+
/** Returns a new font with the value of the axis with the given tag name.
158+
159+
@param tagName The tag name of the axis.
160+
@param value The value of the axis.
161+
162+
@return A new font with the value of the axis with the given tag name.
163+
*/
74164
Font withAxisValue (StringRef tagName, float value) const;
75165

166+
/** Resets the value of the axis with the given tag name.
167+
168+
@param tagName The tag name of the axis.
169+
*/
170+
void resetAxisValue (StringRef tagName);
171+
172+
//==============================================================================
173+
/** Resets the values of all axes.
174+
175+
@return A new font with the values of all axes reset.
176+
*/
177+
void resetAllAxisValues();
178+
179+
//==============================================================================
180+
/** Axis option.
181+
182+
This struct represents an option of the axis.
183+
*/
76184
struct AxisOption
77185
{
78186
AxisOption (StringRef tagName, float value)
@@ -85,16 +193,25 @@ class YUP_API Font
85193
float value;
86194
};
87195

196+
/** Sets the values of the axes.
197+
198+
@param axisOptions The options of the axes.
199+
*/
88200
void setAxisValues (std::initializer_list<AxisOption> axisOptions);
89-
Font withAxisValues (std::initializer_list<AxisOption> axisOptions) const;
90201

91-
void resetAxisValue (int index);
92-
void resetAxisValue (StringRef tagName);
202+
/** Returns a new font with the values of the axes.
93203
94-
void resetAllAxisValues();
204+
@param axisOptions The options of the axes.
205+
206+
@return A new font with the values of the axes.
207+
*/
208+
Font withAxisValues (std::initializer_list<AxisOption> axisOptions) const;
95209

96210
//==============================================================================
211+
/** Returns true if the fonts are equal. */
97212
bool operator== (const Font& other) const;
213+
214+
/** Returns true if the fonts are not equal. */
98215
bool operator!= (const Font& other) const;
99216

100217
//==============================================================================

0 commit comments

Comments
 (0)