refactor(ui): shared drawList + header + key-decode helpers

- drawList(): scrollable list skeleton (visible window, keep-sel-in-view,
  scroll-column reserve, per-row callback, indicator). Migrate Tools, Bot,
  Nearby, Waypoints list and the three QuickMsg lists onto it; centralises the
  scroll-clamp/reserve/indicator that each had open-coded (and inconsistently).
- drawCenteredHeader(): centred title + separator, replacing the duplicated
  two-liner across ~10 screens (incl. QuickMsg, which used width()/2 spacing and
  was missed before); unifies the separator at headerH()-sepH().
- keyIsPrev()/keyIsNext() in UIScreen.h for the LEFT||PREV / RIGHT||NEXT idiom;
  applied to 6 screens, behaviour-preserving. Cancel/context-menu stay
  per-screen (they mean different things on different screens).
- rotLabel() dedups the 0/90/180/270 array in Settings.
- Unify selection-row height to lineStep()-1 (Tools/Bot matched the rest).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-15 21:23:00 +02:00
co-authored by Claude Opus 4.8
parent 98af868e68
commit 9da730e3b6
13 changed files with 89 additions and 123 deletions
@@ -127,8 +127,7 @@ class WaypointsView {
void renderAddForm(DisplayDriver& display) {
display.setColor(DisplayDriver::LIGHT);
display.drawTextCentered(display.width() / 2, 0, "ADD WAYPOINT");
display.fillRect(0, display.headerH() - 1, display.width(), display.sepH());
display.drawCenteredHeader("ADD WAYPOINT");
const int top = display.listStart();
const int step = display.lineStep();
for (int i = 0; i < 4; i++) {
@@ -150,35 +149,25 @@ class WaypointsView {
char title[24];
snprintf(title, sizeof(title), "WAYPOINTS %d/%d",
_task->waypoints().count(), WaypointStore::CAPACITY);
display.drawTextCentered(display.width() / 2, 0, title);
display.fillRect(0, display.headerH() - 1, display.width(), display.sepH());
display.drawCenteredHeader(title);
int n = wpListCount();
int total = n + 1; // final row = "+ Add by coords"
const int top = display.listStart();
const int step = display.lineStep();
int vis = display.listVisible();
if (vis < 1) vis = 1;
if (_sel < _scroll) _scroll = _sel;
if (_sel >= _scroll + vis) _scroll = _sel - vis + 1;
int32_t mylat, mylon; bool have = ownPos(mylat, mylon);
int reserve = scrollIndicatorReserve(display, total, vis);
for (int i = 0; i < vis && (_scroll + i) < total; i++) {
int row = _scroll + i;
int y = top + i * step;
bool sel = (row == _sel);
drawList(display, total, _sel, _scroll, [&](int row, int y, bool sel, int reserve) {
display.drawSelectionRow(0, y - 1, display.width() - reserve, step - 1, sel);
if (row == n) { // the synthetic "Add" row
display.setCursor(2, y); display.print("+ Add by coords");
display.setColor(DisplayDriver::LIGHT);
continue;
return;
}
int32_t tlat, tlon; const char* label;
if (!rowTarget(row, tlat, tlon, label)) continue;
if (!rowTarget(row, tlat, tlon, label)) return;
char dist[12] = ""; int bw = 0;
if (have) {
geo::fmtDist(dist, sizeof(dist), geo::haversineKm(mylat, mylon, tlat, tlon), useImperial());
@@ -189,8 +178,7 @@ class WaypointsView {
display.drawTextEllipsized(2, y, display.width() - 2 - bw - reserve, nm);
if (dist[0]) { display.setCursor(display.width() - bw + 1 - reserve, y); display.print(dist); }
display.setColor(DisplayDriver::LIGHT);
}
drawScrollIndicator(display, top, vis * step, total, vis, _scroll);
});
}
void renderWpNav(DisplayDriver& display) {
@@ -322,8 +310,7 @@ public:
// Navigation view — any nav key returns to the list.
if (_mode == NAV) {
if (c == KEY_CANCEL || c == KEY_LEFT || c == KEY_PREV ||
c == KEY_RIGHT || c == KEY_NEXT) { _mode = LIST; }
if (c == KEY_CANCEL || keyIsPrev(c) || keyIsNext(c)) { _mode = LIST; }
return true;
}