Skip to content

Commit e8854e9

Browse files
committed
#243 menu builder added large number and rtcall support, this completes the api
1 parent 53005ab commit e8854e9

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

src/EditableLargeNumberMenuItem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ class EditableLargeNumberMenuItem : public EditableMultiPartMenuItem {
208208
negativeAllowed = allowNeg;
209209
}
210210

211+
EditableLargeNumberMenuItem(const AnyMenuInfo* info, RuntimeRenderingFn renderFn, const LargeFixedNumber& initial, bool allowNeg, MenuItem* next = nullptr, bool isPgm = INFO_LOCATION_PGM)
212+
: EditableMultiPartMenuItem(info, isPgm, MENUTYPE_LARGENUM_VALUE, initial.getTotalDigits() + (allowNeg ? 1 : 0), renderFn, next) {
213+
data = initial;
214+
negativeAllowed = allowNeg;
215+
}
216+
211217
/** gets the large integer value that this class is using */
212218
LargeFixedNumber* getLargeNumber() { return &data; }
213219

src/TcMenuBuilder.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ TcMenuBuilder& TcMenuBuilder::rgb32CustomRt(menuid_t id, const char *name, Eepro
222222
return *this;
223223
}
224224

225+
TcMenuBuilder& TcMenuBuilder::largeNumberRtCustom(menuid_t id, const char *name, EepromPosition eepromPosition, const LargeFixedNumber& num,
226+
bool allowNegative, RuntimeRenderingFn renderFn, MenuFlags flags, MenuCallbackFn callbackFn) {
227+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 0, callbackFn);
228+
auto item = new EditableLargeNumberMenuItem(&reserve->getInfo()->anyInfo, renderFn, num, allowNegative, nullptr, false);
229+
flags.setOnMenuItem(item);
230+
putAtEndOfSub(item);
231+
return *this;
232+
}
233+
234+
TcMenuBuilder& TcMenuBuilder::largeNumberItem(menuid_t id, const char *name, EepromPosition eepromPosition, const LargeFixedNumber& num, bool allowNegative, MenuFlags flags, MenuCallbackFn callbackFn) {
235+
AnyInfoReserve* reserve = fillInAnyInfo(id, name, eepromPosition, 0, callbackFn);
236+
auto item = new EditableLargeNumberMenuItem(&reserve->getInfo()->anyInfo, num, allowNegative, nullptr, false);
237+
flags.setOnMenuItem(item);
238+
putAtEndOfSub(item);
239+
return *this;
240+
}
241+
242+
225243
TcMenuBuilder & TcMenuBuilder::listItemRam(menuid_t id, const char *name, uint16_t numberOfRows, const char** arrayOfItems, MenuFlags flags, MenuCallbackFn callbackFn) {
226244
AnyInfoReserve* reserve = fillInAnyInfo(id, name, 0xFFFF, numberOfRows, callbackFn);
227245
auto item = new ListRuntimeMenuItem(&reserve->getInfo()->anyInfo, numberOfRows, arrayOfItems, ListRuntimeMenuItem::RAM_ARRAY, nullptr, false);

src/TcMenuBuilder.h

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
#ifndef TCLIBRARYDEV_TCMENUBUILDER_H
33
#define TCLIBRARYDEV_TCMENUBUILDER_H
4+
#include "EditableLargeNumberMenuItem.h"
45
#include "EepromAbstraction.h"
56
#include "MenuItems.h"
67
#include "RuntimeMenuItem.h"
78

9+
class LargeFixedNumber;
810
class TcMenuBuilder;
911
struct RgbColor32;
1012
class MenuManager;
@@ -459,7 +461,7 @@ class TcMenuBuilder {
459461
* @param name The display name for the menu item.
460462
* @param eepromPosition The EEPROM storage position for persisting the value, or -1 if not stored in EEPROM.
461463
* @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.
464+
* @param ipInitial The initial value for the IP address storage.
463465
* @param callbackFn The callback function invoked when the menu item is selected or updated.
464466
* @return Reference to the current instance of TcMenuBuilder to allow method chaining.
465467
*/
@@ -506,8 +508,8 @@ class TcMenuBuilder {
506508
*
507509
* This method facilitates the setup of a scrollable choice menu item that allows the user to select
508510
* a value from a list of predefined choices. The ScrollChoiceBuilder returned by this method enables
509-
* further customization before the item is finalized and integrated into the menu structure. When you've configured
510-
* it make sure you call `endItem()` to finalize the menu item and add it to the menu structure.
511+
* further customization before the item is finalized and integrated into the menu structure. When you've finished
512+
* configuring it, make sure you call `endItem()` to finalize the menu item and add it to the menu structure.
511513
*
512514
* @code
513515
* builder.scrollChoiceBuilder(myId, "Choice Menu", myRomLocation, NoMenuFlags)
@@ -559,7 +561,7 @@ class TcMenuBuilder {
559561
* @param eepromPosition for dynamic set to ROM_SAVE or DONT_SAVE, for legacy mode use an eeprom address.
560562
* @param alphaChannel Boolean flag indicating whether the alpha channel is supported.
561563
* @param flags Additional configuration flags for the menu item.
562-
* @param initial The initial color value of type `RgbColor32` for the menu item.
564+
* @param initial The initial color value, for example, `RgbColor32(255, 0, 0)` for red.
563565
* @param callbackFn A function pointer for the menu item callback, invoked on user interaction.
564566
* @return A reference to the current `TcMenuBuilder` instance to allow for method chaining.
565567
*/
@@ -634,6 +636,43 @@ class TcMenuBuilder {
634636
*/
635637
TcMenuBuilder& listItemRtCustom(menuid_t id, const char *name, uint16_t numberOfRows, RuntimeRenderingFn rtRenderFn, MenuFlags flags, MenuCallbackFn callbackFn = nullptr);
636638

639+
/**
640+
* Adds a large number menu item to the menu structure. This is used for numeric values with a significant number of digits,
641+
* including fractional parts, such as financial or scientific fields. The total and fractional places control the format
642+
* and precision of the number.
643+
*
644+
* When you edit a large number, the editing occurs one digit at a time, allowing for precise control over the number's value,
645+
* even when there's a large number of digits.
646+
*
647+
* @param id The unique identifier for the menu item.
648+
* @param name The display name of the menu item.
649+
* @param eepromPosition The EEPROM position for storing the large number value.
650+
* @param num The large fixed number, for example, `LargeFixedNumber(10, 4, 98765, 1234)` is 10.4 digits representing "98765.1234".
651+
* @param allowNegative Whether negative numbers are allowed in the large number.
652+
* @param flags Additional flags to control visibility, read-only status, or other properties of the menu item.
653+
* @param callbackFn An optional callback function that is triggered when the value changes.
654+
* @return A reference to the builder, allowing method chaining.
655+
*/
656+
TcMenuBuilder& largeNumberItem(menuid_t id, const char *name, EepromPosition eepromPosition, const LargeFixedNumber& num,
657+
bool allowNegative, MenuFlags flags, MenuCallbackFn callbackFn = nullptr);
658+
659+
/**
660+
* Advanced construction case, adds a customized large number menu item with a renderFn callback to specialize how
661+
* it is displayed and processed. For regular large numbers use the standard method "largeNumber".
662+
*
663+
* @param id The unique identifier for the menu item.
664+
* @param name The display name of the menu item.
665+
* @param eepromPosition The EEPROM position for storing the large number value.
666+
* @param num The large fixed number, for example, `LargeFixedNumber(10, 4, 98765, 1234)` is 10.4 digits representing "98765.1234".
667+
* @param allowNegative Whether negative numbers are allowed in the large number.
668+
* @param renderFn The function used to render the list item's contents dynamically at runtime.
669+
* @param flags Additional flags to control visibility, read-only status, or other properties of the menu item.
670+
* @param callbackFn An optional callback function that is triggered when the value changes.
671+
* @return A reference to the builder, allowing method chaining.
672+
*/
673+
TcMenuBuilder& largeNumberRtCustom(menuid_t id, const char *name, EepromPosition eepromPosition, const LargeFixedNumber& num,
674+
bool allowNegative, RuntimeRenderingFn renderFn, MenuFlags flags, MenuCallbackFn callbackFn = nullptr);
675+
637676
/**
638677
* Add an item to the menu that allows for authentication using EEPROM storage. This item is read-only and displays
639678
* authentication status. When the authentication status changes, the provided callback function is invoked.
@@ -672,7 +711,7 @@ class TcMenuBuilder {
672711
* If the current menu has no parent, it returns a reference to the root TcMenuBuilder instance.
673712
* This allows chaining and continuation of the menu-building process.
674713
*
675-
* @return A reference to the parent TcMenuBuilder instance, or the root builder instance if no parent exists.
714+
* @return A reference to the parent TcMenuBuilder instance or the root builder instance if no parent exists.
676715
*/
677716
TcMenuBuilder& endSub();
678717

0 commit comments

Comments
 (0)