Repository navigation
Motion Containers
The motion() element gives content declarative enter and exit animations. Use it for animated lists,
page transitions, and conditional rendering. When the content appears, its enter animation starts. Your code starts an exit animation.
use blinc::layout::motion::motion;
motion()
.fade_in(300) // Duration in milliseconds
.child(my_content())motion()
.fade_in(300)
.fade_out(200)
.child(content)motion()
.scale_in(300) // Scale from 0 to 1
.scale_out(200) // Scale from 1 to 0
.child(content)use blinc::layout::motion::SlideDirection;
motion()
.slide_in(SlideDirection::Left, 300)
.slide_out(SlideDirection::Right, 200)
.child(content)
// Available directions:
// SlideDirection::Top
// SlideDirection::Bottom
// SlideDirection::Left
// SlideDirection::Rightmotion()
.bounce_in(400) // Bouncy entrance
.bounce_out(200)
.child(content)motion()
.pop_in(300) // Scale with overshoot
.child(content)There is no pop_out.
If the content goes away, its exit animation does not play. To start the animation, find the
motion by its key and call exit():
use blinc::layout::selector::query_motion;
let panel = motion().fade_in(300).fade_out(200).child(content);
let key = panel.get_stable_key().to_string();
// Later, for example in a click handler:
query_motion(&key).exit();A motion has one enter animation and one exit animation. If you call two enter methods, the second one replaces the first. You can set one of each:
motion()
.scale_in(300)
.fade_out(200)
.child(content)You can animate list items with a delay between each item and the next:
use blinc::animation::AnimationPreset;
use blinc::layout::motion::{motion, StaggerConfig};
let items = vec!["Item 1", "Item 2", "Item 3", "Item 4"];
motion()
.stagger(
StaggerConfig::new(100, AnimationPreset::fade_in(300))
)
.children(
items.iter().map(|item| {
div()
.p(3.0)
.bg(Color::rgba(0.2, 0.2, 0.25, 1.0))
.child(text(*item).color(Color::WHITE))
})
)let delay_ms = 100;
let preset = AnimationPreset::fade_in(300);
StaggerConfig::new(delay_ms, preset)
.reverse() // Animate last to first
.from_center() // Animate from center outward
.limit(10) // Only stagger first N itemslet preset = || AnimationPreset::fade_in(300);
// Forward (default): 0, 1, 2, 3, 4...
StaggerConfig::new(100, preset());
// Reverse: 4, 3, 2, 1, 0...
StaggerConfig::new(100, preset()).reverse();
// From center: 2, 1/3, 0/4 (for 5 items)
StaggerConfig::new(100, preset()).from_center();For continuous control of an animation, bind motion transforms to AnimatedValue:
use blinc::animation::SpringConfig;
use blinc::app::windowed::WindowedContext;
fn pull_to_refresh(ctx: &WindowedContext) -> impl ElementBuilder {
let offset_y = ctx.use_animated_value(0.0, SpringConfig::wobbly());
let icon_scale = ctx.use_animated_value(0.5, SpringConfig::snappy());
let icon_opacity = ctx.use_animated_value(0.0, SpringConfig::snappy());
stack()
// Refresh icon (behind content)
.child(
motion()
.scale(icon_scale.clone())
.opacity(icon_opacity.clone())
.child(refresh_icon())
)
// Content (translates down to reveal icon)
.child(
motion()
.translate_y(offset_y.clone())
.child(content_list())
)
}The button changes a signal. While the signal is true, show builds the cards. Each time the cards
appear, they come in one after the other.
use blinc::animation::AnimationPreset;
use blinc::layout::motion::{motion, StaggerConfig};
use blinc::prelude::*;
fn animated_card_list(show_cards: Signal<bool>) -> impl ElementBuilder {
let toggle = stateful::<ButtonState>()
.deps([show_cards.id()])
.on_state(move |ctx| {
let label = if show_cards.get() { "Hide Cards" } else { "Show Cards" };
let bg = match ctx.state() {
ButtonState::Hovered => Color::rgba(0.4, 0.6, 1.0, 1.0),
_ => Color::rgba(0.3, 0.5, 0.9, 1.0),
};
div().bg(bg).px(4.0).py(2.0).rounded(8.0)
.child(text(label).color(Color::WHITE))
})
.on_click(move |_| show_cards.update(|shown| !shown));
div()
.flex_col()
.gap(4.0)
.child(toggle)
.child(div().show(show_cards, card_list))
}
fn card_list() -> Motion {
// Cards with staggered animation
motion()
.transient()
.stagger(StaggerConfig::new(80, AnimationPreset::fade_in(300)))
.children((0..5).map(|i| {
div()
.w(300.0)
.p(4.0)
.rounded(12.0)
.bg(Color::rgba(0.15, 0.15, 0.2, 1.0))
.child(text(format!("Card {}", i + 1)).color(Color::WHITE))
}))
}For page navigation, use a signal. When the signal changes, build the page again. transient() makes the enter animation
play each time.
use blinc::layout::motion::{motion, SlideDirection};
use blinc::prelude::*;
fn page_transition(current_page: Signal<u8>) -> impl ElementBuilder {
stateful::<NoState>()
.deps([current_page.id()])
.on_state(move |_ctx| {
// Render different content based on the current page signal
let content = match current_page.get() {
0 => div().child(text("Home Page").color(Color::WHITE)),
1 => div().child(text("Settings Page").color(Color::WHITE)),
_ => div().child(text("Profile Page").color(Color::WHITE)),
};
div().w_full().h_full().child(
motion()
.transient()
.slide_in(SlideDirection::Right, 200)
.child(content),
)
})
}
// Navigate with the shared signal
fn nav_button(current_page: Signal<u8>, target: u8, label: &'static str) -> impl ElementBuilder {
stateful::<ButtonState>()
.on_state(move |ctx| {
let bg = match ctx.state() {
ButtonState::Hovered => Color::rgba(0.4, 0.6, 1.0, 1.0),
_ => Color::rgba(0.3, 0.5, 0.9, 1.0),
};
div().bg(bg).px(4.0).py(2.0).rounded(8.0)
.child(text(label).color(Color::WHITE))
})
.on_click(move |_| current_page.set(target))
}| Feature | Motion | AnimatedValue |
|---|---|---|
| Setup | Declarative | Imperative |
| Control | Preset-based | Full control |
| Enter/Exit | Enter automatic, exit from your code | Manual |
| Lists | Stagger support | Manual delays |
| Use case | Transitions | Interactive |
Use motion for:
- List item animations
- Page transitions
- Conditional content
- Staggered reveals
Use AnimatedValue for:
- Drag interactions
- Hover effects
- Custom physics
- Continuous binding
Getting Started
Migrating
Mobile Development
Example Gallery
- Example Gallery
- Canvas Element
- Canvas Kit Interactive
- Carousel Demo - Selector API Showcase
- Chrome-Style Tabs
- blinc_cn Components
- Run with
cargo run -p blinc_app_examples --features cn --example cn_pickers_demo. - Code Element
- Complex SVG
- CSS Debug
- CSS Visual Features
- Layer Effects
- Emoji and HTML Entities
- @flow Shader
- Fluid Surface
- Skeleton animation with glTF +
blinc_canvas_kit. - Gpu Pass Demo
- Image CSS Styling
- Image Layer Test
- Keyframe Animation Canvas
- Markdown Editor
- 3D Mesh Demo — renders the Khronos glTF
DamagedHelmetsample model - Motion Demo
- Music Player Glass Card
- Node-editor demo — pre-wired graph with three node types, typed
- Notch Menu Bar
- Overflow Fade
- Overlay System
- Pointer Query
- Rich Text Element
- Rich Text Editor
- Scroll Container
- Semantic @flow
- Sortable
- Stateful API + Signal-bound modifiers demo.
- End-to-end 3D demo wiring Blinc's SceneKit3D renderer up to
- Unified Styling API
- SVG Animation
- Table Builder
- Tabler Icons
- Minimal text positioning test
- Text Input Widgets
- KHR_texture_transform
- Theme System
- Timeline Animation
- Typography
- Wet Glass
- Windowed Application
Web Development
Core Concepts
- Elements & Layout
- Styling & Materials
- CSS Styling
- Theming
- Event Handling
- Accessibility
- State Management
- Lists & Conditional Content
- Element Refs
Animation
Components
Component Library (blinc_cn)
- Overview
- Button
- Card
- Icons
- Typography
- Dialog
- Form Components
- Date, Time and Colour Pickers
- Rich Text Editor
- Code Editor
- Navigation
- Feedback
- Layout
- Data Display
Widgets
- Buttons & Inputs
- Text & Rich Text
- Code Editor
- Scroll Containers
- Virtualized List
- Canvas Drawing
- Gestures
- Notched Surfaces
- Images & SVG
- Audio & Video
- Markdown Rendering
Canvas Kit
Advanced
- Routing & Navigation
- Multi-Window
- System Integration
- Element Query API
- Overlay System
- Custom State Machines
- Pointer Query
- Performance Tips
- Flow Shaders
- 3D Rendering
- Custom GPU Passes
- Hot reloading
Architecture
Contributing