From 0c46cc5212c2c1e8b03eee3fdd76cea10a5886ed Mon Sep 17 00:00:00 2001 From: MarekZegare4 Date: Thu, 25 Jun 2026 12:02:32 +0200 Subject: [PATCH] fix(ui): show distance to active target on Home map status line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The MAP page status line only ever measured distance to the nearest live-tracked ([LOC]-sharing) contact, ignoring the active Locator/Nav target entirely. A waypoint target isn't a live-tracked contact at all, so after "Set as target" on a waypoint its flag drew fine on the mini-map but the status line below it never showed how far away it was. statusDistanceKm() (renamed from nearestTrackedKm()) now checks activeTargetPos() first — covers both waypoint and person targets — and only falls back to the nearest live-tracked contact when no target is set. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/ui-new/UITask.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 28ef3c88..f285cfe0 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -622,9 +622,10 @@ public: // Active target flag drawn last so it stays legible even atop a contact/own dot. if (have_tgt) { int px, py; project(tla, tlo, px, py); miniIconDrawCentered(display, px, py, ICON_MAP_TARGET); } - // Bottom-left scale reference, always shown — distance to the nearest - // live-tracked contact now lives on the status line below instead (see - // nearestTrackedKm() / render()), so this corner is free for it. + // Bottom-left scale reference, always shown — distance to the active + // target (or else the nearest live-tracked contact) now lives on the + // status line below instead (see statusDistanceKm() / render()), so this + // corner is free for it. { display.setColor(DisplayDriver::LIGHT); int ty = ay + ah - display.getLineHeight(); @@ -654,12 +655,17 @@ public: return true; } - // Distance to the nearest live-tracked ([LOC]-sharing) contact, in km, or - // -1 when we don't have a fix or there's no active share to measure - // against. Shared by the MAP status line (see render()). - float nearestTrackedKm() { + // Distance shown on the MAP status line. The active Locator/Nav target + // takes priority — that's what the flag on the mini-map is pointing at, + // and it's the only way a waypoint target ever gets a distance readout + // here (a waypoint isn't a live-tracked contact). Falls back to the + // nearest live-tracked ([LOC]-sharing) contact when no target is set. + // -1 when we don't have a fix or nothing to measure against. + float statusDistanceKm() { int32_t mla, mlo; if (!_task->currentLocation(mla, mlo)) return -1.0f; + int32_t tla, tlo; + if (_task->activeTargetPos(tla, tlo)) return geo::haversineKm(mla, mlo, tla, tlo); LiveTrackStore& lt = _task->liveTrack(); uint32_t now = rtc_clock.getCurrentTime(); float nearest_km = -1.0f; @@ -1084,10 +1090,10 @@ public: LiveTrackStore& lt = _task->liveTrack(); int trk = lt.active(now_m); // Fix state lives in the top-bar GPS icon. Track count plus an arrow + - // distance to the nearest live-tracked contact (when we have both a fix - // and an active share) share this one status line. + // distance (to the active target, else the nearest live-tracked + // contact) share this one status line. snprintf(left, sizeof(left), "Track:%d", trk); - float nearest_km = nearestTrackedKm(); + float nearest_km = statusDistanceKm(); if (nearest_km >= 0.0f) geo::fmtDist(right, sizeof(right), nearest_km, _task->useImperial()); display.setColor(DisplayDriver::LIGHT); if (!drew)