[LIB] CenterText
Posted: 31 Jul 2012, 05:03
I have created an easy way to centre text for displaying on the NXT screen. Returns the X position of the text passed in through the first parameter.
Use:
Remember to use the same text that you are displaying in the CenterText function.
Or use:
Code: (for those too lazy to download)
Download:
Use:
Code: Select all
#include "CenterText.Lib.nxc"
TextOut( CenterText("Hello World!"), LCD_LINE3, "Hello World!" );
Or use:
Code: Select all
#include "CenterText.Lib.nxc"
CenterTextOut( LCD_LINE3, "Hello World!" );
Code: Select all
/*
CenterText.Lib.nxc
*/
int CenterText( const string text ) {
int len = StrLen(text);
len = (len * 5);
len = (100 - len);
len = (len / 2);
len = (len - 5);
return len;
}
char CenterTextOut( int y, string text, unsigned long options = DRAW_OPT_NORMAL ) {
int len = CenterText(text);
return TextOut( len, y, text, options );
}