StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use std::time::Duration; |
| 2 | use strato_core::inspector::{inspector, InspectorConfig}; |
| 3 | use strato_core::state::Signal; |
| 4 | use strato_core::types::Color; |
| 5 | use strato_platform::{ApplicationBuilder, WindowBuilder}; |
| 6 | use strato_widgets::animation::{Curve, KeyframeAnimation, Parallel, Timeline, Tween}; |
| 7 | use strato_widgets::prelude::*; |
| 8 | use strato_widgets::scroll_view::ScrollView; |
| 9 | use strato_widgets::InspectorOverlay; |
| 10 | |
| 11 | #[tokio::main] |
| 12 | async fn main() -> anyhow::Result<()> { |
| 13 | tracing_subscriber::fmt::init(); |
| 14 | |
| 15 | inspector().configure(InspectorConfig { |
| 16 | enabled: true, |
| 17 | ..Default::default() |
| 18 | }); |
| 19 | |
| 20 | // Create state for animation targets |
| 21 | let box_color = Signal::new(Color::RED); |
| 22 | let box_width = Signal::new(100.0); |
| 23 | |
| 24 | // Create a ScrollView content |
| 25 | let mut list = Column::new().spacing(10.0); |
| 26 | for i in 0..20 { |
| 27 | list = list.child(Box::new( |
| 28 | Container::new() |
| 29 | .padding(20.0) |
| 30 | .background(if i % 2 == 0 { |
| 31 | Color::rgba(0.2, 0.2, 0.2, 1.0) |
| 32 | } else { |
| 33 | Color::rgba(0.3, 0.3, 0.3, 1.0) |
| 34 | }) |
| 35 | .child(Text::new(format!("Scroll Item {}", i)).color(Color::WHITE)), |
| 36 | )); |
| 37 | } |
| 38 | |
| 39 | let scroll_view = ScrollView::new(list); |
| 40 | |
| 41 | // Setup animation |
| 42 | let mut timeline = Timeline::new(); |
| 43 | |
| 44 | // Animation 1: Change color Red -> Blue |
| 45 | let color_anim = KeyframeAnimation::new( |
| 46 | Duration::from_secs(2), |
| 47 | Tween::new(Color::RED, Color::BLUE), |
| 48 | box_color.clone(), |
| 49 | ) |
| 50 | .with_curve(Curve::EaseInOut); |
| 51 | |
| 52 | // Animation 2: Change width 100 -> 300 |
| 53 | let width_anim = KeyframeAnimation::new( |
| 54 | Duration::from_secs(2), |
| 55 | Tween::new(100.0, 300.0), |
| 56 | box_width.clone(), |
| 57 | ) |
| 58 | .with_curve(Curve::EaseOut); |
| 59 | |
| 60 | // Run parallel |
| 61 | let parallel = Parallel::new(vec![Box::new(color_anim), Box::new(width_anim)]); |
| 62 | |
| 63 | timeline.add(parallel); |
| 64 | timeline.play(); |
| 65 | |
| 66 | ApplicationBuilder::new() |
| 67 | .title("Animated Showcase") |
| 68 | .window(WindowBuilder::new().with_size(1024.0, 768.0)) |
| 69 | .run(InspectorOverlay::new( |
| 70 | Container::new().child( |
| 71 | Row::new().child(Box::new(scroll_view)).child(Box::new( |
| 72 | Container::new() |
| 73 | .width(300.0) |
| 74 | .background(Color::BLACK) |
| 75 | .child(Text::new("Animation Placeholder")), |
| 76 | )), |
| 77 | ), |
| 78 | )); |
| 79 | } |
| 80 |