Is there any simple way of centering test in a field?
I use this:
/***********************************************************************
* FUNCTION: UTDrawCenteredString
*
* DESCRIPTION: Draw a string centered in a field's rectangle
*
* RETURNED: nothing
***********************************************************************/
void UTDrawCenteredString
(
UInt16 fldID, // ( in ) the field to draw it in
Char * fldTextP // ( in ) the string to draw
)
{
ErrNonFatalDisplayIf ( fldTextP == NULL, "UTDrawCenteredString: NULL string" );
ErrNonFatalDisplayIf ( fldID == 0, "UTDrawCenteredString: zero field ID" );
// Get the field position
FieldPtr fldP = ( FieldPtr ) UTGetObjectPtr ( fldID );
RectangleType bounds;
FldGetBounds ( fldP, &bounds );// Set the correct font
FontID oldFont = FntGetFont ();
FontID fldFont = FldGetFont ( fldP );
FntSetFont ( fldFont );// Figure out the string location
UInt16 lineLen = StrLen ( fldTextP );
if ( lineLen > 0 )
{// Draw it
Int16 strWidth = FntCharsWidth ( fldTextP, ( Int16 ) lineLen );
Coord xPos = ( Coord ) ( bounds.topLeft.x + ( bounds.extent.x - strWidth ) / 2 );
WinDrawChars ( fldTextP, ( Int16 ) lineLen, xPos, bounds.topLeft.y );
}
// Restore the environment
FntSetFont ( oldFont ); }
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
