Skip to content

Commit 53005ab

Browse files
committed
#243 menu builder rtcall support
1 parent e60bea3 commit 53005ab

2 files changed

Lines changed: 131 additions & 5 deletions

File tree

src/TcMenuBuilder.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,23 @@ TcMenuBuilder & TcMenuBuilder::rgb32Item(menuid_t id, const char *name, EepromPo
205205
return rgb32Item(id, name, eepromPosition, alphaChannel, flags, RgbColor32(0, 0, 0), callbackFn);
206206
}
207207

208-
TcMenuBuilder & TcMenuBuilder::rgb32Item(menuid_t id, const char *name, EepromPosition eepromPosition, bool alphaChannel, MenuFlags flags, RgbColor32 initial, MenuCallbackFn callbackFn) {
208+
TcMenuBuilder & TcMenuBuilder::rgb32Item(menuid_t id, const char *name, EepromPosition eepromPosition, bool alphaChannel, MenuFlags flags, const RgbColor32& initial, MenuCallbackFn callbackFn) {
209209
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 3, callbackFn);
210210
auto item = new Rgb32MenuItem(&reserve->getInfo()->anyInfo, initial, alphaChannel, nullptr, false);
211211
flags.setOnMenuItem(item);
212212
putAtEndOfSub(item);
213213
return *this;
214214
}
215215

216+
TcMenuBuilder& TcMenuBuilder::rgb32CustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, bool alphaChannel,
217+
RuntimeRenderingFn renderFn, MenuFlags flags, const RgbColor32& initial, MenuCallbackFn callbackFn) {
218+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 3, callbackFn);
219+
auto item = new Rgb32MenuItem(&reserve->getInfo()->anyInfo, renderFn, initial, alphaChannel, nullptr, false);
220+
flags.setOnMenuItem(item);
221+
putAtEndOfSub(item);
222+
return *this;
223+
}
224+
216225
TcMenuBuilder & TcMenuBuilder::listItemRam(menuid_t id, const char *name, uint16_t numberOfRows, const char** arrayOfItems, MenuFlags flags, MenuCallbackFn callbackFn) {
217226
AnyInfoReserve* reserve = fillInAnyInfo(id, name, 0xFFFF, numberOfRows, callbackFn);
218227
auto item = new ListRuntimeMenuItem(&reserve->getInfo()->anyInfo, numberOfRows, arrayOfItems, ListRuntimeMenuItem::RAM_ARRAY, nullptr, false);
@@ -255,6 +264,33 @@ TcMenuBuilder& TcMenuBuilder::ipAddressItem(menuid_t id, const char *name, Eepro
255264
return ipAddressItem(id, name, eepromPosition, flags, IpAddressStorage(127, 0, 0, 1), callbackFn);
256265
}
257266

267+
TcMenuBuilder& TcMenuBuilder::ipAddressCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags,
268+
RuntimeRenderingFn renderFn, IpAddressStorage ipInitial, MenuCallbackFn callbackFn) {
269+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 3, callbackFn);
270+
auto item = new IpAddressMenuItem(&reserve->getInfo()->anyInfo, renderFn, ipInitial, nullptr, false);
271+
flags.setOnMenuItem(item);
272+
putAtEndOfSub(item);
273+
return *this;
274+
}
275+
276+
TcMenuBuilder& TcMenuBuilder::dateItemCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, DateStorage initial,
277+
RuntimeRenderingFn renderFn, MenuCallbackFn callbackFn) {
278+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 3, callbackFn);
279+
auto item = new DateFormattedMenuItem(&reserve->getInfo()->anyInfo, renderFn, initial, id, nullptr, false);
280+
flags.setOnMenuItem(item);
281+
putAtEndOfSub(item);
282+
return *this;
283+
}
284+
285+
TcMenuBuilder& TcMenuBuilder::timeItemCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, const TimeStorage& timeStorage,
286+
RuntimeRenderingFn renderFn, MenuFlags flags, MultiEditWireType timeFormat, MenuCallbackFn callbackFn) {
287+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 3, callbackFn);
288+
auto item = new TimeFormattedMenuItem(&reserve->getInfo()->anyInfo, renderFn, timeStorage, timeFormat, nullptr, false);
289+
flags.setOnMenuItem(item);
290+
putAtEndOfSub(item);
291+
return *this;
292+
}
293+
258294
TcMenuBuilder& TcMenuBuilder::textItem(menuid_t id, const char *name, EepromPosition eepromPosition, uint16_t textLength,
259295
MenuFlags flags, const char *initial, MenuCallbackFn callbackFn) {
260296
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, textLength, callbackFn);
@@ -264,6 +300,16 @@ TcMenuBuilder& TcMenuBuilder::textItem(menuid_t id, const char *name, EepromPosi
264300
return *this;
265301
}
266302

303+
TcMenuBuilder& TcMenuBuilder::textCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition,
304+
uint16_t textLength, RuntimeRenderingFn renderFn, MenuFlags flags,
305+
const char *initial, MenuCallbackFn callbackFn) {
306+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, textLength, callbackFn);
307+
auto item = new TextMenuItem(&reserve->getInfo()->anyInfo, renderFn, initial, textLength, nullptr, false);
308+
flags.setOnMenuItem(item);
309+
putAtEndOfSub(item);
310+
return *this;
311+
}
312+
267313
TcMenuBuilder TcMenuBuilder::subMenu(menuid_t id, const char *name, MenuFlags flags, MenuCallbackFn callbackFn) {
268314
AnyInfoReserve* reserve = fillInAnyInfo(id, name, 0xFFFF, 0, callbackFn);
269315
auto item = new SubMenuItem(&reserve->getInfo()->subInfo, nullptr, nullptr, false);

src/TcMenuBuilder.h

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,85 @@ class TcMenuBuilder {
422422
TcMenuBuilder& textItem(menuid_t id, const char *name, EepromPosition eepromPosition, uint16_t textLength,
423423
MenuFlags flags, const char *initial = "", MenuCallbackFn callbackFn = nullptr);
424424

425+
/**
426+
* Advanced build option for override of the regular text component for advanced cases, for example editing values that
427+
* need customization such as editing hex values for example.
428+
* @param id the ID of the item
429+
* @param name the name of the item
430+
* @param eepromPosition for dynamic set to ROM_SAVE or DONT_SAVE, for legacy mode use an eeprom address.
431+
* @param textLength The length of the text to be edited.
432+
* @param renderFn The callback function that will customize the control. Consult documentation for details.
433+
* @param flags The configuration flags that define the item's behavior and state.
434+
* @param initial the initial value, optional.
435+
* @param callbackFn The callback function triggered when the item's value changes.
436+
* @return
437+
*/
438+
TcMenuBuilder& textCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, uint16_t textLength,
439+
RuntimeRenderingFn renderFn, MenuFlags flags, const char* initial = "", MenuCallbackFn callbackFn = nullptr);
440+
441+
/**
442+
* Adds an IP address menu item to the menu structure. This item allows the user
443+
* to interact with and configure an IP address.
444+
*
445+
* @param id The unique identifier for this menu item.
446+
* @param name The display name for this menu item.
447+
* @param eepromPosition for dynamic set to ROM_SAVE or DONT_SAVE, for legacy mode use an eeprom address.
448+
* @param flags The configuration flags that define the item's behavior and state.
449+
* @param callbackFn An optional callback function triggered when the menu item is changed.
450+
* @return Reference to the TcMenuBuilder instance to allow for method chaining.
451+
*/
425452
TcMenuBuilder& ipAddressItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, MenuCallbackFn callbackFn = nullptr);
426453

454+
/**
455+
* Adds an IP Address type menu item to the menu structure being built. The IP Address menu item allows users
456+
* to configure or display an IP address directly within the menu.
457+
*
458+
* @param id The unique identifier for the menu item.
459+
* @param name The display name for the menu item.
460+
* @param eepromPosition The EEPROM storage position for persisting the value, or -1 if not stored in EEPROM.
461+
* @param flags The flags specifying visibility, read-only status, and other properties of the menu item.
462+
* @param initial The initial value for the IP address storage.
463+
* @param callbackFn The callback function invoked when the menu item is selected or updated.
464+
* @return Reference to the current instance of TcMenuBuilder to allow method chaining.
465+
*/
427466
TcMenuBuilder& ipAddressItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags,
428467
IpAddressStorage ipInitial, MenuCallbackFn callbackFn = nullptr);
429468

469+
/**
470+
* Advanced construction/build option. Adds a custom IP address menu item to the menu using the provided parameters.
471+
* This method allows customization of properties such as the menu ID, display name, EEPROM storage position, flags,
472+
* initial IP address, and an optional
473+
* callback function.
474+
*
475+
* @param id The unique identifier for the menu item.
476+
* @param name The display name of the menu item.
477+
* @param eepromPosition The EEPROM storage position for the value of this item.
478+
* @param flags Additional menu flags controlling visibility, read-only status, etc.
479+
* @param renderFn The callback function that will customize the control. Consult documentation for details.
480+
* @param ipInitial The initial value for the IP address to be displayed or stored.
481+
* @param callbackFn (Optional) A callback function invoked when the menu item is interacted with. Defaults to nullptr if not provided.
482+
* @return A reference to the TcMenuBuilder for further modification or chaining of method calls.
483+
*/
484+
TcMenuBuilder& ipAddressCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags,
485+
RuntimeRenderingFn renderFn, IpAddressStorage ipInitial, MenuCallbackFn callbackFn = nullptr);
486+
430487
TcMenuBuilder& timeItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, MultiEditWireType timeFormat,
431488
const TimeStorage& timeStorage, MenuCallbackFn callbackFn = nullptr);
432489

433490
TcMenuBuilder& timeItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, MultiEditWireType timeFormat,
434491
MenuCallbackFn callbackFn = nullptr);
435492

493+
TcMenuBuilder& timeItemCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, const TimeStorage& timeStorage,
494+
RuntimeRenderingFn renderFn, MenuFlags flags, MultiEditWireType timeFormat, MenuCallbackFn callbackFn = nullptr);
495+
436496
TcMenuBuilder& dateItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, DateStorage initial,
437497
MenuCallbackFn callbackFn = nullptr);
498+
438499
TcMenuBuilder& dateItem(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, MenuCallbackFn callbackFn = nullptr);
439500

501+
TcMenuBuilder& dateItemCustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, MenuFlags flags, DateStorage initial,
502+
RuntimeRenderingFn renderFn, MenuCallbackFn callbackFn = nullptr);
503+
440504
/**
441505
* @brief Creates and preconfigures a ScrollChoiceBuilder to define a scrollable choice menu item.
442506
*
@@ -500,7 +564,24 @@ class TcMenuBuilder {
500564
* @return A reference to the current `TcMenuBuilder` instance to allow for method chaining.
501565
*/
502566
TcMenuBuilder& rgb32Item(menuid_t id, const char *name, EepromPosition eepromPosition, bool alphaChannel,
503-
MenuFlags flags, RgbColor32 initial, MenuCallbackFn callbackFn = nullptr);
567+
MenuFlags flags, const RgbColor32& initial, MenuCallbackFn callbackFn = nullptr);
568+
569+
/**
570+
* Advanced construction/build case for RGB items where you need to override the menu in a custom way. This is
571+
* normally used when you want to customize the rendering or behavior of the RGB menu item beyond the standard options.
572+
*
573+
* @param id The unique identifier for the RGB32 menu item.
574+
* @param name The display name of the menu item.
575+
* @param eepromPosition for dynamic set to ROM_SAVE or DONT_SAVE, for legacy mode use an eeprom address.
576+
* @param alphaChannel Boolean flag indicating whether the alpha channel is supported.
577+
* @param renderFn The custom rendering function for the RGB menu item. Consult the documentation
578+
* @param flags Additional configuration flags for the menu item.
579+
* @param initial The initial color value of type `RgbColor32` for the menu item.
580+
* @param callbackFn A function pointer for the menu item callback, invoked on user interaction.
581+
* @return A reference to the current `TcMenuBuilder` instance to allow for method chaining.
582+
*/
583+
TcMenuBuilder& rgb32CustomRt(menuid_t id, const char *name, EepromPosition eepromPosition, bool alphaChannel,
584+
RuntimeRenderingFn renderFn, MenuFlags flags, const RgbColor32& initial, MenuCallbackFn callbackFn = nullptr);
504585

505586
/**
506587
* @brief Adds a list menu item to the menu structure with content stored in RAM.
@@ -579,7 +660,7 @@ class TcMenuBuilder {
579660
/**
580661
* Add an item that you've created manually, such as a custom item outside the scope of this builder. For example, if
581662
* you had used the traditional static method for some complex items, you could add them using this method.
582-
* @param itemToAdd the item to append to the menu hierarchy.
663+
* @param itemToAdd the item to append to the menu hierarchy. The item must not be deallocated after addition!
583664
* @return A reference to the current TcMenuBuilder instance for method chaining.
584665
*/
585666
TcMenuBuilder& appendCustomItem(MenuItem* itemToAdd);
@@ -626,5 +707,4 @@ class TcMenuBuilder {
626707

627708
};
628709

629-
630-
#endif //TCLIBRARYDEV_TCMENUBUILDER_H
710+
#endif //TCLIBRARYDEV_TCMENUBUILDER_H

0 commit comments

Comments
 (0)