-
-
Notifications
You must be signed in to change notification settings - Fork 231
[bug] Text bounds do not always trim the text as expected #784
Description
Hi,
I am experiencing a problem with text bounds, which appear to be working sometimes, but not always.
I am attaching a minimal example and screenshot to illustrate the problem. In a nutshell, when printing a long string in an area bounded by a text bound, the left side of the text bound is being violated while the right text bound is being honored. Top and bottom bounds of the text box are also being honored, e.g. when printing the long string higher up or lower. It is the left side in this example, where the text bound is violated by the println.
I am not entirely sure if this is intended behaviour since the cursor position is outside the text bounds. However, I cannot imagine that this is the intention as the right/top/bottom bounds are being honored.
The device I am using is a CrowPanel 1.28inch-HMI ESP32 Rotary Display 240*240 IPS Round Touch Knob Screen.
See here for details: https://www.elecrow.com/wiki/CrowPanel_1.28inch-HMI_ESP32_Rotary_Display.html
Maybe I am using the text bounds incorrectly, or is this a bug?
Thanks,
Bjoern
[EDIT: Image now uploaded and included rather than linking to an external image host]
Screenshot illiustrating the problem:

Minimal code example:
#include <Arduino.h>
// --- Arduino Graphics and additional fonts ---
#include <Arduino_GFX_Library.h>
#include <U8g2lib.h>
// --- CrowPanel TFT Panel ---
#define TFT_SCLK 10
#define TFT_MOSI 11
#define TFT_MISO -1
#define TFT_DC 3
#define TFT_CS 9
#define TFT_RES 14
#define TFT_BLK 46
#define LCD_PWR_EN1 1 // LCD_3V3 rail
#define LCD_PWR_EN2 2 // LEDA_3V3 rail
// --- Display Settings ---
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 240
#define DISPLAY_ROTATION 3
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("Setup has started...");
// Power rails for the LCD/backlight
pinMode(LCD_PWR_EN1, OUTPUT);
pinMode(LCD_PWR_EN2, OUTPUT);
digitalWrite(LCD_PWR_EN1, HIGH);
digitalWrite(LCD_PWR_EN2, HIGH);
// Backlight
pinMode(TFT_BLK, OUTPUT);
analogWrite(TFT_BLK, 255);
// --- Initialize Arduino GFX for ESP32/GC9A01 ---
Arduino_ESP32SPI *bus = new Arduino_ESP32SPI(
TFT_DC, TFT_CS, TFT_SCLK, TFT_MOSI, GFX_NOT_DEFINED, FSPI, true
);
Arduino_G *output_display = new Arduino_GC9A01(bus, TFT_RES, DISPLAY_ROTATION, true /* IPS */);
Arduino_GFX *gfx = new Arduino_Canvas(DISPLAY_WIDTH, DISPLAY_HEIGHT, output_display);
// Rendering setup
gfx->begin();
// Enable UTF-8 for "print"
gfx->setUTF8Print(true);
// Wipe background
gfx->fillScreen(RGB565_BLACK);
// Draw frame
gfx->drawRoundRect(25, 122, 190, 36, 6, RGB565_WHITE);
gfx->fillRoundRect(27, 124, 186, 32, 6, RGB565_BLACK);
// Set bounds to the text area
gfx->setTextBound(27, 124, 186, 32); // Same as the inner rectangle
gfx->setTextWrap(false);
// Print text
gfx->setFont(u8g2_font_crox5hb_tr);
gfx->setTextColor(RGB565_CYAN, RGB565_BLACK);
gfx->setCursor(0, 148);
gfx->println("This is a super-long text with many characters");
// Flush
gfx->flush();
// Forever...
Serial.println("Waiting for Godot...");
while (true) {};
}
void loop() {
Serial.println("Ping...");
}