Switched to released easing-function

Also added new easings example.
This commit is contained in:
Jonathan Johnson 2024-08-18 10:58:44 -07:00
parent 18d14a0275
commit 7bd79b0662
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 85 additions and 2 deletions

3
Cargo.lock generated
View file

@ -762,7 +762,8 @@ checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53"
[[package]]
name = "easing-function"
version = "0.1.0"
source = "git+https://github.com/khonsulabs/easing-function#12a233464b0142d86c68d474598befa1d0298031"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5699e572f2ece3d6ea49a528341097d26117751ea0a8ed3adab747bb6e96c480"
[[package]]
name = "either"

View file

@ -48,7 +48,7 @@ image = { version = "0.25.0", features = ["png"] }
plotters = { version = "0.3.5", default-features = false, optional = true }
nominals = "0.3.0"
parking_lot = "0.12.1"
easing-function = { git = "https://github.com/khonsulabs/easing-function" }
easing-function = "0.1.0"
# [patch.crates-io]

82
examples/easings.rs Normal file
View file

@ -0,0 +1,82 @@
use cushy::animation::easings::StandardEasing;
use cushy::context::GraphicsContext;
use cushy::widget::{MakeWidget, WidgetList};
use cushy::widgets::Canvas;
use cushy::Run;
use easing_function::Easing;
use figures::units::{Lp, Px};
use figures::{IntoSigned, Point, Rect, Size, Zero};
use kludgine::shapes::{PathBuilder, Shape, StrokeOptions};
fn main() -> cushy::Result {
StandardEasing::all()
.iter()
.map(|easing| {
let name = format!("Ease{easing:?}");
Canvas::new(|context| {
draw_easing_graph(easing, context);
})
.expand()
.and(name)
.into_rows()
.contain()
.make_widget()
})
.collect::<Vec<_>>()
.chunks(3)
.map(|widgets| {
WidgetList::from_iter(widgets.iter().map(|w| w.clone().expand()))
.into_columns()
.height(Lp::inches(3))
})
.collect::<WidgetList>()
.into_wrap()
.pad()
.vertical_scroll()
.expand()
.run()
}
fn draw_easing_graph(easing: &StandardEasing, context: &mut GraphicsContext<'_, '_, '_, '_>) {
let height = context.gfx.size().height.into_signed();
let padding = height / 4;
let height = height - padding * 2;
let width = context.gfx.size().width.into_signed().get();
let steps = width.max(50);
let mut path = PathBuilder::new(Point::new(
Px::ZERO,
padding + height * (1.0 - easing.ease(0.)),
));
for i in 1..=steps {
path = path.line_to(Point::new(
Px::new(width * i) / steps,
padding + height * (1.0 - easing.ease(i as f32 / steps as f32)),
));
}
let text_color = context.theme().surface.on_color;
let bg = context.theme().surface.low_container;
let outline = context.theme().surface.outline;
context.gfx.draw_shape(&Shape::filled_rect(
Rect::new(
Point::new(Px::ZERO, padding),
Size::new(Px::new(width), height),
),
bg,
));
context.gfx.draw_shape(&Shape::stroked_rect(
Rect::new(
Point::new(Px::ZERO, padding),
Size::new(Px::new(width), height),
),
outline,
));
context.gfx.draw_shape(
&path
.build()
.stroke(StrokeOptions::px_wide(1).colored(text_color)),
);
}