@@ -29,8 +29,7 @@ class MenuSystem;
29
29
// !
30
30
// ! \see Menu
31
31
// ! \see MenuItem
32
- class MenuComponent
33
- {
32
+ class MenuComponent {
34
33
friend class MenuSystem ;
35
34
friend class Menu ;
36
35
public:
@@ -186,8 +185,7 @@ class MenuComponent
186
185
// !
187
186
// ! \see MenuComponent
188
187
// ! \see Menu
189
- class MenuItem : public MenuComponent
190
- {
188
+ class MenuItem : public MenuComponent {
191
189
public:
192
190
// ! \brief Construct a MenuItem
193
191
// ! \param[in] name The name of the menu component that is displayed in
@@ -222,8 +220,7 @@ class MenuItem : public MenuComponent
222
220
223
221
// ! \brief A MenuItem that calls MenuSystem::back() when selected.
224
222
// ! \see MenuItem
225
- class BackMenuItem : public MenuItem
226
- {
223
+ class BackMenuItem : public MenuItem {
227
224
public:
228
225
BackMenuItem (const char * name, SelectFnPtr select_fn, MenuSystem* ms);
229
226
@@ -233,12 +230,11 @@ class BackMenuItem : public MenuItem
233
230
virtual Menu* select ();
234
231
235
232
protected:
236
- MenuSystem* menu_system ;
233
+ MenuSystem* _menu_system ;
237
234
};
238
235
239
236
240
- class NumericMenuItem : public MenuItem
241
- {
237
+ class NumericMenuItem : public MenuItem {
242
238
public:
243
239
// ! \brief Callback for formatting the numeric value into a String.
244
240
// !
@@ -247,39 +243,39 @@ class NumericMenuItem : public MenuItem
247
243
using FormatValueFnPtr = const String (*)(const float value);
248
244
249
245
public:
250
- // / Constructor
251
- // /
252
- // / @param name The name of the menu item.
253
- // / @param select_fn The function to call when this MenuItem is selected.
254
- // / @param value Default value.
255
- // / @param minValue The minimum value.
256
- // / @param maxValue The maximum value.
257
- // / @param increment How much the value should be incremented by.
258
- // / @param valueFormatter The custom formatter. If nullptr the String float
259
- // / formatter will be used.
246
+ // ! Constructor
247
+ // !
248
+ // ! @param name The name of the menu item.
249
+ // ! @param select_fn The function to call when this MenuItem is selected.
250
+ // ! @param value Default value.
251
+ // ! @param min_value The minimum value.
252
+ // ! @param max_value The maximum value.
253
+ // ! @param increment How much the value should be incremented by.
254
+ // ! @param format_value_fn The custom formatter. If nullptr the String
255
+ // ! float formatter will be used.
260
256
NumericMenuItem (const char * name, SelectFnPtr select_fn,
261
- float value, float minValue , float maxValue ,
257
+ float value, float min_value , float max_value ,
262
258
float increment=1.0 ,
263
259
FormatValueFnPtr format_value_fn=nullptr );
264
260
265
- /* *
266
- * Sets the custom number formatter.
267
- *
268
- * @ param numberFormat the custom formatter. If nullptr the String float
269
- * formatter will be used (2 decimals)
270
- */
261
+ // !
262
+ // ! \brief Sets the custom number formatter.
263
+ // !
264
+ // ! \ param numberFormat the custom formatter. If nullptr the String float
265
+ // ! formatter will be used (2 decimals)
266
+ // !
271
267
void set_number_formatter (FormatValueFnPtr format_value_fn);
272
268
273
269
float get_value () const ;
274
- float get_minValue () const ;
275
- float get_maxValue () const ;
270
+ float get_min_value () const ;
271
+ float get_max_value () const ;
276
272
277
- // TODO: get_value_string is a poor name. get_formatted_value maybe?
278
- String get_value_string () const ;
279
273
void set_value (float value);
280
274
void set_min_value (float value);
281
275
void set_max_value (float value);
282
276
277
+ String get_formatted_value () const ;
278
+
283
279
virtual void render (MenuComponentRenderer const & renderer) const ;
284
280
285
281
protected:
@@ -290,20 +286,30 @@ class NumericMenuItem : public MenuItem
290
286
291
287
protected:
292
288
float _value;
293
- float _minValue ;
294
- float _maxValue ;
289
+ float _min_value ;
290
+ float _max_value ;
295
291
float _increment;
296
292
FormatValueFnPtr _format_value_fn;
297
293
};
298
294
299
295
300
- class Menu : public MenuComponent
301
- {
296
+ // ! \brief A MenuComponent that can contain other MenuComponents.
297
+ // !
298
+ // ! Menu represents the branch in the composite design pattern (see:
299
+ // ! https://en.wikipedia.org/wiki/Composite_pattern). When a Menu is
300
+ // ! selected, the user-defined Menu::_select_fn callback is called.
301
+ // !
302
+ // ! \see MenuComponent
303
+ // ! \see MenuItem
304
+ class Menu : public MenuComponent {
302
305
friend class MenuSystem ;
303
306
public:
304
307
Menu (const char * name, SelectFnPtr select_fn=nullptr );
305
308
309
+ // ! \brief Adds a MenuItem to the Menu
306
310
void add_item (MenuItem* p_item);
311
+
312
+ // ! \brief Adds a Menu to the Menu
307
313
void add_menu (Menu* p_menu);
308
314
309
315
MenuComponent const * get_current_component () const ;
@@ -313,16 +319,29 @@ class Menu : public MenuComponent
313
319
uint8_t get_current_component_num () const ;
314
320
uint8_t get_previous_component_num () const ;
315
321
322
+ // ! \copydoc MenuComponent::render
316
323
void render (MenuComponentRenderer const & renderer) const ;
317
324
318
325
protected:
319
- void set_parent (Menu* pParent );
326
+ void set_parent (Menu* p_parent );
320
327
Menu const * get_parent () const ;
321
328
329
+ // ! \brief Activates the current selection
330
+ // !
331
+ // ! When a client makes a selection, activate is called on the current menu
332
+ // ! which in turn calls the menu's current item's callback.
322
333
Menu* activate ();
334
+
335
+ // ! \copydoc MenuComponent::next
323
336
virtual bool next (bool loop=false );
337
+
338
+ // ! \copydoc MenuComponent::prev
324
339
virtual bool prev (bool loop=false );
340
+
341
+ // ! \copydoc MenuComponent::select
325
342
virtual Menu* select ();
343
+
344
+ // ! \copydoc MenuComponent::reset
326
345
virtual void reset ();
327
346
328
347
void add_component (MenuComponent* p_component);
@@ -337,8 +356,7 @@ class Menu : public MenuComponent
337
356
};
338
357
339
358
340
- class MenuSystem
341
- {
359
+ class MenuSystem {
342
360
public:
343
361
MenuSystem (MenuComponentRenderer const & renderer);
344
362
@@ -359,8 +377,7 @@ class MenuSystem
359
377
};
360
378
361
379
362
- class MenuComponentRenderer
363
- {
380
+ class MenuComponentRenderer {
364
381
public:
365
382
virtual void render (Menu const & menu) const = 0;
366
383
0 commit comments