Hi Garmin,
What is the current state of WatchUi.animate(...)? Does it work yet? If so, do you have a working example?
/Tonny
//! Restore the state of the app and prepare the view to be shown
function onShow() {
var drawable = findDrawableById("id_monkey");
Ui.animate(drawable, :locX, Ui.ANIM_TYPE_EASE_IN, 50, 200, 5.4, method(:onDone));
}
function onExitSleep() {
var drawable = findDrawableById("TimeLabel");
Ui.animate(drawable, :locX, Ui.ANIM_TYPE_EASE_IN, 0, screenWidth/2, 2.5, null);
}
<layout id="CircleA">
<label x="102" y="74" /><!--position-->
<label x="15" y="1" /><!--radius/fill-->
</layout>
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Lang as Lang;
class MyCircle extends Ui.Drawable
{
hidden var radius;
hidden var fill;
hidden var color;
function initialize(params) {
Ui.Drawable.initialize(params);
radius = params.get(:radius);
if (radius == null) {
radius = 10;
}
fill = params.get(:fill);
if (fill == null) {
fill = false;
}
color = params.get(:color);
if (color == null) {
color = Gfx.COLOR_WHITE;
}
}
function draw(dc) {
dc.setColor(color, Gfx.COLOR_TRANSPARENT);
if (fill) {
dc.fillCircle(radius, locY, locX);
}
else {
dc.drawCircle(radius, locY, locX);
}
}
}
class AnimateView extends Ui.WatchFace {
var drawable;
var screenWidth;
var screenHeight;
//! Load your resources here
function onLayout(dc) {
var layout = Rez.Layouts.CircleA(dc);
screenWidth=dc.getWidth();
screenHeight=dc.getHeight();
var x = layout[0].locX;
var y = layout[0].locY;
var radius = layout[1].locX;
var fill = layout[1].locY;
drawable = new MyCircle({
:locX => radius,
:locY => y,
:radius => x,
:fill => fill,
:color => Gfx.COLOR_RED
});
}
//! Restore the state of the app and prepare the view to be shown
function onShow() {
}
//! Update the view
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.clear();
drawable.draw(dc);
}
//! The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() {
Ui.animate(drawable, :locX, Ui.ANIM_TYPE_EASE_IN, 10, screenWidth/2, 1.4, null);
}
//! Terminate any active timers and prepare for slow updates.
function onEnterSleep() {
}
}
class AnimationOverloadView extends Ui.WatchFace {
var drawable;
var screenWidth;
var screenHeight;
var beginSize;
var endSize;
var pulsateDirection = true;
//! Load your resources here
function onLayout(dc) {
var layout = Rez.Layouts.CircleA(dc);
screenWidth=dc.getWidth();
screenHeight=dc.getHeight();
var x = layout[0].locX;
var y = layout[0].locY;
var radius = layout[1].locX;
var fill = layout[1].locY;
drawable = new MyCircle({
:locX => radius,
:locY => y,
:radius => x,
:fill => fill,
:color => Gfx.COLOR_RED
});
beginSize = 15;
endSize = screenWidth/2;
changeDir();
}
//! Restore the state of the app and prepare the view to be shown
function onShow() {
}
//! Update the view
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.clear();
// Get and show the current time
var clockTime = Sys.getClockTime();
drawable.draw(dc);
}
function changeDir(){
pulsateDirection = !pulsateDirection;
if(pulsateDirection){
beginSize = screenWidth/2;
endSize = 15;
}else{
beginSize = 15;
endSize = screenWidth/2;
}
Ui.animate(drawable, :locX, Ui.ANIM_TYPE_EASE_IN, beginSize, endSize, 3.91, method(:changeDir));
}
//! The user has just looked at their watch. Timers and animations may be started here.
function onExitSleep() {
changeDir();
}
//! Terminate any active timers and prepare for slow updates.
function onEnterSleep() {
}
}
function draw(dc) {
//to manually clear around the circle when it shrinks
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.fillCircle(radius, locY, locX+20);
dc.setColor(color, Gfx.COLOR_TRANSPARENT);
if (fill) {
dc.fillCircle(radius, locY, locX);
}
else {
dc.drawCircle(radius, locY, locX);
}
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT);
dc.drawText(radius, locY, Gfx.FONT_NUMBER_MILD, locX.format("%.2f"), Gfx.TEXT_JUSTIFY_CENTER|Gfx.TEXT_JUSTIFY_VCENTER);
}
I created a new widget and added this code to make the image slide across the screen.//! Restore the state of the app and prepare the view to be shown
function onShow() {
var drawable = findDrawableById("id_monkey");
Ui.animate(drawable, :locX, Ui.ANIM_TYPE_EASE_IN, 50, 200, 5.4, method(:onDone));
}
You can animate any variable of the Drawable class, though typically it'll either be :locX or :locY. The duration is listed as a Number in the documentation, but it is actually a float. The callback you pass will be called when the animation is complete.
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_TRANSPARENT);
dc.clear();
drawable.draw(dc);
dc.drawText(100, 25, Gfx.FONT_NUMBER_HOT, Lang.format("$1$", [ drawable.locX.format("%0.2f")]), Gfx.TEXT_JUSTIFY_LEFT);
}