55 */
66
77#include " dynamicMenuItems_menu.h"
8+ #include < BaseDialog.h>
89#include < IoAbstractionWire.h>
9-
10- // we declare a reference to an io expander as our encoder is on I2C
11- IoAbstractionRef io8574 = ioFrom8574(0x20 , 0 ); // on addr 0x20 and interrupt pin 0
10+ #include < graphics/RuntimeTitleMenuItem.h>
11+ #include < tcMenuVersion.h>
1212
1313// Pizza toppings that we forward referenced in the scroll choice item, when in RAM or EEPROM then they are declared in
1414// a flat array based on the item size.
@@ -97,13 +97,34 @@ void prepareOvenMenuAtRuntime() {
9797 menuMgr.addMenuAfter (&menuBackOven, &menuOvenTempItem);
9898}
9999
100+ //
101+ // We register a handler that will be called when the title menu item is selected, see setup where we set the callback
102+ //
103+ void onTitlePressed (int /* id*/ ) {
104+ withMenuDialogIfAvailable ([] (MenuBasedDialog* dlg) {
105+ dlg->setButtons (BTNTYPE_CLOSE, BTNTYPE_NONE);
106+ dlg->showRam (" Title clicked" , false );
107+ char szVer[10 ];
108+ tccore::copyTcMenuVersion (szVer, sizeof szVer);
109+ dlg->copyIntoBuffer (szVer);
110+ });
111+ }
112+
100113void setup () {
114+ // If we use wire or serial, it's our responsibility to prepare it.
101115 Serial.begin (115200 );
102116 Wire.begin ();
103117 setupMenu ();
118+
119+ // Here we add a menu observer that is notified as events take place on the menu.
104120 menuMgr.addChangeNotification (&myMgrObserver);
121+
122+ // Now we set up the runtime parameters of various menu items
105123 prepareOvenMenuAtRuntime ();
106124 menuList.setNumberOfRows (numListItems);
125+
126+ // and lastly we add the title callback that is notified of the title being selected
127+ appTitleMenuItem.setCallback (onTitlePressed);
107128}
108129
109130void loop () {
@@ -152,17 +173,24 @@ void CALLBACK_FUNCTION onDialogInfo(int id) {
152173}
153174
154175//
155- // Shows a question dialog that gets the title from const/program memory. Notice that in this case we have a completion handler
156- // that accepts the final value, so that we could do something with the result.
176+ // Shows a question dialog that gets the title from const/program memory. Notice that in this case we have a completion
177+ // handler that accepts the final value, so that we could do something with the result.
157178//
158- const char pgmQuestionHeader[] PROGMEM = {" Question.." };
179+ const char pgmQuestionHeader[] PROGMEM = {" Override the title?" };
180+ const char pgmTitleOverride[] PROGMEM = {" Title Overridden" };
159181taskid_t questionTask = TASKMGR_INVALIDID;
160182void CALLBACK_FUNCTION onDialogQuestion (int id) {
161183 withMenuDialogIfAvailable ([] (MenuBasedDialog* dlg) {
162- dlg->setButtons (BTNTYPE_ACCEPT , BTNTYPE_CANCEL);
184+ dlg->setButtons (BTNTYPE_OK , BTNTYPE_CANCEL);
163185 dlg->show (pgmQuestionHeader, true , [](ButtonType btn, void * data) {
164186 // this is the completion task that runs when the dialog is dismissed.
165187 Serial.print (" Question result was " ); Serial.println (btn);
188+ if (btn == BTNTYPE_OK) {
189+ appTitleMenuItem.setTitleOverridePgm (pgmTitleOverride);
190+ }
191+ else {
192+ appTitleMenuItem.clearTitleOverride ();
193+ }
166194 taskManager.cancelTask (questionTask);
167195 });
168196
@@ -179,7 +207,6 @@ void CALLBACK_FUNCTION onDialogQuestion(int id) {
179207// In this case we create a controller based dialog that increments and decrements a number that is stored within
180208// an Analog item. We add the analog item and also an extra button to the dialog.
181209//
182-
183210class MyDialogController : public BaseDialogController {
184211private:
185212 // create an extra button (buttonNum = 2)
0 commit comments