-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathUIRenderer.cpp
More file actions
2355 lines (2075 loc) · 101 KB
/
Copy pathUIRenderer.cpp
File metadata and controls
2355 lines (2075 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "configuration.h"
#if HAS_SCREEN
#include "CompassRenderer.h"
#include "GPSStatus.h"
#include "MeshRadio.h"
#include "MeshService.h"
#include "NodeDB.h"
#include "NodeListRenderer.h"
#if !MESHTASTIC_EXCLUDE_STATUS
#include "modules/StatusMessageModule.h"
#endif
#if BASEUI_HAS_GAMES
#include "modules/games/GamesModule.h"
#endif
#include "UIRenderer.h"
#include "airtime.h"
#include "gps/GeoCoord.h"
#include "graphics/EmoteRenderer.h"
#include "graphics/SharedUIDisplay.h"
#include "graphics/TFTColorRegions.h"
#include "graphics/TFTPalette.h"
#include "graphics/TimeFormatters.h"
#include "graphics/images.h"
#include "main.h"
#include "target_specific.h"
#include <OLEDDisplay.h>
#include <cstring>
#include <gps/RTC.h>
// External variables
extern std::unique_ptr<graphics::Screen> screen;
#if defined(OLED_TINY)
static uint32_t lastSwitchTime = 0;
#endif
namespace graphics
{
NodeNum UIRenderer::currentFavoriteNodeNum = 0;
std::vector<meshtastic_NodeInfoLite *> graphics::UIRenderer::favoritedNodes;
static bool gBootSplashBoldPass = false;
struct StandardCompassNeedlePoints {
int16_t northTipX;
int16_t northTipY;
int16_t northLeftX;
int16_t northLeftY;
int16_t northRightX;
int16_t northRightY;
int16_t southTipX;
int16_t southTipY;
int16_t southLeftX;
int16_t southLeftY;
int16_t southRightX;
int16_t southRightY;
};
static inline void swapPoint(int16_t &ax, int16_t &ay, int16_t &bx, int16_t &by)
{
const int16_t tx = ax;
const int16_t ty = ay;
ax = bx;
ay = by;
bx = tx;
by = ty;
}
static inline void transformNeedlePoint(float localX, float localY, float sinHeading, float cosHeading, float scale,
int16_t centerX, int16_t centerY, int16_t &outX, int16_t &outY)
{
const float x = ((localX * cosHeading) - (localY * sinHeading)) * scale + centerX;
const float y = ((localX * sinHeading) + (localY * cosHeading)) * scale + centerY;
outX = static_cast<int16_t>(x);
outY = static_cast<int16_t>(y);
}
#if GRAPHICS_TFT_COLORING_ENABLED
static float getCompassRingAngleOffset(float heading)
{
return (uiconfig.compass_mode != meshtastic_CompassMode_FIXED_RING) ? -heading : 0.0f;
}
#endif
static inline StandardCompassNeedlePoints computeStandardCompassNeedlePoints(int16_t compassX, int16_t compassY,
uint16_t compassDiam, float headingRadian,
float centerGapPx)
{
// Standard-style symmetric needle with a narrow waist and a tiny center gap
// between north/south halves to prevent seam bleed while rotating.
const float scaledDiam = compassDiam * 0.76f;
const float gapNormHalf = (centerGapPx * 0.5f) / scaledDiam;
const float sinHeading = sinf(headingRadian);
const float cosHeading = cosf(headingRadian);
StandardCompassNeedlePoints points{};
transformNeedlePoint(0.0f, -0.5f, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.northTipX, points.northTipY);
transformNeedlePoint(-0.09f, -gapNormHalf, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.northLeftX,
points.northLeftY);
transformNeedlePoint(0.09f, -gapNormHalf, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.northRightX,
points.northRightY);
transformNeedlePoint(0.0f, 0.5f, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.southTipX, points.southTipY);
transformNeedlePoint(-0.09f, gapNormHalf, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.southLeftX,
points.southLeftY);
transformNeedlePoint(0.09f, gapNormHalf, sinHeading, cosHeading, scaledDiam, compassX, compassY, points.southRightX,
points.southRightY);
return points;
}
static inline void drawCompassNorthOnlyLabel(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius,
float heading)
{
int16_t labelRadius = compassRadius;
// CompassRenderer::drawCompassNorth() expands radius on high-res by +4.
// Compensate so label placement stays aligned with the current UI layout.
if (currentResolution == ScreenResolution::High && labelRadius > 4) {
labelRadius -= 4;
}
graphics::CompassRenderer::drawCompassNorth(display, compassX, compassY, heading, labelRadius);
}
static inline void drawMonoCompass(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius, float heading,
bool showRing = true)
{
const StandardCompassNeedlePoints points =
computeStandardCompassNeedlePoints(compassX, compassY, static_cast<uint16_t>(compassRadius * 2), -heading, 0.0f);
#ifdef USE_EINK
display->setColor(WHITE);
display->drawTriangle(points.northTipX, points.northTipY, points.northLeftX, points.northLeftY, points.northRightX,
points.northRightY);
display->drawTriangle(points.southTipX, points.southTipY, points.southLeftX, points.southLeftY, points.southRightX,
points.southRightY);
#else
// OLED variant: same needle geometry as TFT, but monochrome contrast.
display->setColor(WHITE);
display->fillTriangle(points.northTipX, points.northTipY, points.northLeftX, points.northLeftY, points.northRightX,
points.northRightY);
display->setColor(BLACK);
display->fillTriangle(points.southTipX, points.southTipY, points.southLeftX, points.southLeftY, points.southRightX,
points.southRightY);
// Keep a white outline so the black half remains visible on dark backgrounds.
display->setColor(WHITE);
display->drawTriangle(points.southTipX, points.southTipY, points.southLeftX, points.southLeftY, points.southRightX,
points.southRightY);
#endif
if (showRing)
display->drawCircle(compassX, compassY, compassRadius);
drawCompassNorthOnlyLabel(display, compassX, compassY, compassRadius, heading);
}
#if GRAPHICS_TFT_COLORING_ENABLED
struct NeedleColorBand {
int16_t xMin;
int16_t xMax;
int16_t yMin;
int16_t yMax;
bool used;
};
static constexpr int kNeedleBandCount = 6;
static inline void registerNeedleSpan(NeedleColorBand (&bands)[kNeedleBandCount], int16_t bandTop, int16_t bandHeight, int16_t y,
int16_t a, int16_t b)
{
if (a > b) {
const int16_t t = a;
a = b;
b = t;
}
int band = (static_cast<int32_t>(y - bandTop) * kNeedleBandCount) / bandHeight;
if (band < 0) {
band = 0;
} else if (band >= kNeedleBandCount) {
band = kNeedleBandCount - 1;
}
NeedleColorBand ®ion = bands[band];
if (!region.used) {
region.used = true;
region.xMin = a;
region.xMax = b;
region.yMin = y;
region.yMax = y;
return;
}
if (a < region.xMin)
region.xMin = a;
if (b > region.xMax)
region.xMax = b;
if (y < region.yMin)
region.yMin = y;
if (y > region.yMax)
region.yMax = y;
}
static void drawNeedleHalfAndRegisterBands(OLEDDisplay *display, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
int16_t y2, uint16_t onColor, uint16_t offColor)
{
// Important for maintainers:
// The compass needle rotates continuously, so color-region registration must
// track triangle shape (or a close approximation), not only one AABB.
// Coarse rectangles can leak south color into north at diagonal angles.
// Keep this banded approach unless a replacement preserves per-angle coverage.
// Performance note: draw the triangle once via fillTriangle(), then build
// band regions in software for accurate color-role registration.
display->fillTriangle(x0, y0, x1, y1, x2, y2);
if (y0 > y1)
swapPoint(x0, y0, x1, y1);
if (y1 > y2)
swapPoint(x1, y1, x2, y2);
if (y0 > y1)
swapPoint(x0, y0, x1, y1);
NeedleColorBand bands[kNeedleBandCount] = {};
const int16_t bandTop = y0;
const int16_t bandBottom = y2;
const int16_t bandHeight = (bandBottom >= bandTop) ? static_cast<int16_t>(bandBottom - bandTop + 1) : 1;
const int32_t dx01 = x1 - x0;
const int32_t dy01 = y1 - y0;
const int32_t dx02 = x2 - x0;
const int32_t dy02 = y2 - y0;
const int32_t dx12 = x2 - x1;
const int32_t dy12 = y2 - y1;
int32_t sa = 0;
int32_t sb = 0;
int16_t y = y0;
const int16_t last = (y1 == y2) ? y1 : static_cast<int16_t>(y1 - 1);
for (; y <= last; y++) {
const int16_t a = static_cast<int16_t>(x0 + ((dy01 != 0) ? (sa / dy01) : 0));
const int16_t b = static_cast<int16_t>(x0 + ((dy02 != 0) ? (sb / dy02) : 0));
sa += dx01;
sb += dx02;
registerNeedleSpan(bands, bandTop, bandHeight, y, a, b);
}
sa = dx12 * static_cast<int32_t>(y - y1);
sb = dx02 * static_cast<int32_t>(y - y0);
for (; y <= y2; y++) {
const int16_t a = static_cast<int16_t>(x1 + ((dy12 != 0) ? (sa / dy12) : 0));
const int16_t b = static_cast<int16_t>(x0 + ((dy02 != 0) ? (sb / dy02) : 0));
sa += dx12;
sb += dx02;
registerNeedleSpan(bands, bandTop, bandHeight, y, a, b);
}
for (int i = 0; i < kNeedleBandCount; i++) {
if (!bands[i].used)
continue;
registerTFTColorRegionDirect(bands[i].xMin, bands[i].yMin, bands[i].xMax - bands[i].xMin + 1,
bands[i].yMax - bands[i].yMin + 1, onColor, offColor);
}
}
static inline void drawCompassCardinalLabel(OLEDDisplay *display, int16_t x, int16_t y, const char *label, int16_t textWidth)
{
const int16_t labelTop = y - (FONT_HEIGHT_SMALL / 2);
const int16_t padX = 1;
const int16_t padY = 1;
// Clear any ring/tick pixels behind the label so letters remain clean.
display->setColor(BLACK);
display->fillRect(x - (textWidth / 2) - padX, labelTop - padY, textWidth + (padX * 2), FONT_HEIGHT_SMALL + (padY * 2));
display->setColor(WHITE);
display->drawString(x, labelTop, label);
}
static inline void drawCompassCardinalLabels(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius,
float heading)
{
const float northAngle = getCompassRingAngleOffset(heading);
const float radius = compassRadius - 1.0f;
const float sinNorth = sinf(northAngle);
const float cosNorth = cosf(northAngle);
const int16_t nX = compassX + static_cast<int16_t>(radius * sinNorth);
const int16_t nY = compassY - static_cast<int16_t>(radius * cosNorth);
const int16_t eX = compassX + static_cast<int16_t>(radius * cosNorth);
const int16_t eY = compassY + static_cast<int16_t>(radius * sinNorth);
const int16_t sX = compassX - static_cast<int16_t>(radius * sinNorth);
const int16_t sY = compassY + static_cast<int16_t>(radius * cosNorth);
const int16_t wX = compassX - static_cast<int16_t>(radius * cosNorth);
const int16_t wY = compassY - static_cast<int16_t>(radius * sinNorth);
display->setFont(FONT_SMALL);
display->setTextAlignment(TEXT_ALIGN_CENTER);
const int16_t labelWidth = static_cast<int16_t>(display->getStringWidth("N"));
drawCompassCardinalLabel(display, nX, nY, "N", labelWidth);
drawCompassCardinalLabel(display, eX, eY, "E", labelWidth);
drawCompassCardinalLabel(display, sX, sY, "S", labelWidth);
drawCompassCardinalLabel(display, wX, wY, "W", labelWidth);
}
static inline void drawCompassDegreeMarkers(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius,
float heading)
{
const float baseAngle = getCompassRingAngleOffset(heading);
constexpr int16_t majorLen = 5;
constexpr int16_t minorLen = 3;
display->setColor(WHITE);
constexpr float kStepAngle = 15.0f * DEG_TO_RAD;
const float sinStep = sinf(kStepAngle);
const float cosStep = cosf(kStepAngle);
float sinAngle = sinf(baseAngle);
float cosAngle = cosf(baseAngle);
bool isMajor = true;
for (int tick = 0; tick < 24; tick++) {
const int16_t tickLen = isMajor ? majorLen : minorLen;
const int16_t xOuter = compassX + static_cast<int16_t>((compassRadius - 1) * sinAngle);
const int16_t yOuter = compassY - static_cast<int16_t>((compassRadius - 1) * cosAngle);
const int16_t xInner = compassX + static_cast<int16_t>((compassRadius - tickLen) * sinAngle);
const int16_t yInner = compassY - static_cast<int16_t>((compassRadius - tickLen) * cosAngle);
display->drawLine(xInner, yInner, xOuter, yOuter);
// Rotate [sin, cos] by a fixed step instead of recomputing trig 24x/frame.
const float nextSin = (sinAngle * cosStep) + (cosAngle * sinStep);
const float nextCos = (cosAngle * cosStep) - (sinAngle * sinStep);
sinAngle = nextSin;
cosAngle = nextCos;
isMajor = !isMajor;
}
}
static inline void drawStandardCompassNeedle(OLEDDisplay *display, int16_t compassX, int16_t compassY, uint16_t compassDiam,
float headingRadian, uint16_t needleOffColor)
{
const StandardCompassNeedlePoints points =
computeStandardCompassNeedlePoints(compassX, compassY, compassDiam, headingRadian, 9.0f);
display->setColor(WHITE);
#ifdef USE_EINK
display->drawTriangle(points.northTipX, points.northTipY, points.northLeftX, points.northLeftY, points.northRightX,
points.northRightY);
display->drawTriangle(points.southTipX, points.southTipY, points.southLeftX, points.southLeftY, points.southRightX,
points.southRightY);
#else
// NOTE: do not collapse these to one region per half during "flash
// optimization". The needle spins, and coarse rectangles will bleed color
// across halves at diagonal angles.
drawNeedleHalfAndRegisterBands(display, points.northTipX, points.northTipY, points.northLeftX, points.northLeftY,
points.northRightX, points.northRightY, TFTPalette::Red, needleOffColor);
drawNeedleHalfAndRegisterBands(display, points.southTipX, points.southTipY, points.southLeftX, points.southLeftY,
points.southRightX, points.southRightY, TFTPalette::Blue, needleOffColor);
#endif
}
static inline void drawTftCompass(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius, float heading,
bool showRing = true)
{
// Compass colors should follow whatever background role is already active at this location.
const uint16_t compassBgColor = resolveTFTOffColorAt(compassX, compassY, getThemeBodyBg());
const uint16_t compassGlyphColor = TFTPalette::pickReadableMonoFg(compassBgColor);
const int16_t pad = 2;
const int16_t labelPadX = static_cast<int16_t>(display->getStringWidth("W") / 2) + 2;
const int16_t labelPadY = static_cast<int16_t>(FONT_HEIGHT_SMALL / 2) + 2;
const int16_t boxX = compassX - compassRadius - pad - labelPadX;
const int16_t boxY = compassY - compassRadius - pad - labelPadY;
const int16_t boxW = (compassRadius * 2) + (pad * 2) + 1 + (labelPadX * 2);
const int16_t boxH = (compassRadius * 2) + (pad * 2) + 1 + (labelPadY * 2);
// Never let compass-local tint regions override the header role regions.
const int16_t bodyTop = static_cast<int16_t>(getTextPositions(display)[1]);
int16_t clippedY = boxY;
int16_t clippedH = boxH;
if (clippedY < bodyTop) {
clippedH = static_cast<int16_t>(clippedH - (bodyTop - clippedY));
clippedY = bodyTop;
}
if (clippedH > 0) {
registerTFTColorRegionDirect(boxX, clippedY, boxW, clippedH, compassGlyphColor, compassBgColor);
}
drawStandardCompassNeedle(display, compassX, compassY, static_cast<uint16_t>(compassRadius * 2), -heading, compassBgColor);
if (showRing)
display->drawCircle(compassX, compassY, compassRadius);
drawCompassDegreeMarkers(display, compassX, compassY, compassRadius, heading);
drawCompassCardinalLabels(display, compassX, compassY, compassRadius, heading);
}
#endif // GRAPHICS_TFT_COLORING_ENABLED
static void drawCompassStatusText(OLEDDisplay *display, int16_t compassX, int16_t compassY, const char *statusLine1,
const char *statusLine2)
{
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(compassX, compassY - FONT_HEIGHT_SMALL, statusLine1);
display->drawString(compassX, compassY, statusLine2);
display->setTextAlignment(TEXT_ALIGN_LEFT);
}
static void drawBearingCompassOrStatus(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius,
bool showCompass, float myHeading, float bearing, const char *statusLine1,
const char *statusLine2, bool showRing = true)
{
// Shared "favorite node" compass renderer: draw ring, then either heading data or fallback status text.
if (showRing)
display->drawCircle(compassX, compassY, compassRadius);
if (showCompass) {
CompassRenderer::drawCompassNorth(display, compassX, compassY, myHeading, compassRadius);
CompassRenderer::drawNodeHeading(display, compassX, compassY, compassRadius * 2, bearing);
} else {
drawCompassStatusText(display, compassX, compassY, statusLine1, statusLine2);
}
}
static void drawDetailedCompassOrStatus(OLEDDisplay *display, int16_t compassX, int16_t compassY, int16_t compassRadius,
bool validHeading, float heading, const char *statusLine1, const char *statusLine2,
bool showRing = true)
{
// Shared "position screen" compass renderer: use mono/TFT path only when heading is valid.
if (validHeading) {
#if GRAPHICS_TFT_COLORING_ENABLED
drawTftCompass(display, compassX, compassY, compassRadius, heading, showRing);
#else
drawMonoCompass(display, compassX, compassY, compassRadius, heading, showRing);
#endif
} else {
if (showRing)
display->drawCircle(compassX, compassY, compassRadius);
drawCompassStatusText(display, compassX, compassY, statusLine1, statusLine2);
}
}
static bool computeLandscapeCompassPlacement(OLEDDisplay *display, int16_t xOffset, int16_t topY, int16_t *compassX,
int16_t *compassY, int16_t *compassRadius)
{
// Keep compass vertically centered in the body area while reserving footer/nav space.
const int16_t bottomY = SCREEN_HEIGHT - (FONT_HEIGHT_SMALL - 1);
const int16_t usableHeight = bottomY - topY - 5;
int16_t radius = usableHeight / 2;
if (radius < 8) {
radius = 8;
}
*compassRadius = radius;
*compassX = xOffset + SCREEN_WIDTH - radius - 8;
*compassY = topY + (usableHeight / 2) + ((FONT_HEIGHT_SMALL - 1) / 2) + 2;
return true;
}
static bool computeBottomCompassPlacement(OLEDDisplay *display, int16_t xOffset, int16_t yBelowContent, int16_t bottomReserved,
int16_t margin, int16_t *compassX, int16_t *compassY, int16_t *compassRadius)
{
// Return false when content leaves no room for a readable compass.
int availableHeight = SCREEN_HEIGHT - yBelowContent - bottomReserved - margin;
if (availableHeight < FONT_HEIGHT_SMALL * 2) {
return false;
}
int16_t radius = static_cast<int16_t>(availableHeight / 2);
if (radius < 8) {
radius = 8;
}
if (radius * 2 > SCREEN_WIDTH - 16) {
radius = (SCREEN_WIDTH - 16) / 2;
}
*compassRadius = radius;
*compassX = xOffset + (SCREEN_WIDTH / 2);
*compassY = static_cast<int16_t>(yBelowContent + (availableHeight / 2));
return true;
}
static void drawTruncatedStatusLine(OLEDDisplay *display, int16_t x, int16_t y, const char *statusText)
{
// Fixed-buffer truncate helper replaces iterative std::string chopping to keep code size down.
char rawStatus[96];
snprintf(rawStatus, sizeof(rawStatus), " Status: %s", statusText ? statusText : "");
char clippedStatus[96];
UIRenderer::truncateStringWithEmotes(display, rawStatus, clippedStatus, sizeof(clippedStatus), display->getWidth());
display->drawString(x, y, clippedStatus);
}
static int computeChannelUtilizationFill(int percent, int maxFill)
{
// Compact linear fill mapping for the utilization bar.
if (percent <= 0 || maxFill <= 0) {
return 0;
}
if (percent >= 100) {
return maxFill;
}
return (maxFill * percent + 50) / 100;
}
void graphics::UIRenderer::rebuildFavoritedNodes()
{
favoritedNodes.clear();
size_t total = nodeDB->getNumMeshNodes();
for (size_t i = 0; i < total; i++) {
meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(i);
if (!n || n->num == nodeDB->getNodeNum())
continue;
if (nodeInfoLiteIsFavorite(n))
favoritedNodes.push_back(n);
}
std::sort(favoritedNodes.begin(), favoritedNodes.end(),
[](const meshtastic_NodeInfoLite *a, const meshtastic_NodeInfoLite *b) { return a->num < b->num; });
}
#if !MESHTASTIC_EXCLUDE_GPS
// GeoCoord object for coordinate conversions
extern GeoCoord geoCoord;
// Threshold values for the GPS lock accuracy bar display
extern uint32_t dopThresholds[5];
// Draw GPS status summary (satellite icon + status text).
// Handles all GPS states: disabled / not present / fixed position / no lock / sat count.
void UIRenderer::drawGps(OLEDDisplay *display, int16_t x, int16_t y, const meshtastic::GPSStatus *gps, bool center)
{
char textString[12];
if (config.position.fixed_position) {
// Fixed position overrides live GPS state, regardless of gps_mode
snprintf(textString, sizeof(textString), "Fixed GPS");
} else if (config.position.gps_mode == meshtastic_Config_PositionConfig_GpsMode_NOT_PRESENT) {
snprintf(textString, sizeof(textString), "No GPS");
} else if (config.position.gps_mode != meshtastic_Config_PositionConfig_GpsMode_ENABLED) {
snprintf(textString, sizeof(textString), "GPS off");
} else if (!gps || !gps->getIsConnected()) {
snprintf(textString, sizeof(textString), "No Lock");
} else if (!gps->getHasLock()) {
snprintf(textString, sizeof(textString), "No Sats");
} else {
snprintf(textString, sizeof(textString), "%u sats", gps->getNumSatellites());
}
const int textOffset = (currentResolution == ScreenResolution::High) ? 18 : 11;
if (center) {
int contentWidth = textOffset + display->getStringWidth(textString);
x = (SCREEN_WIDTH - contentWidth) / 2;
}
// Draw satellite image
if (currentResolution == ScreenResolution::High) {
NodeListRenderer::drawScaledXBitmap16x16(x, y - 2, imgGPS_width, imgGPS_height, imgGPS, display);
} else {
display->drawXbm(x + 1, y + 1, imgGPS_width, imgGPS_height, imgGPS);
}
display->drawString(x + textOffset, y, textString);
}
void UIRenderer::drawGpsAltitude(OLEDDisplay *display, int16_t x, int16_t y, const meshtastic::GPSStatus *gps)
{
char displayLine[32];
if (!gps->getIsConnected() && !config.position.fixed_position) {
// displayLine = "No GPS Module";
// display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine);
} else if (!gps->getHasLock() && !config.position.fixed_position) {
// displayLine = "No GPS Lock";
// display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine);
} else {
geoCoord.updateCoords(int32_t(gps->getLatitude()), int32_t(gps->getLongitude()), int32_t(gps->getAltitude()));
if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL)
snprintf(displayLine, sizeof(displayLine), "Altitude: %.0fft", geoCoord.getAltitude() * METERS_TO_FEET);
else
snprintf(displayLine, sizeof(displayLine), "Altitude: %.0im", geoCoord.getAltitude());
display->drawString(x + (display->getWidth() - (display->getStringWidth(displayLine))) / 2, y, displayLine);
}
}
// Draw GPS status coordinates
void UIRenderer::drawGpsCoordinates(OLEDDisplay *display, int16_t x, int16_t y, const meshtastic::GPSStatus *gps,
const char *mode)
{
auto gpsFormat = uiconfig.gps_format;
char displayLine[32];
if (!gps->getIsConnected() && !config.position.fixed_position) {
if (strcmp(mode, "line1") == 0) {
strcpy(displayLine, "No GPS present");
display->drawString(x, y, displayLine);
}
} else if (!gps->getHasLock() && !config.position.fixed_position) {
if (strcmp(mode, "line1") == 0) {
strcpy(displayLine, gps->getHasTime() ? "GPS Time Only" : "No GPS Lock");
display->drawString(x, y, displayLine);
}
} else {
geoCoord.updateCoords(int32_t(gps->getLatitude()), int32_t(gps->getLongitude()), int32_t(gps->getAltitude()));
if (gpsFormat != meshtastic_DeviceUIConfig_GpsCoordinateFormat_DMS) {
char coordinateLine_1[22];
char coordinateLine_2[22];
if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_DEC) { // Decimal Degrees
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "Lat: %f", geoCoord.getLatitude() * 1e-7);
snprintf(coordinateLine_2, sizeof(coordinateLine_2), "Lon: %f", geoCoord.getLongitude() * 1e-7);
} else if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_UTM) { // Universal Transverse Mercator
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "%2i%1c %06u E", geoCoord.getUTMZone(),
geoCoord.getUTMBand(), geoCoord.getUTMEasting());
snprintf(coordinateLine_2, sizeof(coordinateLine_2), "%07u N", geoCoord.getUTMNorthing());
} else if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_MGRS) { // Military Grid Reference System
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "%2i%1c %1c%1c", geoCoord.getMGRSZone(),
geoCoord.getMGRSBand(), geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k());
snprintf(coordinateLine_2, sizeof(coordinateLine_2), "%05u E %05u N", geoCoord.getMGRSEasting(),
geoCoord.getMGRSNorthing());
} else if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_OLC) { // Open Location Code
geoCoord.getOLCCode(coordinateLine_1);
coordinateLine_2[0] = '\0';
} else if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_OSGR) { // Ordnance Survey Grid Reference
if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') { // OSGR is only valid around the UK region
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "%s", "Out of Boundary");
coordinateLine_2[0] = '\0';
} else {
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "%1c%1c", geoCoord.getOSGRE100k(),
geoCoord.getOSGRN100k());
snprintf(coordinateLine_2, sizeof(coordinateLine_2), "%05u E %05u N", geoCoord.getOSGREasting(),
geoCoord.getOSGRNorthing());
}
} else if (gpsFormat == meshtastic_DeviceUIConfig_GpsCoordinateFormat_MLS) { // Maidenhead Locator System
double lat = geoCoord.getLatitude() * 1e-7;
double lon = geoCoord.getLongitude() * 1e-7;
// Normalize
if (lat > 90.0)
lat = 90.0;
if (lat < -90.0)
lat = -90.0;
while (lon < -180.0)
lon += 360.0;
while (lon >= 180.0)
lon -= 360.0;
double adjLon = lon + 180.0;
double adjLat = lat + 90.0;
char maiden[10]; // enough for 8-char + null
// Field (2 letters)
int lonField = int(adjLon / 20.0);
int latField = int(adjLat / 10.0);
adjLon -= lonField * 20.0;
adjLat -= latField * 10.0;
// Square (2 digits)
int lonSquare = int(adjLon / 2.0);
int latSquare = int(adjLat / 1.0);
adjLon -= lonSquare * 2.0;
adjLat -= latSquare * 1.0;
// Subsquare (2 letters)
double lonUnit = 2.0 / 24.0;
double latUnit = 1.0 / 24.0;
int lonSub = int(adjLon / lonUnit);
int latSub = int(adjLat / latUnit);
snprintf(maiden, sizeof(maiden), "%c%c%c%c%c%c", 'A' + lonField, 'A' + latField, '0' + lonSquare, '0' + latSquare,
'A' + lonSub, 'A' + latSub);
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "MH: %s", maiden);
coordinateLine_2[0] = '\0'; // only need one line
}
if (strcmp(mode, "line1") == 0) {
display->drawString(x, y, coordinateLine_1);
} else if (strcmp(mode, "line2") == 0) {
display->drawString(x, y, coordinateLine_2);
} else if (strcmp(mode, "combined") == 0) {
display->drawString(x, y, coordinateLine_1);
if (coordinateLine_2[0] != '\0') {
display->drawString(x + display->getStringWidth(coordinateLine_1), y, coordinateLine_2);
}
}
} else {
char coordinateLine_1[22];
char coordinateLine_2[22];
snprintf(coordinateLine_1, sizeof(coordinateLine_1), "Lat: %2i° %2i' %2u\" %1c", geoCoord.getDMSLatDeg(),
geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(), geoCoord.getDMSLatCP());
snprintf(coordinateLine_2, sizeof(coordinateLine_2), "Lon: %3i° %2i' %2u\" %1c", geoCoord.getDMSLonDeg(),
geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(), geoCoord.getDMSLonCP());
if (strcmp(mode, "line1") == 0) {
display->drawString(x, y, coordinateLine_1);
} else if (strcmp(mode, "line2") == 0) {
display->drawString(x, y, coordinateLine_2);
} else { // both
display->drawString(x, y, coordinateLine_1);
display->drawString(x, y + 10, coordinateLine_2);
}
}
}
}
#endif // !MESHTASTIC_EXCLUDE_GPS
// Draw nodes status
void UIRenderer::drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const meshtastic::NodeStatus *nodeStatus, int node_offset,
bool show_total, const char *additional_words, bool center)
{
char usersString[20];
int nodes_online = (nodeStatus->getNumOnline() > 0) ? nodeStatus->getNumOnline() + node_offset : 0;
snprintf(usersString, sizeof(usersString), "%d %s", nodes_online, additional_words);
if (show_total) {
int nodes_total = (nodeStatus->getNumTotal() > 0) ? nodeStatus->getNumTotal() + node_offset : 0;
snprintf(usersString, sizeof(usersString), "%d/%d %s", nodes_online, nodes_total, additional_words);
}
int string_offset = (currentResolution == ScreenResolution::High) ? 9 : 0;
if (center) {
int contentWidth = 10 + string_offset + display->getStringWidth(usersString);
x = (SCREEN_WIDTH - contentWidth) / 2;
}
#if (defined(USE_EINK) || defined(HAS_SPI_TFT)) && !defined(DISPLAY_FORCE_SMALL_FONTS)
if (currentResolution == ScreenResolution::High) {
NodeListRenderer::drawScaledXBitmap16x16(x, y - 1, 8, 8, imgUser, display);
} else {
display->drawFastImage(x, y + 3, 8, 8, imgUser);
}
#else
if (currentResolution == ScreenResolution::High) {
NodeListRenderer::drawScaledXBitmap16x16(x, y - 1, 8, 8, imgUser, display);
} else {
display->drawFastImage(x, y + 1, 8, 8, imgUser);
}
#endif
display->drawString(x + 10 + string_offset, y - 2, usersString);
}
// **********************
// * Favorite Node Info *
// **********************
// Compact panels: toggle between the compass/distance view and the status/telemetry view.
static int favoriteViewIndex = 0;
void UIRenderer::scrollFavoriteDown()
{
favoriteViewIndex = (favoriteViewIndex + 1) % 2;
}
void UIRenderer::scrollFavoriteUp()
{
if (favoriteViewIndex > 0)
favoriteViewIndex--;
}
// cppcheck-suppress constParameterPointer; signature must match FrameCallback typedef from OLEDDisplayUi library
void UIRenderer::drawFavoriteNode(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
if (favoritedNodes.empty())
return;
// --- Only display if index is valid ---
int nodeIndex = state->currentFrame - (screen->frameCount - favoritedNodes.size());
if (nodeIndex < 0 || nodeIndex >= (int)favoritedNodes.size())
return;
meshtastic_NodeInfoLite *node = favoritedNodes[nodeIndex];
if (!node || node->num == nodeDB->getNodeNum() || !nodeInfoLiteIsFavorite(node))
return;
display->clear();
#if defined(OLED_TINY)
uint32_t now = millis();
if (now - lastSwitchTime >= 10000) // 10000 ms = 10 秒
{
display->display();
lastSwitchTime = now;
}
#endif
currentFavoriteNodeNum = node->num;
// === Create the shortName and title string ===
const char *shortName = (nodeInfoLiteHasUser(node) && node->short_name[0]) ? node->short_name : "Node";
char titlestr[40];
snprintf(titlestr, sizeof(titlestr), "*%s*", shortName);
// === Draw battery/time/mail header (common across screens) ===
graphics::drawCommonHeader(display, x, y, titlestr, false, false, false, true, TFTPalette::Yellow);
#if HAS_GPS && defined(OLED_COMPACT_UI)
// Compact panels: page 0 = name/distance/compass, page 1 = status/telemetry (scroll down)
if (graphics::isCompactPanel(display)) {
int cline = 1;
const meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
meshtastic_PositionLite nodePos, ourPos;
const bool haveNodePos = nodeDB->copyNodePosition(node->num, nodePos);
const bool haveOurPos = ourNode && nodeDB->copyNodePosition(ourNode->num, ourPos);
const bool hasOwnPositionFix = (ourNode && nodeDB->hasValidPosition(ourNode));
const bool hasNodePositionFix = nodeDB->hasValidPosition(node);
const bool hasFix = hasOwnPositionFix && hasNodePositionFix && haveOurPos && haveNodePos;
if (favoriteViewIndex == 0) {
// --- Long name (falls back to short) ---
const char *rawName = (nodeInfoLiteHasUser(node) && node->long_name[0]) ? node->long_name : shortName;
char nodeName[40];
UIRenderer::truncateStringWithEmotes(display, rawName, nodeName, sizeof(nodeName), SCREEN_WIDTH - 4);
UIRenderer::drawStringWithEmotes(display, 2, getTextPositions(display)[cline++], nodeName, FONT_HEIGHT_SMALL, 1,
false);
// --- Compass (bearing to node), right-aligned ---
bool showCompass = false;
float myHeading = 0.0f, bearing = 0.0f;
const char *statusLine1 = nullptr;
const char *statusLine2 = nullptr;
if (hasFix) {
showCompass = CompassRenderer::getHeadingRadians(DegD(ourPos.latitude_i), DegD(ourPos.longitude_i), myHeading);
if (showCompass) {
bearing = GeoCoord::bearing(DegD(ourPos.latitude_i), DegD(ourPos.longitude_i), DegD(nodePos.latitude_i),
DegD(nodePos.longitude_i));
bearing = CompassRenderer::adjustBearingForCompassMode(bearing, myHeading);
} else {
statusLine1 = "No";
statusLine2 = "Heading";
}
} else {
statusLine1 = "No";
statusLine2 = "Fix";
}
const int compassTop = getTextPositions(display)[cline];
int availableHeight = SCREEN_HEIGHT - compassTop - 1;
const int maxCompassDiameter = (SCREEN_WIDTH / 2 - 4 < availableHeight) ? (SCREEN_WIDTH / 2 - 4) : availableHeight;
int compassRadius = maxCompassDiameter / 2;
if (compassRadius < 8)
compassRadius = 8;
const int compassX = SCREEN_WIDTH - compassRadius - 4;
const int compassY = compassTop + availableHeight / 2;
drawBearingCompassOrStatus(display, compassX, compassY, compassRadius, showCompass, myHeading, bearing, statusLine1,
statusLine2, /*showRing=*/false);
// --- Distance, directly under the name, left side only, shown when a fix is available ---
if (hasFix) {
char distStr[16];
const float distanceMeters = GeoCoord::latLongToMeter(DegD(nodePos.latitude_i), DegD(nodePos.longitude_i),
DegD(ourPos.latitude_i), DegD(ourPos.longitude_i));
if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL) {
const int feet = static_cast<int>((distanceMeters * METERS_TO_FEET) + 0.5f);
if (feet < 1000)
snprintf(distStr, sizeof(distStr), "%dft", feet);
else
snprintf(distStr, sizeof(distStr), "%dmi", (feet + 2640) / 5280);
} else {
const int meters = static_cast<int>(distanceMeters + 0.5f);
if (meters < 1000)
snprintf(distStr, sizeof(distStr), "%dm", meters);
else
snprintf(distStr, sizeof(distStr), "%dkm", (meters + 500) / 1000);
}
display->drawString(2, getTextPositions(display)[cline++], distStr);
}
// --- Last heard, directly under distance ---
uint32_t seenSeconds = sinceLastSeen(node);
if (seenSeconds != 0 && seenSeconds != UINT32_MAX) {
uint32_t minutes = seenSeconds / 60, hours = minutes / 60, days = hours / 24;
char seenStr[16];
snprintf(seenStr, sizeof(seenStr), (days > 365 ? "?" : "%d%c"),
(days ? days
: hours ? hours
: minutes),
(days ? 'd'
: hours ? 'h'
: 'm'));
display->drawString(2, getTextPositions(display)[cline++], seenStr);
}
} else {
// --- Page 1: status, signal/hops, heard, uptime, battery ---
meshtastic_StatusMessage cachedStatus;
if (nodeDB && nodeDB->copyNodeStatus(node->num, cachedStatus) && cachedStatus.status[0]) {
drawTruncatedStatusLine(display, x, getTextPositions(display)[cline++], cachedStatus.status);
}
const bool isZeroHop = node->has_hops_away && node->hops_away == 0;
const bool showHops = node->has_hops_away && node->hops_away > 0;
if (isZeroHop && node->snr > -100 && node->snr != 0) {
char sigStr[16];
snprintf(sigStr, sizeof(sigStr), "SNR:%.1f", node->snr);
display->drawString(x, getTextPositions(display)[cline++], sigStr);
} else if (showHops) {
char hopStr[16];
snprintf(hopStr, sizeof(hopStr), "Hops:%d", node->hops_away);
display->drawString(x, getTextPositions(display)[cline++], hopStr);
}
uint32_t seconds = sinceLastSeen(node);
if (seconds != 0 && seconds != UINT32_MAX) {
uint32_t minutes = seconds / 60, hours = minutes / 60, days = hours / 24;
char seenStr[20];
snprintf(seenStr, sizeof(seenStr), (days > 365 ? "Heard:?" : "Heard:%d%c ago"),
(days ? days
: hours ? hours
: minutes),
(days ? 'd'
: hours ? 'h'
: 'm'));
display->drawString(x, getTextPositions(display)[cline++], seenStr);
}
meshtastic_DeviceMetrics nodeMetrics;
if (nodeDB->copyNodeTelemetry(node->num, nodeMetrics)) {
if (nodeMetrics.has_uptime_seconds) {
char uptimeStr[24];
getUptimeStr(nodeMetrics.uptime_seconds * 1000, "Up:", uptimeStr, sizeof(uptimeStr));
display->drawString(x, getTextPositions(display)[cline++], uptimeStr);
}
if (nodeMetrics.has_battery_level) {
char batStr[24];
int pct = (int)nodeMetrics.battery_level;
if (pct > 100) {
snprintf(batStr, sizeof(batStr), "Plugged In");
} else {
snprintf(batStr, sizeof(batStr), "Bat:%d%%", pct);
}
display->drawString(x, getTextPositions(display)[cline++], batStr);
}
}
}
// Two-page indicator, matching the position screen's scrollbar thumb style.
const int scrollbarX = SCREEN_WIDTH - 2;
const int thumbHeight = SCREEN_HEIGHT / 2;
const int thumbY = favoriteViewIndex * (SCREEN_HEIGHT - thumbHeight);
for (int i = 0; i < thumbHeight; i++) {
display->setPixel(scrollbarX, thumbY + i);
}
graphics::drawCommonFooter(display, x, y);
return;
}
#endif
// ===== DYNAMIC ROW STACKING WITH YOUR MACROS =====
// 1. Each potential info row has a macro-defined Y position (not regular increments!).
// 2. Each row is only shown if it has valid data.
// 3. Each row "moves up" if previous are empty, so there are never any blank rows.
// 4. The first line is ALWAYS at your macro position; subsequent lines use the next available macro slot.
// List of available macro Y positions in order, from top to bottom.
int line = 1; // which slot to use next
// === 1. Long Name (always try to show first) ===
const char *username;
if (currentResolution == ScreenResolution::UltraLow) {
username = (nodeInfoLiteHasUser(node) && node->long_name[0]) ? node->short_name : nullptr;
} else {
username = (nodeInfoLiteHasUser(node) && node->long_name[0]) ? node->long_name : nullptr;
}
// Print node's long name (e.g. "Backpack Node")
if (username) {
int username_buffer = 0;
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN || MESHTASTIC_EXCLUDE_PKI)
if (nodeInfoLiteHasXeddsaSigned(node)) {
if (currentResolution == ScreenResolution::High) {
graphics::NodeListRenderer::drawScaledXBitmap16x16(x + 2, getTextPositions(display)[line] + 1,
xeddsa_shield_width, xeddsa_shield_height, xeddsa_shield,
display);
username_buffer = (xeddsa_shield_width * 2) + 4;
} else {
display->drawXbm(x, getTextPositions(display)[line] + 3, xeddsa_shield_width, xeddsa_shield_height,
xeddsa_shield);
username_buffer = xeddsa_shield_width + 2;
}
}
#endif
#if GRAPHICS_TFT_COLORING_ENABLED
const int usernameWidth = UIRenderer::measureStringWithEmotes(display, username);
#if !(MESHTASTIC_EXCLUDE_PKI_KEYGEN || MESHTASTIC_EXCLUDE_PKI)
if (nodeInfoLiteHasXeddsaSigned(node)) {
setAndRegisterTFTColorRole(TFTColorRole::FavoriteNodeBGHighlight, TFTPalette::Yellow, TFTPalette::Black,
x + usernameWidth, getTextPositions(display)[line], username_buffer, FONT_HEIGHT_SMALL);
}
#endif
setAndRegisterTFTColorRole(TFTColorRole::FavoriteNodeBGHighlight, TFTPalette::Yellow, TFTPalette::Black, x,
getTextPositions(display)[line], usernameWidth, FONT_HEIGHT_SMALL);
#endif
UIRenderer::drawStringWithEmotes(display, x + username_buffer, getTextPositions(display)[line++], username,
FONT_HEIGHT_SMALL, 1, false);
}
#if !MESHTASTIC_EXCLUDE_STATUS && !MESHTASTIC_EXCLUDE_STATUSDB
// === Optional: Last received StatusMessage line for this node ===
// Display it directly under the username line (if we have one). The cache
// lives on NodeDB now, keyed by NodeNum, so this is an O(1) lookup.
if (nodeDB) {
meshtastic_StatusMessage cachedStatus;
if (nodeDB->copyNodeStatus(node->num, cachedStatus) && cachedStatus.status[0]) {
drawTruncatedStatusLine(display, x, getTextPositions(display)[line++], cachedStatus.status);
}
}
#endif
// === 2. Signal/Hops line (if available) ===
bool haveSignal = false;
int bars = 0;
const char *qualityLabel = nullptr;
// Helper to get SNR limit based on modem preset
auto getSnrLimit = [](meshtastic_Config_LoRaConfig_ModemPreset preset) -> float {
switch (preset) {