//in onUpdate, something like this, and if you're doint runtime checks, can use screen shape, height, and width for different options
font=Gfx.FONT_MEDIUM;
fHeight=dc.getFontHeight(font);
//then in onUpdate
y=yStart;
dc.drawText(x,y,font,line1,...
y+=fHeight;
dc.drawText(x,y,font,line2,...
y+=fHeight;
...
//where x and justification are whatever you want.
Could you post some sample code and describe what you are seeing vs what you expect to see? Or post screenshots?
The font sizes are different between device families, and even the relative font sizes are different. e.g. FONT_LARGE is not always smaller than FONT_NUMBER_MILD, which surprised me.
Typically I use the font height to help position things, as in Jim’s sample code, and depending on what I'm doing, I also use the text width -getTextDimensionsInPixels().
var _end = mModel.getCurrentEnd();
dc.drawText(
(_canvas_w / 2),
_canvas_h/2 - 2 * Graphics.getFontHeight(Graphics.FONT_MEDIUM),
Graphics.FONT_MEDIUM ,
mEnds,
Graphics.TEXT_JUSTIFY_CENTER);
dc.drawText(
(_canvas_w / 2),
_canvas_h/2 + Graphics.getFontAscent(Graphics.FONT_MEDIUM) - 2 * Graphics.getFontHeight(Graphics.FONT_MEDIUM) ,
Graphics.FONT_NUMBER_MEDIUM ,
_end.format("%d"),
community.garmin.com/.../1455852.jpgWhat you might be seeing is some fonts (number fonts are most common) have extra white space at the top.
function onUpdate(dc) {
var mEnds = "Ends";
var _end = 123; // dummy data
dc.setColor(0, Graphics.COLOR_WHITE);
dc.clear();
// calculate starting y position
var y = _canvas_h/2 - Graphics.getFontHeight(Graphics.FONT_MEDIUM) - Graphics.getFontHeight(Graphics.FONT_NUMBER_MEDIUM);
dc.drawText(
(_canvas_w / 2),
y,
Graphics.FONT_MEDIUM ,
mEnds,
Graphics.TEXT_JUSTIFY_CENTER);
y += Graphics.getFontHeight(Graphics.FONT_MEDIUM);
dc.drawText(
(_canvas_w / 2),
y,
Graphics.FONT_NUMBER_MEDIUM ,
_end.format("%d"),
Graphics.TEXT_JUSTIFY_CENTER);
y += Graphics.getFontHeight(Graphics.FONT_NUMBER_MEDIUM);
//... Draw everything else
// draw a horizontal line that's vertically centered
dc.drawLine(0, _canvas_h/2, _canvas_w, _canvas_h/2);
}
[IMG2=JSON]{"data-align":"none","data-size":"full","src":"https:\/\/i.postimg.cc\/L6vxv549\/draw-f3.png"}[/IMG2]