diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 1e9c89e00..3edfa1f49 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -1191,10 +1191,10 @@ public: mesh::ui::drawTextCenteredEllipsized( display, layout.pairing, layout.pairing_label_y, pairing_label); display.setTextSize(pairing_value_size); - mesh::ui::drawTextCenteredEllipsized( + const bool value_drawn = mesh::ui::drawTextCenteredEllipsized( display, layout.pairing, layout.pairing_value_y, pairing_value); _pairing_pin_visible = pairing_value == pairing_pin - && display.getTextWidth(pairing_value) <= layout.pairing.width + && value_drawn && layout.pairing_value_y + display.textLineHeight() <= display.height(); } else if (expanded_home) { display.setColor(UIColor::secondary_txt); diff --git a/src/helpers/ui/CompanionHomeLayout.h b/src/helpers/ui/CompanionHomeLayout.h index 8d80f3956..a2bedb6d8 100644 --- a/src/helpers/ui/CompanionHomeLayout.h +++ b/src/helpers/ui/CompanionHomeLayout.h @@ -144,16 +144,19 @@ inline void clearDisplayRegion(DisplayDriver& display, // Center short text inside the supplied region and ellipsize long text from // the region's left edge. In both cases the rendered row is horizontally // bounded by the region and cannot run into an adjacent UI block. -inline void drawTextCenteredEllipsized(DisplayDriver& display, +// Return true when the complete text was drawn, without measuring it again. +inline bool drawTextCenteredEllipsized(DisplayDriver& display, const DisplayRegion& region, int y, const char* text) { - if (text == nullptr || text[0] == 0 || region.width <= 0) return; + if (text == nullptr || text[0] == 0 || region.width <= 0) return false; const int text_width = display.getTextWidth(text); if (text_width <= region.width) { display.setCursor(region.x + (region.width - text_width) / 2, y); display.print(text); + return true; } else { display.drawTextEllipsized(region.x, y, region.width, text); + return false; } } @@ -196,8 +199,9 @@ public: // including native 160x80 T096 and 250x122 MeshPocket panels. The caller must // not draw ordinary instructions/network rows in this same area. // Return true only when the complete value fits and was drawn. -inline bool drawBottomPairingBlock(DisplayDriver& display, int content_top, - const char* label, const char* value) { +// Keep this layout separate from the large home renderer to reduce flash use. +__attribute__((noinline)) inline bool drawBottomPairingBlock( + DisplayDriver& display, int content_top, const char* label, const char* value) { const int bottom = display.height() - (display.height() > 64 ? 2 : 0); const int available = bottom - content_top; const int margin = display.width() >= 16 ? 4 : 0; @@ -227,8 +231,7 @@ inline bool drawBottomPairingBlock(DisplayDriver& display, int content_top, drawTextCenteredEllipsized(display, region, region.y, label); } display.setTextSize(value_size); - drawTextCenteredEllipsized(display, region, bottom - value_height, value); - return display.getTextWidth(value) <= width; + return drawTextCenteredEllipsized(display, region, bottom - value_height, value); } } // namespace ui diff --git a/test/test_companion_inbox.py b/test/test_companion_inbox.py index ce97c3802..2de3b9959 100644 --- a/test/test_companion_inbox.py +++ b/test/test_companion_inbox.py @@ -250,10 +250,12 @@ int main() { #define PRESS_LABEL "Press" int UITask::getPreviewCount() const { return 12; } const char* UITask::inboxTitle() const { return "HISTORY"; } -void renderHome(DisplayDriver& display, UITask* _task) { +bool renderHome(DisplayDriver& display, UITask* _task) { + bool _pairing_pin_visible = false; char tmp[80]; const int body_top = 14; '''+ first_page + r''' + return _pairing_pin_visible; } struct MeasuredDisplay : Display { int size = 1; @@ -276,7 +278,8 @@ int main() { MeasuredDisplay display(dims.first, dims.second); UITask task(display); task._msgcount = 0; task.connected = true; task.client = client; - renderHome(display, &task); + const bool pairing_pin_visible = renderHome(display, &task); + assert(pairing_pin_visible == display.contains("123456")); assert(display.contains("HISTORY: 12")); assert(display.contains("Pending: 0")); if (task.hasBluetoothConnection()) {