ztk::animate
Moves options of a widget or of canvas items from their current values to new values, with easing.
Synopsis
ztk::animate TARGET ?-OPTION VALUE ...? ?-duration MS? ?-easing EASING? ?-delay MS? ?-repeat COUNT? ?-command SCRIPT?
ztk::animate cancel|pause|resume ID
ztk::animate info ?ID?
ztk::animate reduce ?BOOLEAN?
Arguments
| Name | Type | Default | Meaning |
|---|---|---|---|
TARGET |
widget path, or {CANVAS TAGORID} |
The widget, or the items of a canvas. | |
-OPTION VALUE |
option of the target | An end value. A color moves in sRGB, a distance or an integer moves as a rounded number, and another option with a number value moves as a number. | |
-duration |
milliseconds | 300 | The time of one run. A spring easing sets its own time. |
-easing |
easing | ease |
linear, ease, ease-in, ease-out, ease-in-out, {cubic-bezier X1 Y1 X2 Y2}, {steps N ?jump-start|jump-end|jump-none|jump-both?}, or {spring ?STIFFNESS? ?DAMPING? ?MASS?} (default 100 10 1). |
-delay |
milliseconds | 0 | The wait before the first run. |
-repeat |
count | 1 | The count of runs. 0 repeats with no end. |
-command |
script | empty | Runs as an idle callback after the frame that shows the end value. |
cancel ID |
subcommand | Stops the animation. The option keeps the value on the screen. | |
pause ID |
subcommand | Stops the clock of the animation. | |
resume ID |
subcommand | Starts the clock of a paused animation again. | |
info ?ID? |
subcommand | With no ID, gives the ids of the running animations. With an ID, gives a dict of -target, -state (waiting, running, or paused), and -elapsed in milliseconds. |
|
reduce ?BOOLEAN? |
subcommand | the setting of the system | 1 shows each end value at once. With no value, gives the current state. |
A new animation of an option starts from the value on the screen, and the old animation of that option stops.
Return value
A new animation gives its id, such as anim#1. info gives a list or a dict. reduce gives 0 or 1. cancel, pause, and resume give an empty string.
Errors
| Error | When |
|---|---|
bad window path name "W" |
No widget has the name. |
unknown option "-X" |
The widget has no such option. |
can't animate -OPTION to "V" |
The end value is no color or number. |
no option to animate |
The call has no option of the widget. |
value for "-X" missing |
An option with no value. |
expected a count of 0 or more but got "N" |
A negative -duration, -delay, or -repeat. |
bad easing "X": must be linear, ease, ease-in, ease-out, ease-in-out, cubic-bezier, steps, or spring |
An unknown easing. |
cubic-bezier needs 4 numbers, steps needs a count |
An easing with too few numbers. |
animation "ID" doesn't exist |
cancel, pause, resume, or info of an unknown id. |
bad option "X": must be a window path, cancel, info, pause, reduce, or resume |
An unknown subcommand. |
Platforms
| Platform | Works |
|---|---|
| Windows | Yes |
| macOS | Yes |
| Linux, Wayland | Yes |
| Linux, X11 | Yes |
| Web | Yes. The browser setting prefers-reduced-motion turns on reduce. |
| iOS, Android | Yes |
| Headless | Yes. ztk::clock set moves the time. |
Example
label .l -text Hello -background #dbeafe
pack .l -padx 20 -pady 20
set id [ztk::animate .l -background #2563eb -foreground white -duration 400 -easing ease-out]
dict get [ztk::animate info $id] -state