Creating a new watchface from Visual Code and the code snippet from https://developer.garmin.com/connect-iq/core-topics/complications/ displays "Obj:' and an associated object number.
I've looked at ComplexWF from jim_m_58, https://forums.garmin.com/developer/connect-iq/f/discussion/349473/simple-example-wf-that-shows-a-bunch-of-things. It's a great example but I would like to build a watchface from scratch and better understand complications.
I could not use the insert code function from the forum so I pasted my code below.
Why does this code compile and show "Obj: 166" on the simulator and a real device?
import Toybox.Application;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
import Toybox.Complications;
class CaloriesCompView extends WatchUi.WatchFace {
function initialize() {
WatchFace.initialize();
}
// Load your resources here
function onLayout(dc as Dc) as Void {
setLayout(Rez.Layouts.WatchFace(dc));
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() as Void {
}
// Update the view
function onUpdate(dc as Dc) as Void {
// Get the current time and format it correctly
var timeFormat = "$1$:$2$";
var clockTime = System.getClockTime();
var hours = clockTime.hour;
if (!System.getDeviceSettings().is24Hour) {
if (hours > 12) {
hours = hours - 12;
}
} else {
if (getApp().getProperty("UseMilitaryFormat")) {
timeFormat = "$1$$2$";
hours = hours.format("%02d");
}
}
var timeString = Lang.format(timeFormat, [hours, clockTime.min.format("%02d")]);
// Update the view
var view = View.findDrawableById("TimeLabel") as Text;
view.setColor(getApp().getProperty("ForegroundColor") as Number);
view.setText(timeString);
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
// Get device width and height
var MyW = dc.getWidth();
var MyH = dc.getHeight();
// Code from developer.garmin.com/.../
var cals = Complications.getComplication(
new Id(Complications.COMPLICATION_TYPE_CALORIES)
);
// Print cals
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.drawText(MyW*.5, MyH*.6, Graphics.FONT_MEDIUM, cals, Graphics.TEXT_JUSTIFY_CENTER);
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() as Void {
}
// The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() as Void {
}
// Terminate any active timers and prepare for slow updates.
function onEnterSleep() as Void {
}
}