mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-27 15:02:41 +00:00
proper centering and rounder hops labels
This commit is contained in:
parent
2ad52812c0
commit
cb3ce1b1a8
@ -13,6 +13,23 @@ void InkHUD::MapApplet::onRender()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper: draw rounded rectangle centered at x,y
|
||||||
|
auto fillRoundedRect = [&](int16_t cx, int16_t cy, int16_t w, int16_t h, int16_t r, uint16_t color) {
|
||||||
|
int16_t x = cx - (w / 2);
|
||||||
|
int16_t y = cy - (h / 2);
|
||||||
|
|
||||||
|
// center rects
|
||||||
|
fillRect(x + r, y, w - 2 * r, h, color);
|
||||||
|
fillRect(x, y + r, r, h - 2 * r, color);
|
||||||
|
fillRect(x + w - r, y + r, r, h - 2 * r, color);
|
||||||
|
|
||||||
|
// corners
|
||||||
|
fillCircle(x + r, y + r, r, color);
|
||||||
|
fillCircle(x + w - r - 1, y + r, r, color);
|
||||||
|
fillCircle(x + r, y + h - r - 1, r, color);
|
||||||
|
fillCircle(x + w - r - 1, y + h - r - 1, r, color);
|
||||||
|
};
|
||||||
|
|
||||||
// Find center of map
|
// Find center of map
|
||||||
getMapCenter(&latCenter, &lngCenter);
|
getMapCenter(&latCenter, &lngCenter);
|
||||||
calculateAllMarkers();
|
calculateAllMarkers();
|
||||||
@ -25,37 +42,32 @@ void InkHUD::MapApplet::onRender()
|
|||||||
int16_t y = Y(0.5) - (m.northMeters * metersToPx);
|
int16_t y = Y(0.5) - (m.northMeters * metersToPx);
|
||||||
|
|
||||||
// Add white halo outline first
|
// Add white halo outline first
|
||||||
constexpr int outlinePad = 1; // size of white outline padding
|
constexpr int outlinePad = 1;
|
||||||
int boxSize;
|
int boxSize = 11;
|
||||||
if ((m.hasHopsAway && m.hopsAway > config.lora.hop_limit) || !m.hasHopsAway) {
|
int radius = 2; // rounded corner radius
|
||||||
boxSize = 12;
|
|
||||||
} else {
|
// White halo background
|
||||||
boxSize = 10;
|
fillRoundedRect(x, y, boxSize + (outlinePad * 2), boxSize + (outlinePad * 2), radius + 1, WHITE);
|
||||||
}
|
|
||||||
fillRect(x - (boxSize / 2) - outlinePad, y - (boxSize / 2) - outlinePad, boxSize + (outlinePad * 2),
|
// Draw inner box
|
||||||
boxSize + (outlinePad * 2), WHITE);
|
fillRoundedRect(x, y, boxSize, boxSize, radius, BLACK);
|
||||||
|
|
||||||
|
// Text inside
|
||||||
|
setFont(fontSmall);
|
||||||
|
setTextColor(WHITE);
|
||||||
|
|
||||||
// Draw actual marker on top
|
// Draw actual marker on top
|
||||||
if (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) {
|
if (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) {
|
||||||
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
|
printAt(x + 1, y + 1, "X", CENTER, MIDDLE);
|
||||||
setFont(fontSmall);
|
|
||||||
setTextColor(WHITE);
|
|
||||||
printAt(x, y, "X", CENTER, MIDDLE);
|
|
||||||
} else if (!m.hasHopsAway) {
|
} else if (!m.hasHopsAway) {
|
||||||
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
|
printAt(x + 1, y + 1, "?", CENTER, MIDDLE);
|
||||||
setFont(fontSmall);
|
|
||||||
setTextColor(WHITE);
|
|
||||||
printAt(x, y, "?", CENTER, MIDDLE);
|
|
||||||
} else {
|
} else {
|
||||||
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
|
|
||||||
char hopStr[4];
|
char hopStr[4];
|
||||||
snprintf(hopStr, sizeof(hopStr), "%d", m.hopsAway);
|
snprintf(hopStr, sizeof(hopStr), "%d", m.hopsAway);
|
||||||
setFont(fontSmall);
|
printAt(x, y + 1, hopStr, CENTER, MIDDLE);
|
||||||
setTextColor(WHITE);
|
|
||||||
printAt(x, y, hopStr, CENTER, MIDDLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore default font and color (safety for rest of UI)
|
// Restore default font and color
|
||||||
setFont(fontSmall);
|
setFont(fontSmall);
|
||||||
setTextColor(BLACK);
|
setTextColor(BLACK);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user