Text formatting with Text Areas? (GLCD v3)

So I've made a very simple program that displays a number followed by some units.

// include the library header
#include <glcd.h>

// include the Fonts
#include <fonts/allFonts.h>

void setup() {

  GLCD.Init();   // Initialize the GLCD 

gText mPH = gText(5,5,3,1,fixednums15x31,SCROLL_UP);

gText unit = gText(55,25,3,1,SystemFont5x7,SCROLL_UP);
  
    mPH.print("12");
    unit.print("MPH");
}

void loop() {

  //
  //example
  //
}

but as you may be able to tell, the moment it drops under 100mph the text will move to the left, so instead of looking like "12mph" it looks like "12 mph".
is there any formatting option in the GLCD libary? I've read the manual but can't find a thing about it.

thanks

The library supports "printf" style formating.
So you can print the digits using a printf formatting string:

mPH.Printf("%3d", speed);

or if you want zero filled:

mPH.Printf("%03d", speed);

The BigNums example sketch has some examples of using Printf()

Note: including the xxprintf formatting routines will eat up about 1.8k of flash
so there is a cost associated with the formatting routines.

--- bill

Thanks for the quick reply!

with the zeros filled it works perfectly, but without the zero fill it still doesn't format properly.

but having zeros wont bother me too much :).

Ah I see the problem.
The fixednums15x31 font is not a full font.
It does not have a character. In only has numbers along with , + - and /
Sorry about that. It would work with a font that contains the character.

If you want to zero fill and don't want to use the extra code space from the xxprintf() formatting
routines you could just print a "0" if the speed is lower than 100.

ex:

if(speed < 100)
    mPH.print("0");
mPH.print(speed);

If you want a space it is a bit trickier since you will have position the cursor over
to column 1 to skip over that first position to create the space. Then you have to
make sure to clear that first digit position to ensure that if you drop from say 100 to
99 you you don't end up with a left over '1' and display 199 instead of 99

ex:

if(speed < 100)
{
    mPH.CursorTo(1); // skip over to column 1 to skip over 100's position
    mPH.EraseTextLine(eraseFROM_BOL); // clear any remaining digit in colum 0
}
mPH.print(speed);

--- bill