Skip to main content
December 28, 2020
Solved

Problem with text wildcard

  • December 28, 2020
  • 6 replies
  • 1376 views

Hello!

I have textArea with wildcard, which is updated by Slider moving

void OPTIONS_SCREENView::R_Slider_MOVED(int value)
{
 
RGB_LED_Sample_box.setColor(touchgfx::Color::getColorFrom24BitRGB(R_Slider.getValue(), G_Slider.getValue(), B_Slider.getValue()));
RGB_LED_Sample_box.invalidate();
	
Unicode::snprintf(R_Value_textBuffer, 20, "%d", value);
R_Value_text.setWildcard(R_Value_textBuffer);
R_Value_text.resizeToCurrentText(); 
R_Value_text.invalidate();
}

When I set values from 0 to 255, everything is fine. When reduce from 255 to 0 - problem: if the number is less than 100, then a 3 digit incorrect number, 1 and 2 - correct two-digit number, if less than 10 during the 2nd and 3rd digits of the wrong number, the first correct one digit number.

values in variable "value" - are always correct.

For example:

255->255

101->101

89->891

78->781

11->111

9->911

What's wrong?

This topic has been closed for replies.
Best answer by Bob Bailey
	
Unicode::snprintf(R_Value_textBuffer, 20, "%d", value);
R_Value_text.invalidate(); // invalidate the old size of the text
R_Value_text.setWildcard(R_Value_textBuffer);
R_Value_text.resizeToCurrentText(); 
R_Value_text.invalidate();

this will do it I think. or create the textarea large enough for the biggest number and dont resize it

6 replies

Bob Bailey
Senior
December 29, 2020

you need to invalidate twice. first to remove the old number, then to make the new number get drawn. 89->891 the 1 is from the previous "101" number.

December 29, 2020

"89->891 the 1 is from the previous "101" number " - I guessed it.

" twice" - where and where in code? I called SetWildcard only once.

Bob Bailey
Bob BaileyBest answer
Senior
December 29, 2020
	
Unicode::snprintf(R_Value_textBuffer, 20, "%d", value);
R_Value_text.invalidate(); // invalidate the old size of the text
R_Value_text.setWildcard(R_Value_textBuffer);
R_Value_text.resizeToCurrentText(); 
R_Value_text.invalidate();

this will do it I think. or create the textarea large enough for the biggest number and dont resize it

December 29, 2020

"this will do it I think" - Works! Thanks!

"or create the textarea large enough for the biggest number a" - how to do it? Where can I set size?

I want to use second of your variants, because if I resize - alignment not works.

Alexandre RENOUX
Visitor II
January 5, 2021

Hello EEuge,

When your question is answered, please close this topic by choosing Select as Best.

/Alexandre