Feature request - DrawFloat and DrawNumber add Units #2183
-
Hello, I apologize if there is a better way to do this, it should be easy to add. It would be handy to be able to overload the function to allow for character units to be added on the end of the float or number. For example, 80.1F, 100.24PPM. That way you don't have to code a separate string at the end. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Good question! The library supports implementation of this in the sketch. The functions drawString, drawNumber and drawFloat return the pixel width of the string/number rendered so this can be used to position a squence of text and numeric values. For example:
If x and y are constants ( 10 and 20 in this case) then a single line of code would work:
Since this is quite simple (once you know how!) I am not convinced adding a new function is required and would be less flexible. For example non-numeric characters can precede a numeric value (e.g. $123.45) and then this would be another function or an additional parameter to indicate where the text is to be placed:
One day I will write a user manual and this would be good to include! |
Beta Was this translation helpful? Give feedback.
-
Thank you. This is a big help.
On Sunday, November 20, 2022 at 12:40:14 PM EST, Bodmer ***@***.***> wrote:
Good question!
The library supports implementation of this in the sketch. The functions drawString, drawNumber and drawFloat return the pixel width of the string/number rendered so this can be used to position a squence of text and numeric values. For example:
int16_t x = 10;
int16_t y = 10;
int16_t val = 123;
x+= tft.drawNumber(val, x, y);
tft.drawString(" F", x, y);
If x and y are constants ( 10 and 20 in this case) then a single line of code would work:
tft.drawString(" F", tft.drawNumber(val, 10, 20) + 10, 20);
Since this is quite simple (once you know how!) I am not convinced adding a new function is required and would be less flexible. For example non-numeric characters can precede a numeric value (e.g. $123.45) and then this would be another function or an additional parameter to indicate where the text is to be placed:
float f = 123.45
tft.drawFloat(f, tft.drawString("$", 10, 40) + 10, 40);
One day I will write a user manual and this would be good to include!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Good question!
The library supports implementation of this in the sketch. The functions drawString, drawNumber and drawFloat return the pixel width of the string/number rendered so this can be used to position a squence of text and numeric values. For example:
If x and y are constants ( 10 and 20 in this case) then a single line of code would work:
Since this is quite simple (once you know how!) I am not convinced adding a new function is required and would be less flexible. For example non-numeric characters…