Files
MeshCore-Solo/examples/companion_radio/ui-new/AutoAdvertScreen.h
T
Jakub 6d1e71cd3f fix(ui): one rule for value rows, one meaning for Hold Enter
Three interaction inconsistencies found while auditing the favourites work,
all of the same shape: the same gesture meaning different things depending
on which screen you were on.

Value rows in popup menus. Rows like "Notif: ON" or "Sort: Dist" show a
value the user steps through with LEFT/RIGHT, but Enter treated them as
ordinary menu picks and closed the popup, so changing two of them meant
reopening the menu in between. Trail's settings submenu was the lone
exception, working around it by rebuilding and re-selecting after each
Enter. PopupMenu now knows the difference: addValueItem() marks a row, and
Enter on it returns the new VALUE_NEXT instead of SELECTED, leaving the
menu open. Only Back closes a menu now. Applied to the Messages
contact/room/channel menus, Nodes, the Ringtone editor and Trail, which
drops its reopenSettingsAt() workaround. The LEFT/RIGHT cycling bodies
moved into one helper per menu, since Enter and RIGHT now share them.

Nodes' Fav row was the worst case: LEFT/RIGHT did nothing there at all, so
the only way to toggle a favourite was an Enter that dismissed the menu on
every flip. Its label moved to a member buffer (as the Pin row already had)
so it can be retitled in place.

Settings rows Auto-off, Low battery, GPS pwr and Battery ignored Enter,
though their options wrap exactly like the melody/keyboard/clock rows
beside them, where Enter has always stepped forward. They accept it now.
Rows that ramp between fixed ends (Brightness, Volume, TX Pwr, Timezone,
SF/BW/CR) stay LEFT/RIGHT-only -- there is nothing to wrap to.

Hold Enter no longer doubles as Back. It quietly meant "go back" on Tools,
Locator, Live Share, Repeater, Bot, Auto-Advert, GPIO, Compass, the
Dashboard config and the Messages navigate view, while elsewhere the same
long press opens a context menu. It now only ever opens a menu, or does
nothing where there is none. Same for dismissing an open popup, which it
used to do. Checked that this strands nobody: every board that can reach
these screens has a real Back key (back_btn on joystick boards, Esc on
CardKB/TCA8418/T-Deck). Single-button boards produce no KEY_ENTER at all,
so they never leave the home pages in the first place.
2026-08-31 15:43:10 +02:00

73 lines
2.2 KiB
C++

#pragma once
// Configures periodic automatic 0-hop advert with GPS position.
// Included by UITask.cpp after DashboardConfigScreen.h.
class AutoAdvertScreen : public UIScreen {
UITask* _task;
NodePrefs* _prefs;
bool _dirty;
static const int OPT_COUNT = 8;
static const uint32_t OPTS[OPT_COUNT];
static const char* OPT_LABELS[OPT_COUNT];
int currentIdx() const {
for (int i = 0; i < OPT_COUNT; i++)
if (OPTS[i] == _prefs->advert_auto_interval_sec) return i;
return 0;
}
public:
AutoAdvertScreen(UITask* task, NodePrefs* prefs) : _task(task), _prefs(prefs) {}
void onShow() override { _dirty = false; }
int render(DisplayDriver& display) override {
display.setTextSize(1);
display.setColor(DisplayDriver::LIGHT);
int label_y = display.listStart();
int bar_y = label_y + display.lineStep();
int bar_h = display.lineStep();
int tip_y = bar_y + bar_h + 4;
display.drawCenteredHeader("AUTO-ADVERT");
display.setCursor(2, label_y);
display.print("Interval:");
int idx = currentIdx();
display.setColor(DisplayDriver::LIGHT);
display.fillRect(0, bar_y, display.width(), bar_h);
display.setColor(DisplayDriver::DARK);
display.drawTextCentered(display.width() / 2, bar_y + 1, OPT_LABELS[idx]);
display.setColor(DisplayDriver::LIGHT);
display.setCursor(2, tip_y);
display.print("< > to change");
display.setCursor(2, tip_y + display.lineStep());
display.print("[Esc] to save");
return 500;
}
bool handleInput(char c) override {
if (c == KEY_CANCEL) {
_task->savePrefsIfDirty(_dirty);
_task->gotoToolsScreen();
return true;
}
bool right = keyIsNext(c) || c == KEY_ENTER;
bool left = keyIsPrev(c);
if (right || left) {
int idx = currentIdx();
idx = right ? (idx + 1) % OPT_COUNT : (idx + OPT_COUNT - 1) % OPT_COUNT;
_prefs->advert_auto_interval_sec = OPTS[idx];
_dirty = true;
return true;
}
return false;
}
};
const uint32_t AutoAdvertScreen::OPTS[AutoAdvertScreen::OPT_COUNT] = { 0, 30, 60, 120, 300, 600, 1800, 3600 };
const char* AutoAdvertScreen::OPT_LABELS[AutoAdvertScreen::OPT_COUNT] = { "OFF", "30s", "1min", "2min", "5min", "10min", "30min", "1h" };