From 9f8ef317feebc9f70784fa26f25a8d94b61e82b9 Mon Sep 17 00:00:00 2001 From: Jonas Diemer Date: Tue, 30 Dec 2025 18:07:48 +0100 Subject: [PATCH] Replace truncation in file selection with central function. --- lib/GfxRenderer/GfxRenderer.h | 3 ++- src/activities/reader/FileSelectionActivity.cpp | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/GfxRenderer/GfxRenderer.h b/lib/GfxRenderer/GfxRenderer.h index ed733a2..a636e36 100644 --- a/lib/GfxRenderer/GfxRenderer.h +++ b/lib/GfxRenderer/GfxRenderer.h @@ -75,7 +75,8 @@ class GfxRenderer { int getSpaceWidth(int fontId) const; int getFontAscenderSize(int fontId) const; int getLineHeight(int fontId) const; - std::string truncatedText(const int fontId, const char* text, const int maxWidth, const EpdFontStyle style) const; + std::string truncatedText(const int fontId, const char* text, const int maxWidth, + const EpdFontStyle style = REGULAR) const; // UI Components void drawButtonHints(int fontId, const char* btn1, const char* btn2, const char* btn3, const char* btn4) const; diff --git a/src/activities/reader/FileSelectionActivity.cpp b/src/activities/reader/FileSelectionActivity.cpp index 4f4ed9d..350298c 100644 --- a/src/activities/reader/FileSelectionActivity.cpp +++ b/src/activities/reader/FileSelectionActivity.cpp @@ -180,12 +180,7 @@ void FileSelectionActivity::render() const { const auto pageStartIndex = selectorIndex / PAGE_ITEMS * PAGE_ITEMS; renderer.fillRect(0, 60 + (selectorIndex % PAGE_ITEMS) * 30 - 2, pageWidth - 1, 30); for (int i = pageStartIndex; i < files.size() && i < pageStartIndex + PAGE_ITEMS; i++) { - auto item = files[i]; - int itemWidth = renderer.getTextWidth(UI_10_FONT_ID, item.c_str()); - while (itemWidth > renderer.getScreenWidth() - 40 && item.length() > 8) { - item.replace(item.length() - 5, 5, "..."); - itemWidth = renderer.getTextWidth(UI_10_FONT_ID, item.c_str()); - } + auto item = renderer.truncatedText(UI_10_FONT_ID, files[i].c_str(), renderer.getScreenWidth() - 40); renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % PAGE_ITEMS) * 30, item.c_str(), i != selectorIndex); }