Skip to content

Commit c79a878

Browse files
committed
ready for 3.0 release - small fix
1 parent 7f2f96a commit c79a878

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

examples/arduino32/piPicoTftEncoder/piPicoTftEncoder.ino

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void setup() {
4545
}, NO_REPEAT);
4646

4747
// and initialise the list menu item with the number of rows, see the list callback function below
48-
menuRootList.setNumberOfRows(FILE_NAME_SIZE);
48+
// we set the number of items to all the files plus the refresh item
49+
menuRootList.setNumberOfRows(FILE_NAME_SIZE + 1);
4950
}
5051

5152
void loop() {
@@ -154,16 +155,32 @@ void CALLBACK_FUNCTION onShowDialogs(int) {
154155
int CALLBACK_FUNCTION fnRootListRtCall(RuntimeMenuItem* item, uint8_t row, RenderFnMode mode, char* buffer, int bufferSize) {
155156
switch(mode) {
156157
case RENDERFN_INVOKE:
157-
serlogF2(SER_DEBUG, "List invoke: ", row);
158-
menuMgr.resetMenu(false); // drop back one level dismissing the list
159-
reinterpret_cast<ListRuntimeMenuItem*>(item)->asParent();
158+
// we have a list of files and a refresh option at the end.
159+
if(row < FILE_NAME_SIZE) {
160+
// a file has been selected, dismiss list.
161+
serlogF2(SER_DEBUG, "List invoke: ", row);
162+
menuMgr.resetMenu(false); // drop back one level dismissing the list
163+
reinterpret_cast<ListRuntimeMenuItem *>(item)->asParent();
164+
} else {
165+
// refresh was selected, refresh and force recalc.
166+
item->setNumberOfRows(item->getNumberOfRows() + 1);
167+
menuMgr.recalculateListIfOnDisplay(item);
168+
}
160169
return true;
161170
case RENDERFN_NAME:
162171
strncpy(buffer, "Choose File", bufferSize);
163172
return true;
164173
case RENDERFN_VALUE:
165-
if(row < FILE_NAME_SIZE) {
174+
if(row == LIST_PARENT_ITEM_POS) {
175+
// no value on the parent item, IE when this list is displayed in a parent menu.
176+
buffer[0]=0;
177+
} else if(row < FILE_NAME_SIZE) {
178+
// copy the file name into the buffer
166179
strncpy(buffer, fileNames[row], bufferSize);
180+
} else if(row == FILE_NAME_SIZE) {
181+
strcpy(buffer, "Add more");
182+
} else {
183+
ltoaClrBuff(buffer, row, 4, '0', bufferSize);
167184
}
168185
return true;
169186
case RENDERFN_EEPROM_POS: return 0xffff; // lists are generally not saved to EEPROM

examples/arduino32/picoAdafruitDashboard/dashboardConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// A few references from the dashboard source exported for the main file.
12

23
#ifndef TCEXAMPLE_DASHBOARDCONFIG_H
34
#define TCEXAMPLE_DASHBOARDCONFIG_H

src/tcMenu.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,14 @@ bool MenuManager::isWrapAroundEncoder(MenuItem* menuItem) {
484484
return useWrapAroundByDefault;
485485
}
486486

487-
void MenuManager::majorOrderChangeApplied(int newMax) {
488-
if(renderer->getRendererType() == RENDER_TYPE_CONFIGURABLE && getCurrentMenu()->getMenuType() != MENUTYPE_RUNTIME_LIST) {
489-
setItemsInCurrentMenu(newMax);
487+
void MenuManager::recalculateListIfOnDisplay(RuntimeMenuItem* runtimeItem) {
488+
auto enc = switches.getEncoder();
489+
// if there is an encoder, and the current menu is the list..
490+
if(enc && navigator.getCurrentRoot() == runtimeItem) {
491+
auto newRows = runtimeItem->getNumberOfRows();
492+
auto encVal = enc->getCurrentReading();
493+
uint8_t newPos = encVal < newRows ? encVal : (newRows - 1);
494+
setItemsInCurrentMenu(newRows, newPos);
490495
}
491496
}
492497

src/tcMenu.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,12 @@ class MenuManager {
446446
*/
447447
void addChangeNotification(MenuManagerObserver* observer);
448448

449-
void majorOrderChangeApplied(int newMax);
449+
/**
450+
* This provides support for when lists are on the display, to allow the encoder to be updated so it can present
451+
* the new items. If the list is not on display, nothing is done.
452+
* @param runtimeItem
453+
*/
454+
void recalculateListIfOnDisplay(RuntimeMenuItem* runtimeItem);
450455

451456
void setEditorHints(CurrentEditorRenderingHints::EditorRenderingType hint, size_t start=0, size_t end=0);
452457
const CurrentEditorRenderingHints& getEditorHints() { return renderingHints; }

0 commit comments

Comments
 (0)