lovyan03 / LovyanGFX

SPI LCD graphics library for ESP32 (ESP-IDF/ArduinoESP32) / ESP8266 (ArduinoESP8266) / SAMD51(Seeed ArduinoSAMD51)
Other
1.19k stars 209 forks source link

Need function to determine size in pixels of a string with a specified font #649

Closed craiglindley closed 6 days ago

craiglindley commented 6 days ago

I have a need to display various size text strings on my display. To position them I need to have a function that can give me the size in pixels of a specified string taking into consideration the current font and the current text size.

I've looked through all the documentation I have found about your library and cannot find a function like this. This new function could be like the

"getTextBounds" function in the Adafruit GFX library which returns the width and height of the string passed to it. The Adafruit function takes into consideration the current font and the current text size.

tobozo commented 6 days ago

hi,

text height is usually fixed, only width is variable when the font is not monotype:

    tft.setFont(&myFont);
    auto textWidth = tft.getTextWidth("blah");
    auto textHeight = tft.getTextSizeY();
craiglindley commented 6 days ago

Thanks but I didn't find getTextWidth("String") but I did find textWidth("String")

But thanks, you gave me the answer I needed. I guess the issue could be closed.

On Tue, Nov 19, 2024 at 2:00 PM tobozo @.***> wrote:

hi,

text height is usually fixed, only width is variable when the font is not monotype:

tft.setFont(&myFont);
auto textWidth = tft.getTextWidth("blah");
auto textHeight = tft.getTextSizeY();

— Reply to this email directly, view it on GitHub https://github.com/lovyan03/LovyanGFX/issues/649#issuecomment-2486741700, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6K5DY763RZPSJF7HVMNFT2BORGDAVCNFSM6AAAAABSC3HK4OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBWG42DCNZQGA . You are receiving this because you authored the thread.Message ID: @.***>