Skip to content

Provide wrappers around menu creation for fluent menu creation #243

@davetcc

Description

@davetcc

Is your feature request related to a problem? Please describe.
The current situation with TcMenu needing a designer UI for day-to-day actions is somewhat outdated now. The main need for this goes back to earlier C++ versions and strict memory requirements of some boards.

Confirm that the bug is in the embedded library
Yes

Describe the solution you'd like
Create a menu builder that can use fluent syntax to build menus, it will not be able to store parts of the structure in the INFO block, but with memory even on the smallest boards now at 32K the whole structure of even a moderately large menu should come in at about 2K.

No way of getting around this, it is dynamic using new, but this happens once at startup and is never released through the application run. This means there will be very limited to no fragmentation. Further, the INFO blocks are pre-allocated as they do not use dynamic types.

There is no plan to remove the existing support; in fact, this is just a thin wrapper around it.

This is an inflight code example by converting one of the structures:

void buildMenu(TcMenuBuilder& builder) {
    builder.usingDynamicEEPROMStorage()
        .actionItem(HIBERNATE_ID, "Hibernate", NoMenuFlags, onHibernate)
        .analogBuilder(INT_EDIT_ID, "Int Edit", ROM_SAVE, NoMenuFlags, 4)
            .offset(0).divisor(1).maxValue(100).unit("%").endItem()
        .analogBuilder(DEC_EDIT_ID, "Dec Edit", ROM_SAVE, NoMenuFlags, 0)
            .offset(0).divisor(100).maxValue(1000).unit("oC").endItem()
        .analogBuilder(HALVES_ID, "Halves", ROM_SAVE, MenuFlags().readOnly(), 0)
            .offset(0).divisor(2).maxValue(100).unit("").endItem()
        .enumItem(FOODS_ID, "Foods", ROM_SAVE, enumFoodsArray, 4, NoMenuFlags)
        .boolItem(DOOR_OPEN_ID, "Door Open", ROM_SAVE, NAMING_YES_NO, NoMenuFlags)
        .subMenu(EXTRAS_ID, "Extras", NoMenuFlags)
            .textItem(EXTRAS_TEXT_ID, "Text", ROM_SAVE, 10, NoMenuFlags)
            .rgb32Item(EXTRAS_RGB_ID, "Color", ROM_SAVE, false, NoMenuFlags)
            .listItemRtCustom(EXTRAS_LIST_ID, "My List", 10, fnExtrasMyListRtCall, NoMenuFlags)
            .endSub()
        .subMenu(CONNECTIVITY_ID, "Connectivity", NoMenuFlags)
            .textItem(CONNECTIVITY_SSID_ID, "SSID", ROM_SAVE, 20, NoMenuFlags)
            .textItem(CONNECTIVITY_PASSCODE_ID, "Passcode", ROM_SAVE, 20, NoMenuFlags)
            .enumItem(CONNECTIVITY_WIFI_MODE_ID, "WiFi Mode", ROM_SAVE, enumWiFiMode, 2, NoMenuFlags)
            .ipAddressItem(CONNECTIVITY_IP_ADDR_ID, "IP Address", DONT_SAVE, NoMenuFlags)
            .remoteConnectivityMonitor(CONNECTIVITY_MON_ID, "IoT Monitor", MenuFlags().localOnly())
            .eepromAuthenticationItem(CONNECTIVITY_AUTH_ID, "Authenticator", MenuFlags().localOnly())
            .endSub();

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions