feat: wrapped text in GfxRender, implemented in themes so far (#1141)

## Summary

* **What is the goal of this PR?** (e.g., Implements the new feature for
file uploading.)


* **What changes are included?**
Conrgegate the changes of #1074 , #1013 , and extended upon #911 by
@lkristensen
New function implemented in GfxRenderer.cpp
```C++
std::vector<std::string> GfxRenderer::wrappedText(const int fontId, const char* text, const int maxWidth,
                                                  const int maxLines, const EpdFontFamily::Style style) const
```
Applied logic to all uses in Lyra, Lyra Extended, and base theme
(continue reading card as pointed out by @znelson


## Additional Context





![IMG_8604](https://github.com/user-attachments/assets/49da71c9-a44f-4cde-b3bf-6773d71601b6)

![IMG_8605](https://github.com/user-attachments/assets/5eab4293-65c1-47fb-b422-8ab53a6b50a2)

![IMG_8606](https://github.com/user-attachments/assets/e0f98d19-0e3f-4294-83a1-e49264378dca)


---

### 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? _**< YES >**_

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
iandchasse
2026-02-25 04:24:35 -05:00
committed by GitHub
parent f2fbdccd53
commit 35988ada55
6 changed files with 102 additions and 166 deletions

View File

@@ -830,7 +830,8 @@ std::string GfxRenderer::truncatedText(const int fontId, const char* text, const
if (!text || maxWidth <= 0) return "";
std::string item = text;
const char* ellipsis = "...";
// U+2026 HORIZONTAL ELLIPSIS (UTF-8: 0xE2 0x80 0xA6)
const char* ellipsis = "\xe2\x80\xa6";
int textWidth = getTextWidth(fontId, item.c_str(), style);
if (textWidth <= maxWidth) {
// Text fits, return as is
@@ -844,6 +845,70 @@ std::string GfxRenderer::truncatedText(const int fontId, const char* text, const
return item.empty() ? ellipsis : item + ellipsis;
}
std::vector<std::string> GfxRenderer::wrappedText(const int fontId, const char* text, const int maxWidth,
const int maxLines, const EpdFontFamily::Style style) const {
std::vector<std::string> lines;
if (!text || maxWidth <= 0 || maxLines <= 0) return lines;
std::string remaining = text;
std::string currentLine;
while (!remaining.empty()) {
if (static_cast<int>(lines.size()) == maxLines - 1) {
// Last available line: combine any word already started on this line with
// the rest of the text, then let truncatedText fit it with an ellipsis.
std::string lastContent = currentLine.empty() ? remaining : currentLine + " " + remaining;
lines.push_back(truncatedText(fontId, lastContent.c_str(), maxWidth, style));
return lines;
}
// Find next word
size_t spacePos = remaining.find(' ');
std::string word;
if (spacePos == std::string::npos) {
word = remaining;
remaining.clear();
} else {
word = remaining.substr(0, spacePos);
remaining.erase(0, spacePos + 1);
}
std::string testLine = currentLine.empty() ? word : currentLine + " " + word;
if (getTextWidth(fontId, testLine.c_str(), style) <= maxWidth) {
currentLine = testLine;
} else {
if (!currentLine.empty()) {
lines.push_back(currentLine);
// If the carried-over word itself exceeds maxWidth, truncate it and
// push it as a complete line immediately — storing it in currentLine
// would allow a subsequent short word to be appended after the ellipsis.
if (getTextWidth(fontId, word.c_str(), style) > maxWidth) {
lines.push_back(truncatedText(fontId, word.c_str(), maxWidth, style));
currentLine.clear();
if (static_cast<int>(lines.size()) >= maxLines) return lines;
} else {
currentLine = word;
}
} else {
// Single word wider than maxWidth: truncate and stop to avoid complicated
// splitting rules (different between languages). Results in an aesthetically
// pleasing end.
lines.push_back(truncatedText(fontId, word.c_str(), maxWidth, style));
return lines;
}
}
}
if (!currentLine.empty() && static_cast<int>(lines.size()) < maxLines) {
lines.push_back(currentLine);
}
return lines;
}
// Note: Internal driver treats screen in command orientation; this library exposes a logical orientation
int GfxRenderer::getScreenWidth() const {
switch (orientation) {

View File

@@ -5,6 +5,8 @@
#include <HalDisplay.h>
#include <map>
#include <string>
#include <vector>
#include "Bitmap.h"
@@ -120,6 +122,11 @@ class GfxRenderer {
int getLineHeight(int fontId) const;
std::string truncatedText(int fontId, const char* text, int maxWidth,
EpdFontFamily::Style style = EpdFontFamily::REGULAR) const;
/// Word-wrap \p text into at most \p maxLines lines, each no wider than
/// \p maxWidth pixels. Overflowing words and excess lines are UTF-8-safely
/// truncated with an ellipsis (U+2026).
std::vector<std::string> wrappedText(int fontId, const char* text, int maxWidth, int maxLines,
EpdFontFamily::Style style = EpdFontFamily::REGULAR) const;
// Helper for drawing rotated text (90 degrees clockwise, for side buttons)
void drawTextRotated90CW(int fontId, int x, int y, const char* text, bool black = true,