egui_animated_selectable_value/
lib.rs

1//! **This crate is in alpha, not yet intended for production use. Some parts of documentation are missing for now**
2//!
3//! This crate lets you easily create selectable values similiar to the [ones built into egui](egui::Ui::selectable_value),
4//! but animated.
5//!
6//! You will most often use the [`begin_animated_selectable_value`] function to create a selectable value. See its docs for quickstart
7
8use std::hash::Hash;
9
10use egui::{emath::easing, Button, Color32, Id, Pos2, Rect, RichText, Shape, Stroke, WidgetText};
11use egui_animation::animate_eased;
12
13pub mod animated_frame;
14pub mod selectable_value;
15pub use animated_frame::AnimatedFrame;
16pub use selectable_value::begin as begin_animated_selectable_value;
17
18pub mod prelude {
19    pub use super::begin_animated_selectable_value;
20}
21
22pub fn animate_rect_with_time(
23    ctx: &egui::Context,
24    id: Id,
25    target_value: Rect,
26    animation_time: f32,
27) -> Rect {
28    let min_x = animate_eased(
29        ctx,
30        id.with("animate_rect_with_time, min.x"),
31        target_value.min.x,
32        animation_time,
33        easing::circular_in_out,
34    );
35    let min_y = animate_eased(
36        ctx,
37        id.with("animate_rect_with_time, min.y"),
38        target_value.min.y,
39        animation_time,
40        easing::circular_in_out,
41    );
42    let max_x = animate_eased(
43        ctx,
44        id.with("animate_rect_with_time, max.x"),
45        target_value.max.x,
46        animation_time,
47        easing::circular_in_out,
48    );
49    let max_y = animate_eased(
50        ctx,
51        id.with("animate_rect_with_time, max.y"),
52        target_value.max.y,
53        animation_time,
54        easing::circular_in_out,
55    );
56
57    Rect {
58        min: Pos2 { x: min_x, y: min_y },
59        max: Pos2 { x: max_x, y: max_y },
60    }
61}