Problem with drawString #1025
-
I'm having a problem with drawString that I cannot seem to resolve. I have done a few projects with this library with little problem and have come to prefer to use drawString rather than print. The attached pic shows the problem with the one on the left working correctly using print, and the one on the right showing the problem using drawString. All other display info is done using drawString, drawNumber. The relevant bit of code is below, and none of the rest of the code hits this area.
As I say I have resolved using 'print' but I would like to get to the bottom of this, Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
Can you set the location to put that text right before that line? It's possible the location is being changed somewhere else in your loop? |
Beta Was this translation helpful? Give feedback.
-
Check that the text datum has not been changed by your sketch, to for example right justify the numbers. To be safe set the datum before using drawString |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
For the screen that is in the picture I use draw rather than print.
For the fixed text and messages I have ...
tft.setCursor(Msgx,Msgy); // Position cursor, not needed for drawstring but a hangover from my using print
tft.setTextDatum(TL_DATUM); // Set datum to top left of text so text is left justified
tft.setTextColor(TFT_RED, TFT_WHITE); // Set message colour
tft.drawString(msgtxt,Msgx,Msgy-20,4); // Output message text. (Could have used tft.print(msgtxt);
tft.setTextColor(TFT_GREEN, TFT_BLACK); // Reset text colour
For the changing data e.g. height I have ...
tft.setTextColor(TFT_GREEN, TFT_BLACK); // Set text color
tft.setTextDatum(TR_DATUM); // Sets datum to right of text so it will right justift
// PROCESS HEIGHT
// Write to the display the string with right text alignment:
tft.setTextPadding( tft.textWidth("8888", 4) ); // Define text padding so I do not have to worry about clearing digits e.g. going from 1100 to 900, don't have to write space over leading '1'
tft.drawNumber(HeightNum,Heightx,Heighty,4); // drawString text or value using font 4
Regards,
Colin
From: dookie454 <[email protected]>
Sent: 26 February 2021 14:04
To: Bodmer/TFT_eSPI <[email protected]>
Cc: colinb1950 <[email protected]>; Author <[email protected]>
Subject: Re: [Bodmer/TFT_eSPI] Problem with drawString (#1025)
cool, yes very helpful, didnt notice that. Im working on a situation now where I want a decimal on the TFT.
With the normal LCD libraries and many other TFT libaries, I could just use TFT.Print(2.31, 2), the 2 would be the decimal.
How would I do that using the directions shown below in the Wiki? And would I add TFT to the front? "TFT.print(TEXT,TYPE);"
That is where these examples are a bit confusing, the examples are missing critical pieces.
print(TEXT,TYPE);
TEXT >> "", *pointer, NUM
TYPE >> CHR, HEX, DEC, OCT = Optional, DEFAULT CHR
println(TEXT,TYPE);
TEXT >> "", *pointer, NUM
TYPE >> CHR, HEX, DEC, OCT = Optional, DEFAULT CHR
print(); with the addition of lf & cr
-
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FBodmer%2FTFT_eSPI%2Fdiscussions%2F1025%23discussioncomment-409334&data=04%7C01%7C%7C308d8d0bef534cd6ce7308d8da5f5330%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637499450232692434%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=pxcrthmxa%2BRJg%2Fz6DFJuctf4Z4Brg7Sl1rk3VaXSZEM%3D&reserved=0>, or unsubscribe<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAS63CU3HAGM3EF2GUZ74C7DTA6S33ANCNFSM4YDDPTFQ&data=04%7C01%7C%7C308d8d0bef534cd6ce7308d8da5f5330%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637499450232702428%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Mr%2BvHWMijARQXOD5Pyg90LIpo1ZQ0jPkihoa5ocpQgU%3D&reserved=0>.
|
Beta Was this translation helpful? Give feedback.
Check that the text datum has not been changed by your sketch, to for example right justify the numbers.
To be safe set the datum before using drawString