fix(nav/map): keep waypoint labels inside the map rect

The label was always drawn up-and-right of the marker (wx+4, wy-3) and was
dropped entirely if it would clip the right edge — so waypoints near the
top/bottom (and left) edges had their label spill off the map or vanish.
Add an edge-aware placement helper: prefer upper-right, flip to the left
when it would clip the right edge, and clamp vertically so edge/corner
waypoints keep a visible label. Used by both the normal and degenerate
single-point map paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-04 12:26:02 +02:00
parent daaa5b1503
commit 901c1dcd92

View File

@@ -691,10 +691,7 @@ private:
drawWaypointMarker(display, ccx, ccy);
const char* lbl = wp.at(0).label; // single coincident spot — label it
char s[3] = { lbl[0], lbl[0] ? lbl[1] : (char)0, 0 };
if (s[0] && ccx + 4 + (int)display.getTextWidth(s) <= area_x + area_w) {
display.setCursor(ccx + 4, ccy - 3);
display.print(s);
}
drawWaypointLabel(display, s, ccx, ccy, area_x, area_y, area_w, area_h);
}
if (have_gps || have_trail) drawCurrentMarker(display, ccx, ccy);
return;
@@ -756,10 +753,7 @@ private:
int wx, wy; projectLL(w.lat_1e6, w.lon_1e6, wx, wy);
drawWaypointMarker(display, wx, wy);
char s[3] = { w.label[0], w.label[0] ? w.label[1] : (char)0, 0 };
if (s[0] && wx + 4 + (int)display.getTextWidth(s) <= area_x + area_w) {
display.setCursor(wx + 4, wy - 3);
display.print(s);
}
drawWaypointLabel(display, s, wx, wy, area_x, area_y, area_w, area_h);
}
// Current position marker on top — live GPS if we have a fix, otherwise the
@@ -907,6 +901,25 @@ private:
display.print(lbl);
}
// Place a 12 char waypoint label beside its marker, kept inside the map
// rect: prefer upper-right, flip to the left if it would clip the right
// edge, and clamp vertically so edge/corner waypoints stay on the map.
static void drawWaypointLabel(DisplayDriver& d, const char* s, int wx, int wy,
int ax, int ay, int aw, int ah) {
if (!s[0]) return;
int tw = (int)d.getTextWidth(s);
int ch = d.getLineHeight();
int lx = wx + 4;
if (lx + tw > ax + aw) lx = wx - 4 - tw; // would clip right → flip left
if (lx < ax) lx = ax; // clamp to left edge
if (lx + tw > ax + aw) lx = ax + aw - tw; // clamp to right edge
int ly = wy - 3;
if (ly < ay) ly = ay; // clamp to top edge
if (ly + ch > ay + ah) ly = ay + ah - ch; // clamp to bottom edge
d.setCursor(lx, ly);
d.print(s);
}
static void drawFilledDot(DisplayDriver& d, int cx, int cy) {
d.fillRect(cx - 1, cy - 1, 3, 3);
}