Adafruit-GFX-Library
Adafruit-GFX-Library copied to clipboard
Allow text size as float
It would be a nice to have feature where the text size could be also entered as a float. Currently an integer numbers for text size are allowed.
By default:
- text size 1 produces text with size 6x8 (width x height) pixels
- text size 2 produces text with size 12x16 pixels
In my application I use both sizes but I would also like to have a size 9x12 pixels. This could be achieved with text size of 1.5 however at the moment this value is not allowed because text size is defined as uint8_t:
Adafruit_GFX.h
uint8_t textsize_x; ///< Desired magnification in X-axis of text to print()
uint8_t textsize_y; ///< Desired magnification in Y-axis of text to print()
In 1.10.7-text-size branch of my fork I made a change where text size is now a float. It is implemented over original 1.10.7 release version. I did a minimal required effort to have what I want to have. Side effects for this are unknown; just the text size meet my requirement. Maybe somebody will find it as a useful feature and can use it in his own solution.
The result can be seen on the picture below. Under each Trip word is written what is the text size. The code used to generate the preview is:
display.clearDisplay();
display.setTextSize(1.0); // 6x8
display.setCursor(0, 0);
display.write("Trip");
display.setCursor(5, 16);
display.write("1.0");
display.setTextSize(1.5); // 9x12
display.setCursor(30, 0);
display.write("Trip");
display.setCursor(35, 16);
display.write("1.5");
display.setTextSize(2.0); // 12x16
display.setCursor(75, 0);
display.write("Trip");
display.setCursor(80, 16);
display.write("2.0");
display.display();
The display has 128px width and 32px height. AVR board is Arduino Pro Mini 5V.