Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/app/src/shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ impl ShotDriver {
if !self.pass_primed {
// Replay from an identical clean slate so a scene's light and dark
// captures differ only in palette, never in accumulated state.
*app = PlotiumApp::new_with_settings(Settings::default());
let mut settings = Settings::default();
// Captures land a fixed number of frames after each step, so
// sidebars and dialogs must not be caught mid-animation.
settings.appearance.reduce_motion = plotium_core::settings::ReduceMotion::On;
*app = PlotiumApp::new_with_settings(settings);
ctx.set_theme(self.themes[self.theme_idx].preference());
self.scene_idx = 0;
self.wait = SCENES[0].settle;
Expand Down
10 changes: 5 additions & 5 deletions crates/app/src/ui/data_sheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ pub(super) fn dock_rect(ctx: &egui::Context) -> Option<egui::Rect> {
ctx.data(|data| data.get_temp::<egui::Rect>(dock_rect_id()))
}

fn dock_margin(app: &PlotiumApp) -> egui::Margin {
fn dock_margin(ctx: &egui::Context) -> egui::Margin {
egui::Margin {
left: if app.session.primary_sidebar_visible {
left: if super::sidebars::reserves_space(ctx, true) {
8
} else {
4
},
right: if app.session.secondary_sidebar_visible {
right: if super::sidebars::reserves_space(ctx, false) {
8
} else {
4
Expand Down Expand Up @@ -119,7 +119,7 @@ fn dock_sheet(
derived_from: None,
};
let mut panel = shown_panel(app, ui.ctx(), was_shown, None);
let margin = dock_margin(app);
let margin = dock_margin(ui.ctx());
let response = dock::show(ui, &mut panel, margin, dark, &header, |ui| {
draft::controls(ui, &mut app.session.ui.table_cell_edit, None);
});
Expand Down Expand Up @@ -184,7 +184,7 @@ fn dock_sheet(
was_shown,
Some(app.doc.datasets[di].resource_id()),
);
let margin = dock_margin(app);
let margin = dock_margin(ui.ctx());
let response = dock::show(ui, &mut panel, margin, dark, &header, |ui| {
if matches!(
freshness.status,
Expand Down
25 changes: 25 additions & 0 deletions crates/app/src/ui/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub(crate) const HOVER_SECONDS: f32 = 0.10;
pub(crate) const APPEAR_SECONDS: f32 = 0.16;
/// Scale a dialog grows from while it fades in.
pub(crate) const APPEAR_SCALE_FROM: f32 = 0.96;
/// Sidebars sliding in and out.
pub(crate) const SLIDE_SECONDS: f32 = 0.20;
/// Spring period in seconds and damping ratio for sliding selections and
/// board camera glides.
const SPRING_RESPONSE: f32 = 0.34;
Expand Down Expand Up @@ -171,6 +173,29 @@ pub(crate) fn hover(ctx: &egui::Context, id: Id, hovered: bool) -> f32 {
ctx.animate_bool_with_time(id.with("hover").with(ctx.viewport_id()), hovered, seconds)
}

/// Eased fraction of a sliding surface that is shown, from 0 (closed) to 1
/// (open). The first call for `id` lands on `open` without moving. The easing
/// is symmetric, so reversing mid-slide continues from the current position.
pub(crate) fn slide(ctx: &egui::Context, id: Id, open: bool) -> f32 {
let seconds = if reduced(ctx) { 0.0 } else { SLIDE_SECONDS };
ctx.animate_bool_with_time_and_easing(
slide_key(ctx, id),
open,
seconds,
egui::emath::easing::cubic_in_out,
)
}

/// Lands a slide on `open` at once, for a surface the user already moved
/// there directly.
pub(crate) fn land_slide(ctx: &egui::Context, id: Id, open: bool) {
ctx.animate_bool_with_time(slide_key(ctx, id), open, 0.0);
}

fn slide_key(ctx: &egui::Context, id: Id) -> Id {
id.with("slide").with(ctx.viewport_id())
}

/// Eased progress from 0 to 1 since the surface `id` started showing. A
/// surface counts as newly shown when it was absent on the previous pass.
pub(crate) fn appear(ctx: &egui::Context, id: Id) -> f32 {
Expand Down
24 changes: 24 additions & 0 deletions crates/app/src/ui/motion_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,27 @@ fn scale_about_keeps_the_pivot_fixed() {
assert_eq!(transform * pivot, pivot);
assert_eq!(transform * egui::pos2(200.0, 50.0), egui::pos2(150.0, 50.0));
}

#[test]
fn reversing_a_slide_continues_from_where_it_is() {
let ctx = egui::Context::default();
let id = Id::new("test_slide");
let mut time = 0.0;
let mut step = |open: bool| {
time += 1.0 / 60.0;
let mut shown = 0.0;
pass(&ctx, time, |ctx| shown = slide(ctx, id, open));
shown
};
step(false);
let mut last = step(true);
for _ in 0..4 {
last = step(true);
}
assert!(last > 0.0 && last < 1.0, "{last}");
let reversed = step(false);
assert!(
reversed < last && last - reversed < 0.2,
"{last} -> {reversed}"
);
}
Loading
Loading