Layout and animation¶
Build elements¶
Use XML for visuals and animation composition. Attributes accept strings,
{expressions}, or bare utilities:
let card = <Box w-240 h-100 rounded-lg fill="blue3" flex items-center justify-center>
<Label>Hello</Label>
</Box>
Box is an unstyled container: transparent, full available width, automatic
height, vertical child flow. Use flex flex-row or flex flex-col for
flex layout. Explicit attributes override utilities.
Animate in order¶
Unassigned top-level animations run in order. Assigned animations are stored for later; functions return animations without playing them.
let title = <Label>Hello</Label>
title.fade_in()
title.move_to([120pt, 0pt], duration=1s)
wait(1s)
title.fade_out()
Run together¶
<Animation> runs its children in parallel. Set flow="sequence" to run
them in order. Include a visual child to display it immediately.
let title = <Label>Hello</Label>
<Animation>
{title.fade_in(duration=1s)}
{title.move_to([120pt, 0pt], duration=1s)}
</Animation>
Animation methods¶
Methods below are called on an Element or List<Element> and return
Animation. Each accepts duration: Duration = 300ms and ease: String.
The default ease is "spring" for motion/size, "smootherstep" for
fade/fill/reveal.
element.fade_in(duration: Duration = 300ms, ease: String = "smootherstep"): Animation
element.fade_out(duration: Duration = 300ms, ease: String = "smootherstep"): Animation
element.move_to(to: List<Length, 2> | List<Percent, 2>, duration: Duration = 300ms, ease: String = "spring"): Animation
Other methods take the same timing options:
Method and extra arguments |
Effect |
|---|---|
|
Add a relative offset. |
|
Set rotation or scale. |
|
Change fill color. |
|
Reveal/erase a vector path. |
|
Trace outlines, then fill/erase. |
|
Scale a centered, unrotated element with fixed sizing. |
|
Reveal horizontal extent from an origin. |
|
Set horizontal scale around an origin. |
wait(duration: Duration | Forever): Animation
animate<T>(target: mut T, to: T, duration: Duration, ease: String = "spring"): Animation
animation.repeat(count: Number | Forever): Animation
animate changes a mutable input and updates its dependent signals.
Alternatively pass curve= instead of to= (Curves). Overlapping
writers to the same property are errors. Tracks hold their final value.
wait(forever) holds indefinitely; repeat(forever) repeats a finite,
positive cycle. Other durations must be finite and at most two hours.
Layout and timing options¶
Sizes:
w-N,h-N,w-full,h-full; numbers are points.96px == 72pt. Percentages resolve against the parent.Placement:
position={[x, y]},x_align/y_alignusingAlign.Start,Align.Center,Align.End.Boxdefaults to start; other shapes default to center. Useabsoluteto opt out of child flow.Flex:
items-start/center/end,justify-start/center/end/between/around,gap-N,p-N,grow,shrink,basis-N.Appearance:
fill,rounded-N,rounded-full,border-N,bg-COLOR; gradient utilitiesbg-linear-to-r from-COLOR to-COLOR.<Animation>:duration={...}sets its time span;"auto"measures children and"match_parent"fills the parent.gap/paddinguse durations;justifydistributes spare time.position_mode="absolute"excludes a child from intrinsic duration.overflowclips by default.
The host controls canvas size, FPS and DPI. bg(Color(...)) sets the
background; its default is Adwaita window_bg_dark.
For animated list insertion/removal, bind children={items} and animate
that mutable list with animate. See Functions, Signals, and Lists for list operations,
Scrolling for overflow and Text wrapping for text layout.
Visual checks¶
assert(condition: Bool | Predicate, message?: String, at?: Duration): Unit
check(condition: Bool | Predicate, message?: String, at?: Duration): Unit
always(condition: Predicate): Predicate
inside_canvas(element: Element): Predicate
Relations include element.above(other, gap=0pt), below, left_of,
right_of, contains, overlaps, disjoint and touches. Visual
checks sample time zero unless at is given; always checks the whole
timeline. assert fails on refuted or unknown results; check records
them. Boolean checks run immediately and do not accept at.