Hi, how do I make sure that the current day of the week is displayed in an ellipse?
Has anyone handled something like this?
Thank you.
Hi, how do I make sure that the current day of the week is displayed in an ellipse?
Has anyone handled something like this?
Thank you.
There's a rounded rectangle
which you can use to draw the text and you can measure the length of it via
which is also on the Graphics object. Once you've done that you need to format the current date using Time.now() and use today.day_of_week, which is in the example on
https://developer.garmin.com/connect-iq/api-docs/Toybox/Time.html
completely untested example below:
using Toybox.System;
using Toybox.Time;
using Toybox.Time.Gregorian;
using Toybox.Graphics;
function onUpdate(dc){
var today = Gregorian.info(Time.now(), Time.FORMAT_MEDIUM);
var day = today.day_of_week;
var dims = dc.getTextDimensions(t
oday.day_of_week, GRAPHICS.FONT_SYSTEM_SMALL);
dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT);
dc.setPenWidth(4);
dc.drawRoundedRectangle(0, 0, dims[0]+10, dims[1]+10, 3);
dc.drawText(dims[0]/2, dims[1]/2, GRAPHICS.FONT_SYSTEM_SMALL, today.day_of_week, Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
}
You get the idea. You should be able to put all those things together to print the day of the week in a rounded rectangle.
Here's a simple example. where I size the box based on the size of the text and the fount used, with the upper left being at 30,50
var f=Graphics.FONT_XTINY; var str=clockTime.day_of_week.substring(0,3); var rX=30; var rY=50; var rW=dc.getTextWidthInPixels(str, f)+6; var rH=dc.getFontHeight(f)+2; dc.setPenWidth(2); dc.drawRoundedRectangle(rX, rY, rW, rH, 3); dc.drawText(rX+rW/2,rY+rH/2,f,str,Graphics.TEXT_JUSTIFY_CENTER|Graphics.TEXT_JUSTIFY_VCENTER);,
And this is how it looks in the sim (ignore the stuff below the DayOfWeek.)
You can also use a fixed size box, and use the came code to center the text in the box.
Hi Jim,
please send me the whole code with the Toybox import.
It doesn't work for me after copying.
How do I edit your code so that watchFace displays all days and the current day in an ellipse?
Error Sim: Symbol Not Found Error
Details: Could not find symbol 'day_of_week'
Thank you for your help.