BTW, may I have a feature request? For aligning the digits to the right I use my own function in the code: rightAlignment(). Can we do something more sophisticated from the library? Like TextAlignment(uint8_t alignment) and 3 arguments: LEFT, RIGHT, CENTER.
I know what you mean. I have had many cases where I wanted to center text.
The general case of aligning text is a bit more complex than it may seem at first.
It could be a mode type setting like you have above and the alignment code could make some assumptions
about vertical positioning when doing future rendering (like the current vertical location,
but then it has to know the left and right bounds, which could be assumed to be the left & right bounds of the current text area.
But then you also have a few potential issues that crop up since alignment has to be based on strings
and the selected font (since each character can potentially have a different width)
so there has to be quite a bit of documentation explaining the behaviors of these modes
when using the existing text functions. Things like how to handle line wrapping or
what happens when next text after this is sent. Does it start a new line or go on the right of this string?
These are just a few of the things that pop up.
I've thought about it several times and never reached a conclusion as to the best way to do this.
My initial thought for ease of use and simplicity was to do something like an enhanced version
of DrawString() where you pass in additional parameters to specify the alignment and the bounds
for the alignment for that specific string. And perhaps a version where instead of a x,y position
you pass in the upper/lower, right/left bounds and the desired alignments. That way
the text can be aligned not only horizontally but vertically as well.
For what you are doing with simple numbers that are going to land in fixed width fields,
I'd recommend using text areas for the values along with printf. The glcd library has support
for printf built in. See the "Printf" function in the documentation and also the BigNums example
sketch for an example of using text areas to update numeric fields on the screen.
The use of a fixed width font along with text areas and printf can make updating those fields quite simple.
i.e. you use printf format capabilities to format the string with leading padding (zeros or spaces)
and then use the text area to hold a text field of the exact size of the numeric data.
Then to update the field you simply write to the text area.
For example once you defined your text area and set the font for it,
to update the value could be as simple as:
(assuming you named the text areas "volts", and "millivolts", used a fixed width font, and created 3x1 character areas for each)
If you want 0 filled, instead of leading spaces for small numbers,
you would use "%03d" for the format string instead.
Just keep in mind that when using Printf() in glcd that the current printf() support is limited to integers because
in order to get floating point support for the printf functions,
you have to link against a different AVR libC library and the Arduino IDE does not allow setting of any compiler or linker options.