cushy/examples/offscreen-apng.rs
Jonathan Johnson a197bb5e81
Unit-tested, auto-generated screenshots
This commit adds my first take at creating a harness for a user's guide
using the new capture functionality. The example has tests that ensure
the align widget creates the expected results.
2024-01-04 13:56:45 -08:00

36 lines
1.1 KiB
Rust

use std::time::Duration;
use cushy::animation::easings::EaseInOutSine;
use cushy::widget::MakeWidget;
use figures::units::Px;
use figures::{Point, Size};
fn ui() -> impl MakeWidget {
"Hello World".into_button().centered()
}
fn main() {
let mut recorder = ui()
.build_recorder()
.size(Size::new(320, 240))
.finish()
.unwrap();
let initial_point = Point::new(Px::new(140), Px::new(150));
recorder.set_cursor_position(initial_point);
recorder.set_cursor_visible(true);
recorder.refresh().unwrap();
let mut animation = recorder.record_animated_png(60);
animation
.animate_cursor_to(
Point::new(Px::new(160), Px::new(120)),
Duration::from_millis(250),
EaseInOutSine,
)
.unwrap();
animation.wait_for(Duration::from_millis(500)).unwrap();
animation
.animate_cursor_to(initial_point, Duration::from_millis(250), EaseInOutSine)
.unwrap();
animation.wait_for(Duration::from_millis(500)).unwrap();
animation.write_to("examples/offscreen-apng.png").unwrap();
}