Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best approach to replacing previous text values #3506

Open
tmargot opened this issue Oct 13, 2024 · 2 comments
Open

Best approach to replacing previous text values #3506

tmargot opened this issue Oct 13, 2024 · 2 comments

Comments

@tmargot
Copy link

tmargot commented Oct 13, 2024

Hi,

I have been battling to figure out how to clear the previous printed text, I have searched everywhere and I am sure there is a simple answer.

It doesn't matter whether I use tft.drawString() or tft.println(), if the previous string printed was longer than the new, the remainder of the previous string remains on the screen.

Using the code below as an example, if x is set to a multiple digit value and then set back to zero the remainder multiple digits remain.
For example: x was 0, then was set to 9999 and then set back to 0, the screen would show "x: 0999" instead of "x:0".

UPDATE: I have managed to get the following working use tft.setTextPadding() and tft.drawString() but how would you achieve this with tft.println() as adding padding did not seem to work for me?

This is working

void loop() {
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
int16_t padSize = tft.textWidth("x: 9999");
  tft.setCursor(0, 0); 
  tft.setTextPadding(padSize);  
  tft.drawString("x: " + String(x),0,100,1);
  tft.drawString("y: " + String(y),0,150,1);
  tft.drawString("z: " + String(z),0,200,1);
}

This is not, is there a way?

void loop() {
tft.setTextColor(TFT_WHITE, TFT_BLACK);
int16_t padSize = tft.textWidth("x: 9999");
  tft.setCursor(0, 0); 
  tft.println("x: " + String(x));  
  tft.println("y: " + String(y));  
  tft.println("z: " + String(z)); 
}

Thank you

@Basitadam
Copy link

Basitadam commented Oct 16, 2024

`void loop()
{
tft.setTextColor(TFT_BLACK, TFT_BLACK);
int16_t padSize = tft.textWidth("x: 9999");

tft.setCursor(0, 0);
tft.println("x: " + String(x)); // previous string x
tft.println("y: " + String(y)); // previous string y
tft.println("z: " + String(z)); // previous string z

tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.setCursor(0, 0);
tft.println("x: " + String(x)); // new string x
tft.println("y: " + String(y)); // new string y
tft.println("z: " + String(z)); // new string z
}`

I know. It is a dirty trick

@tmargot
Copy link
Author

tmargot commented Oct 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants