From 6d6846689151a34c9b3960ef74a8a9e1755981c4 Mon Sep 17 00:00:00 2001 From: GenesiaW <74142392+GenesiaW@users.noreply.github.com> Date: Mon, 19 Jan 2026 21:01:51 +0800 Subject: [PATCH] fix: truncate chapter names that are too long (#422) ## Summary * **What is the goal of this PR?** (e.g., Implements the new feature for file uploading.) - Implements a fix to truncate chapter names that exceeds display width * **What changes are included?** - Implements a fix to truncate chapter names that exceeds display width ## Additional Context * Add any other information that might be helpful for the reviewer (e.g., performance implications, potential risks, specific areas to focus on). - Prior to the fix, if the book contains multiple chapters with names longer than the display width, there is a noticeable delay when scrolling through the list of chapters. Serial output of the issue: ``` [25673] [ACT] Entering activity: EpubReaderChapterSelection [25693] [GFX] !! Outside range (485, 65) -> (65, -6) [25693] [GFX] !! Outside range (486, 65) -> (65, -7) [25693] [GFX] !! Outside range (487, 65) -> (65, -8) [25693] [GFX] !! Outside range (488, 65) -> (65, -9) [25693] [GFX] !! Outside range (485, 66) -> (66, -6) [25693] [GFX] !! Outside range (486, 66) -> (66, -7) [25694] [GFX] !! Outside range (487, 66) -> (66, -8) [25694] [GFX] !! Outside range (484, 67) -> (67, -5) [25694] [GFX] !! Outside range (485, 67) -> (67, -6) [25694] [GFX] !! Outside range (486, 67) -> (67, -7) [25694] [GFX] !! Outside range (483, 68) -> (68, -4) [25694] [GFX] !! Outside range (484, 68) -> (68, -5) [25694] [GFX] !! Outside range (485, 68) -> (68, -6) ``` --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_ Co-authored-by: Dave Allie --- .../reader/EpubReaderChapterSelectionActivity.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/activities/reader/EpubReaderChapterSelectionActivity.cpp b/src/activities/reader/EpubReaderChapterSelectionActivity.cpp index f9a1aa69..ad4dd2ff 100644 --- a/src/activities/reader/EpubReaderChapterSelectionActivity.cpp +++ b/src/activities/reader/EpubReaderChapterSelectionActivity.cpp @@ -199,7 +199,11 @@ void EpubReaderChapterSelectionActivity::renderScreen() { // Draw TOC item (account for top sync offset) const int tocIndex = tocIndexFromItemIndex(itemIndex); auto item = epub->getTocItem(tocIndex); - renderer.drawText(UI_10_FONT_ID, 20 + (item.level - 1) * 15, displayY, item.title.c_str(), !isSelected); + const int indentSize = 20 + (item.level - 1) * 15; + const std::string chapterName = + renderer.truncatedText(UI_10_FONT_ID, item.title.c_str(), pageWidth - 40 - indentSize); + renderer.drawText(UI_10_FONT_ID, indentSize, 60 + (tocIndex % pageItems) * 30, chapterName.c_str(), + tocIndex != selectorIndex); } }