mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-04 19:26:19 +00:00
feat(units): global metric/imperial setting for all distance displays
Add a single "Units" choice (Settings › System: Metric / Imperial) that governs every distance and speed shown in Tools — Nearby Nodes, the Trail views, and the navigate-to-point screen. - NodePrefs: units_imperial (global) + trail_show_pace (Trail readout mode), schema bumped 0xC0DE0005 → 0006. The old combined trail_units_idx is kept for file-layout stability but no longer drives anything; upgraders default to metric + speed. - geo::fmtDist gains an imperial mode (ft below ~1000 ft, then miles). - NavView / Nearby / Trail (waypoint list, Summary distance, List deltas, map scale-bar label) all format through the global preference. - Trail's action-menu "Units" row becomes a Speed/Pace readout toggle; the km-vs-mi unit now follows the global setting instead of being one of four combined options. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -42,11 +42,20 @@ static inline const char* bearingCardinal(int deg) {
|
||||
return dirs[((deg + 22) % 360) / 45];
|
||||
}
|
||||
|
||||
// Human distance string: "850m" / "2.3km" / "140km".
|
||||
static inline void fmtDist(char* buf, int n, float km) {
|
||||
if (km < 1.0f) snprintf(buf, n, "%dm", (int)(km * 1000 + 0.5f));
|
||||
else if (km < 100.0f) snprintf(buf, n, "%.1fkm", km);
|
||||
else snprintf(buf, n, "%dkm", (int)(km + 0.5f));
|
||||
// Human distance string. Metric: "850m" / "2.3km" / "140km". Imperial:
|
||||
// "850ft" / "2.3mi" / "140mi" (feet below ~1000 ft, then miles).
|
||||
static inline void fmtDist(char* buf, int n, float km, bool imperial) {
|
||||
if (imperial) {
|
||||
float ft = km * 3280.84f;
|
||||
if (ft < 1000.0f) { snprintf(buf, n, "%dft", (int)(ft + 0.5f)); return; }
|
||||
float mi = km * 0.621371f;
|
||||
if (mi < 100.0f) snprintf(buf, n, "%.1fmi", mi);
|
||||
else snprintf(buf, n, "%dmi", (int)(mi + 0.5f));
|
||||
} else {
|
||||
if (km < 1.0f) snprintf(buf, n, "%dm", (int)(km * 1000 + 0.5f));
|
||||
else if (km < 100.0f) snprintf(buf, n, "%.1fkm", km);
|
||||
else snprintf(buf, n, "%dkm", (int)(km + 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace geo
|
||||
|
||||
Reference in New Issue
Block a user