diff --git a/crates/app/src/shot.rs b/crates/app/src/shot.rs index 97655e1f..cbd73e7b 100644 --- a/crates/app/src/shot.rs +++ b/crates/app/src/shot.rs @@ -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; diff --git a/crates/app/src/ui/data_sheet.rs b/crates/app/src/ui/data_sheet.rs index 570310c9..623a224f 100644 --- a/crates/app/src/ui/data_sheet.rs +++ b/crates/app/src/ui/data_sheet.rs @@ -58,14 +58,14 @@ pub(super) fn dock_rect(ctx: &egui::Context) -> Option { ctx.data(|data| data.get_temp::(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 @@ -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); }); @@ -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, diff --git a/crates/app/src/ui/motion.rs b/crates/app/src/ui/motion.rs index caf3f1f2..cad3ffdf 100644 --- a/crates/app/src/ui/motion.rs +++ b/crates/app/src/ui/motion.rs @@ -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; @@ -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 { diff --git a/crates/app/src/ui/motion_tests.rs b/crates/app/src/ui/motion_tests.rs index 74daa8ba..e272ee2f 100644 --- a/crates/app/src/ui/motion_tests.rs +++ b/crates/app/src/ui/motion_tests.rs @@ -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}" + ); +} diff --git a/crates/app/src/ui/sidebars.rs b/crates/app/src/ui/sidebars.rs index 6fbe2ff5..b821e263 100644 --- a/crates/app/src/ui/sidebars.rs +++ b/crates/app/src/ui/sidebars.rs @@ -4,95 +4,254 @@ const MIN_WORKSPACE_WIDTH: f32 = 320.0; /// Logical pixels from the window's outer edge, independent of sidebar width. const HIDE_EDGE_DISTANCE: f32 = 24.0; +/// How a sidebar takes part in the frame's layout. +#[derive(Clone, Copy, Debug, PartialEq)] +enum Placement { + /// At rest beside the workspace, resizable. + Docked, + Hidden, + /// Sliding over the workspace with `shown` of its width in view. The + /// workspace keeps the layout it had when the slide began (`reserved`) + /// and lays out again once, when the slide ends, so a heavy canvas is + /// never re-laid out at every width in between. + Sliding { + shown: f32, + reserved: bool, + }, +} + +impl Placement { + fn resolve(visible: bool, shown: f32, was_reserved: bool) -> Self { + let settled = if visible { shown >= 1.0 } else { shown <= 0.0 }; + match (settled, visible) { + (true, true) => Self::Docked, + (true, false) => Self::Hidden, + (false, _) => Self::Sliding { + shown, + reserved: was_reserved, + }, + } + } + + fn reserves_space(self) -> bool { + matches!(self, Self::Docked | Self::Sliding { reserved: true, .. }) + } +} + pub(super) fn render(app: &mut PlotiumApp, ui: &mut Ui, dark: bool, workspace_width: f32) { - let mut primary_rect = None; - let mut secondary_rect = None; let compact = workspace_width < 1200.0; let inspector_visible = app.session.secondary_sidebar_visible; if !inspector_visible { app.finish_axis_overrides_edit(); } object_inspector::finish_series_edit_if_inactive(app, inspector_visible); - if app.session.primary_sidebar_visible { - let min_width = if compact { 150.0 } else { 190.0 }; - let other_width = if app.session.secondary_sidebar_visible { - app.session.secondary_sidebar_width - } else { - 0.0 - }; - let max_width = - (workspace_width - other_width - MIN_WORKSPACE_WIDTH).clamp(min_width, 420.0); - let panel = egui::Panel::left("primary_sidebar") - .frame(egui::Frame::NONE) - .show_separator_line(false) - .resizable(true) - .default_size( - app.session - .primary_sidebar_width - .clamp(min_width, max_width), - ) - .size_range(min_width..=max_width); - let response = show_sidebar(panel, app, ui, dark, true, min_width..=max_width); - paint_sidebar_resize_edge( - ui, - Id::new("primary_sidebar"), - response.inner, - SidebarEdge::Right, - dark, - ); - app.session.primary_sidebar_width = response.response.rect.width(); - primary_rect = Some(response.inner); - if resize_released_at_window_edge(ui.ctx(), Id::new("primary_sidebar"), SidebarEdge::Right) - { - app.session.primary_sidebar_visible = false; - sidebar_hidden_status(app, commands::CommandId::TogglePrimarySidebar, "Left"); - } + let primary_rect = render_side(app, ui, dark, workspace_width, compact, true); + let secondary_rect = render_side(app, ui, dark, workspace_width, compact, false); + super::workspace_geometry::set_sidebar_rects(ui.ctx(), primary_rect, secondary_rect); +} + +/// Shows one sidebar and returns the rectangle the workspace lays out around. +fn render_side( + app: &mut PlotiumApp, + ui: &mut Ui, + dark: bool, + workspace_width: f32, + compact: bool, + primary: bool, +) -> Option { + let id = sidebar_id(primary); + let session = &app.session; + let (visible, stored_width, other_width) = if primary { + ( + session.primary_sidebar_visible, + session.primary_sidebar_width, + session + .secondary_sidebar_visible + .then_some(session.secondary_sidebar_width), + ) } else { - // A shown panel consumes one auto-id slot from this ui. Burn the same - // slot while hidden so the later siblings' container ids (secondary - // panel, central panel) do not shift when a sidebar toggles. - ui.skip_ahead_auto_ids(1); + ( + session.secondary_sidebar_visible, + session.secondary_sidebar_width, + session + .primary_sidebar_visible + .then_some(session.primary_sidebar_width), + ) + }; + let shown = motion::slide(ui.ctx(), id, visible); + let was_reserved = reserves_space(ui.ctx(), primary); + let placement = Placement::resolve(visible, shown, was_reserved); + let reserved_id = reserved_id(ui.ctx(), primary); + ui.ctx() + .data_mut(|data| data.insert_temp(reserved_id, placement.reserves_space())); + + let (min_width, width_cap) = match (primary, compact) { + (true, true) => (150.0, 420.0), + (true, false) => (190.0, 420.0), + (false, true) => (180.0, 460.0), + (false, false) => (230.0, 460.0), + }; + let max_width = (workspace_width - other_width.unwrap_or(0.0) - MIN_WORKSPACE_WIDTH) + .clamp(min_width, width_cap); + let width = stored_width.clamp(min_width, max_width); + let panel = if primary { + egui::Panel::left("primary_sidebar") + } else { + egui::Panel::right("secondary_sidebar") } + .frame(egui::Frame::NONE) + .show_separator_line(false); + let edge = if primary { + SidebarEdge::Right + } else { + SidebarEdge::Left + }; - if app.session.secondary_sidebar_visible { - let min_width = if compact { 180.0 } else { 230.0 }; - let other_width = if app.session.primary_sidebar_visible { - app.session.primary_sidebar_width - } else { - 0.0 - }; - let max_width = - (workspace_width - other_width - MIN_WORKSPACE_WIDTH).clamp(min_width, 460.0); - let panel = egui::Panel::right("secondary_sidebar") - .frame(egui::Frame::NONE) - .show_separator_line(false) - .resizable(true) - .default_size( - app.session - .secondary_sidebar_width - .clamp(min_width, max_width), - ) - .size_range(min_width..=max_width); - let response = show_sidebar(panel, app, ui, dark, false, min_width..=max_width); - paint_sidebar_resize_edge( - ui, - Id::new("secondary_sidebar"), - response.inner, - SidebarEdge::Left, - dark, - ); - app.session.secondary_sidebar_width = response.response.rect.width(); - secondary_rect = Some(response.inner); - if resize_released_at_window_edge(ui.ctx(), Id::new("secondary_sidebar"), SidebarEdge::Left) - { - app.session.secondary_sidebar_visible = false; - sidebar_hidden_status(app, commands::CommandId::ToggleSecondarySidebar, "Right"); + match placement { + Placement::Hidden => { + prime_sliding_area(ui.ctx(), primary); + // A shown panel consumes one auto-id slot from this ui. Burn the + // same slot while hidden so the later siblings' container ids + // (secondary panel, central panel) do not shift when a sidebar + // toggles. + ui.skip_ahead_auto_ids(1); + None } + Placement::Docked => { + prime_sliding_area(ui.ctx(), primary); + let panel = panel + .resizable(true) + .default_size(width) + .size_range(min_width..=max_width); + let response = show_sidebar(panel, app, ui, dark, primary, min_width..=max_width); + paint_sidebar_resize_edge(ui, id, response.inner, edge, dark); + // Only a docked sidebar reports its width: the in-between widths + // of a slide are not the user's choice. + let actual = response.response.rect.width(); + if primary { + app.session.primary_sidebar_width = actual; + } else { + app.session.secondary_sidebar_width = actual; + } + if resize_released_at_window_edge(ui.ctx(), id, edge) { + // The user already dragged it to the edge; do not slide. + motion::land_slide(ui.ctx(), id, false); + if primary { + app.session.primary_sidebar_visible = false; + sidebar_hidden_status(app, commands::CommandId::TogglePrimarySidebar, "Left"); + } else { + app.session.secondary_sidebar_visible = false; + sidebar_hidden_status( + app, + commands::CommandId::ToggleSecondarySidebar, + "Right", + ); + } + } + Some(response.inner) + } + Placement::Sliding { shown, reserved } => { + let slot = if reserved { + // Keep the docked width reserved and empty; the sidebar slides + // over it in its own layer. + panel + .resizable(false) + .exact_size(width) + .show_inside(ui, |_| {}) + .response + .rect + } else { + ui.skip_ahead_auto_ids(1); + let available = ui.available_rect_before_wrap(); + if primary { + Rect::from_min_max( + available.min, + egui::pos2(available.left() + width, available.bottom()), + ) + } else { + Rect::from_min_max( + egui::pos2(available.right() - width, available.top()), + available.max, + ) + } + }; + show_sliding(app, ui, dark, primary, slot, shown); + reserved.then_some(slot) + } + } +} + +/// Whether the workspace currently lays out around this sidebar, which lags +/// its visibility until a slide ends. +pub(super) fn reserves_space(ctx: &egui::Context, primary: bool) -> bool { + ctx.data(|data| data.get_temp::(reserved_id(ctx, primary))) + .unwrap_or(false) +} + +fn reserved_id(ctx: &egui::Context, primary: bool) -> Id { + super::viewport_local_id( + ctx, + if primary { + "plotium_primary_sidebar_reserved" + } else { + "plotium_secondary_sidebar_reserved" + }, + ) +} + +fn sidebar_id(primary: bool) -> Id { + Id::new(if primary { + "primary_sidebar" } else { - // See the primary branch: keep the sibling auto-id sequence stable. - ui.skip_ahead_auto_ids(1); + "secondary_sidebar" + }) +} + +/// Draws the sidebar in an area just above the workspace panels and below +/// floating windows, shifted toward its window edge by the hidden fraction +/// and clipped to its slot. As an area it owns the pointer over its visible +/// part, so canvas gestures that test the layer under the pointer stop there. +fn show_sliding(app: &mut PlotiumApp, ui: &Ui, dark: bool, primary: bool, slot: Rect, shown: f32) { + let outward = if primary { -1.0 } else { 1.0 }; + let rect = slot.translate(egui::vec2(outward * (1.0 - shown) * slot.width(), 0.0)); + let ctx = ui.ctx(); + let area = sliding_area(primary); + ctx.set_sublayer(ui.layer_id(), area.layer()); + area.fixed_pos(rect.min).show(ctx, |area_ui| { + area_ui.set_clip_rect(slot.intersect(ui.clip_rect())); + area_ui.scope_builder(UiBuilder::new().max_rect(rect), |content| { + sidebar_contents(app, content, dark, primary); + }); + // A moving sidebar takes no input: this cover, added last, wins the + // hit test over its contents. + area_ui.interact( + rect.intersect(slot), + area_ui.id().with("cover"), + egui::Sense::click_and_drag(), + ); + }); +} + +fn sliding_area(primary: bool) -> egui::Area { + egui::Area::new(sidebar_id(primary).with("sliding")) + .order(egui::Order::Background) + .constrain(false) + .movable(false) + .fade_in(false) + .sense(egui::Sense::hover()) +} + +/// A new area spends its first frame on an invisible sizing pass. Run that +/// pass once, empty, inert and off screen, before any slide so the first +/// slide shows at once. +fn prime_sliding_area(ctx: &egui::Context, primary: bool) { + let area = sliding_area(primary); + if egui::AreaState::load(ctx, area.layer().id).is_none() { + area.interactable(false) + .default_size(Vec2::ZERO) + .fixed_pos(egui::pos2(-1.0e4, -1.0e4)) + .show(ctx, |_| {}); } - super::workspace_geometry::set_sidebar_rects(ui.ctx(), primary_rect, secondary_rect); } /// Preview and commit use the same current pointer position: dragging back @@ -151,44 +310,54 @@ fn show_sidebar( width_range: std::ops::RangeInclusive, ) -> InnerResponse { let (id, edge) = if primary { - (Id::new("primary_sidebar"), SidebarEdge::Right) + (sidebar_id(true), SidebarEdge::Right) } else { - (Id::new("secondary_sidebar"), SidebarEdge::Left) + (sidebar_id(false), SidebarEdge::Left) }; show_resizable_sidebar(panel, ui, id, edge, width_range, |ui| { - // Anchor the content ids globally: a Ui's per-pass unique id folds in - // the parent's auto-id counter, so without this every widget in this - // sidebar changes id whenever an earlier sibling panel toggles. That - // dropped focus mid-edit and tripped egui's rect-changed-id debug - // overlay (one-frame red boxes) on the unmoved sidebar. - ui.scope_builder( - UiBuilder::new() - .id_salt(id.with("stable_scope")) - .global_scope(true), - |ui| { - let size = ui.available_size(); - let frame = window_shell::edge_frame(dark, window_shell::EDGE_INSET); - let inset = frame.total_margin().sum(); - let rect = frame - .show(ui, |ui| { - ui.set_min_size((size - inset).max(Vec2::ZERO)); - if primary { - primary_sidebar::render(app, ui); - } else { - secondary_sidebar::render(app, ui); - } - }) - .response - .rect; - let divider = if primary { - window_shell::Side::Right - } else { - window_shell::Side::Left - }; - window_shell::paint_separator(ui, rect, divider, dark); - rect - }, - ) - .inner + sidebar_contents(app, ui, dark, primary) }) } + +fn sidebar_contents(app: &mut PlotiumApp, ui: &mut Ui, dark: bool, primary: bool) -> Rect { + let id = sidebar_id(primary); + // Anchor the content ids globally: a Ui's per-pass unique id folds in + // the parent's auto-id counter, so without this every widget in this + // sidebar changes id whenever an earlier sibling panel toggles. That + // dropped focus mid-edit and tripped egui's rect-changed-id debug + // overlay (one-frame red boxes) on the unmoved sidebar. The global scope + // also keeps the ids when the sidebar moves into its sliding layer. + ui.scope_builder( + UiBuilder::new() + .id_salt(id.with("stable_scope")) + .global_scope(true), + |ui| { + let size = ui.available_size(); + let frame = window_shell::edge_frame(dark, window_shell::EDGE_INSET); + let inset = frame.total_margin().sum(); + let rect = frame + .show(ui, |ui| { + ui.set_min_size((size - inset).max(Vec2::ZERO)); + if primary { + primary_sidebar::render(app, ui); + } else { + secondary_sidebar::render(app, ui); + } + }) + .response + .rect; + let divider = if primary { + window_shell::Side::Right + } else { + window_shell::Side::Left + }; + window_shell::paint_separator(ui, rect, divider, dark); + rect + }, + ) + .inner +} + +#[cfg(test)] +#[path = "sidebars_tests.rs"] +mod tests; diff --git a/crates/app/src/ui/sidebars_tests.rs b/crates/app/src/ui/sidebars_tests.rs new file mode 100644 index 00000000..6e556582 --- /dev/null +++ b/crates/app/src/ui/sidebars_tests.rs @@ -0,0 +1,218 @@ +use super::*; +use plotium_core::settings::{ReduceMotion, Settings}; + +const FRAME: f64 = 1.0 / 60.0; + +struct Harness { + ctx: egui::Context, + app: PlotiumApp, + time: f64, + /// The next auto id after the sidebars, which later siblings start from. + next_auto_id: Id, +} + +impl Harness { + fn new() -> Self { + let mut app = PlotiumApp::new_with_settings(Settings::default()); + app.session.primary_sidebar_visible = true; + app.session.secondary_sidebar_visible = false; + app.session.primary_sidebar_width = 300.0; + Self { + ctx: crate::typography::test_context(), + app, + time: 0.0, + next_auto_id: Id::NULL, + } + } + + fn frame(&mut self) { + self.time += FRAME; + let Self { + ctx, + app, + time, + next_auto_id, + } = self; + let _ = ctx.run_ui( + egui::RawInput { + time: Some(*time), + screen_rect: Some(Rect::from_min_size(Pos2::ZERO, Vec2::new(1400.0, 900.0))), + ..Default::default() + }, + |ui| { + render(app, ui, false, ui.available_width()); + *next_auto_id = ui.next_auto_id(); + }, + ); + } + + fn reserved(&self, primary: bool) -> bool { + reserves_space(&self.ctx, primary) + } + + fn set_visible(&mut self, primary: bool, visible: bool) { + if primary { + self.app.session.primary_sidebar_visible = visible; + } else { + self.app.session.secondary_sidebar_visible = visible; + } + } + + fn widths(&self) -> (f32, f32) { + ( + self.app.session.primary_sidebar_width, + self.app.session.secondary_sidebar_width, + ) + } + + /// Runs frames until the sidebar's reserved space matches `reserved`, + /// checking that no width is written meanwhile; returns the frame count. + fn slide_until(&mut self, primary: bool, reserved: bool) -> usize { + let widths = self.widths(); + let mut frames = 0; + self.frame(); + while self.reserved(primary) != reserved { + assert_eq!(self.widths(), widths); + frames += 1; + assert!(frames < 60, "the slide never ended"); + self.frame(); + } + frames + } +} + +#[test] +fn placement_keeps_the_starting_layout_until_the_slide_ends() { + assert_eq!(Placement::resolve(true, 1.0, false), Placement::Docked); + assert_eq!(Placement::resolve(false, 0.0, true), Placement::Hidden); + let opening = Placement::resolve(true, 0.4, false); + assert_eq!( + opening, + Placement::Sliding { + shown: 0.4, + reserved: false + } + ); + assert!(!opening.reserves_space()); + let closing = Placement::resolve(false, 0.4, true); + assert!(closing.reserves_space()); + // Reversing mid-slide keeps the layout the slide started from. + assert!(Placement::resolve(true, 0.6, true).reserves_space()); + assert!(!Placement::resolve(false, 0.6, false).reserves_space()); +} + +#[test] +fn sliding_keeps_the_stored_width_and_relayouts_once_at_the_end() { + for primary in [true, false] { + let mut harness = Harness::new(); + harness.set_visible(primary, true); + harness.frame(); + harness.frame(); + assert!(harness.reserved(primary)); + let docked = harness.widths(); + + harness.set_visible(primary, false); + let frames = harness.slide_until(primary, false); + assert!(frames > 3, "closed in {frames} frames"); + + harness.set_visible(primary, true); + let frames = harness.slide_until(primary, true); + assert!(frames > 3, "opened in {frames} frames"); + harness.frame(); + assert_eq!(harness.widths(), docked); + } +} + +#[test] +fn both_sidebars_slide_together_without_writing_widths() { + let mut harness = Harness::new(); + harness.set_visible(false, true); + harness.frame(); + harness.frame(); + let docked = harness.widths(); + harness.set_visible(true, false); + harness.set_visible(false, false); + harness.slide_until(true, false); + assert!(!harness.reserved(false)); + harness.set_visible(true, true); + harness.set_visible(false, true); + harness.slide_until(true, true); + assert!(harness.reserved(false)); + harness.frame(); + assert_eq!(harness.widths(), docked); +} + +#[test] +fn reduced_motion_docks_and_hides_on_the_same_frame() { + let mut harness = Harness::new(); + motion::sync(&harness.ctx, ReduceMotion::On); + harness.frame(); + assert!(harness.reserved(true)); + harness.set_visible(true, false); + harness.frame(); + assert!(!harness.reserved(true)); + harness.set_visible(true, true); + harness.frame(); + assert!(harness.reserved(true)); +} + +#[test] +fn a_sliding_sidebar_paints_just_above_the_workspace_from_its_first_frame() { + let mut harness = Harness::new(); + harness.frame(); + // Primed, so the first slide frame is not an invisible sizing pass. + let area = sidebar_id(true).with("sliding"); + assert!(egui::AreaState::load(&harness.ctx, area).is_some()); + harness.set_visible(true, false); + harness.frame(); + assert!(harness.reserved(true)); + let sliding = egui::LayerId::new(egui::Order::Background, sidebar_id(true).with("sliding")); + let order: Vec<_> = harness.ctx.memory(|memory| memory.layer_ids().collect()); + let background = order + .iter() + .position(|layer| *layer == egui::LayerId::background()); + let overlay = order.iter().position(|layer| *layer == sliding); + assert_eq!(overlay, background.map(|index| index + 1), "{order:?}"); +} + +#[test] +fn later_siblings_keep_their_auto_ids_through_a_slide() { + let mut harness = Harness::new(); + harness.frame(); + let docked = harness.next_auto_id; + harness.set_visible(true, false); + harness.frame(); + assert!(harness.reserved(true)); + assert_eq!(harness.next_auto_id, docked); + harness.slide_until(true, false); + assert_eq!(harness.next_auto_id, docked); + harness.set_visible(true, true); + harness.frame(); + assert!(!harness.reserved(true)); + assert_eq!(harness.next_auto_id, docked); +} + +#[test] +fn an_opening_sidebar_owns_the_pointer_over_its_visible_part() { + let mut harness = Harness::new(); + harness.set_visible(true, false); + harness.frame(); + harness.set_visible(true, true); + harness.frame(); + harness.frame(); + assert!(!harness.reserved(true)); + let near_edge = Pos2::new(4.0, 450.0); + let layer = harness.ctx.layer_id_at(near_edge); + assert_eq!( + layer, + Some(egui::LayerId::new( + egui::Order::Background, + sidebar_id(true).with("sliding") + )) + ); + let beyond = Pos2::new(1000.0, 450.0); + assert_eq!( + harness.ctx.layer_id_at(beyond), + Some(egui::LayerId::background()) + ); +} diff --git a/docs/src/content/docs/reference/preferences.md b/docs/src/content/docs/reference/preferences.md index 30133d92..a5ef3f25 100644 --- a/docs/src/content/docs/reference/preferences.md +++ b/docs/src/content/docs/reference/preferences.md @@ -50,8 +50,9 @@ saved preferences except your recent-files list. AI connection preferences are d chrome theme. Snap guides keep a contrasting color of their own so they stay distinct, and figure content and exported colors are never affected. -- **Reduce motion** — replaces interface animations, such as sliding tab - highlights, dialog fades, and zoom-to-fit glides, with immediate changes. +- **Reduce motion** — replaces interface animations, such as sidebars sliding + open and closed, sliding tab highlights, dialog fades, and zoom-to-fit + glides, with immediate changes. **Follow system** uses the macOS or Windows accessibility setting. On Linux, where no system setting can be read, the default keeps animations on. - **UI scale** — the size of all interface text and controls, per display. diff --git a/docs/src/content/docs/zh-cn/reference/preferences.md b/docs/src/content/docs/zh-cn/reference/preferences.md index 7c982a9e..81e46768 100644 --- a/docs/src/content/docs/zh-cn/reference/preferences.md +++ b/docs/src/content/docs/zh-cn/reference/preferences.md @@ -39,8 +39,8 @@ AI 连接启用状态和权限会持久保存,详见下文。 预览的颜色。可自选颜色,也可用 **Follow theme** 跟随系统强调色(macOS 和 Windows)或应用主题。吸附参考线始终使用另一种对比色以便区分;图形 内容和导出配色不受影响。 -- **Reduce motion**——让标签高亮滑动、对话框淡入、适应视图的平移缩放等界面 - 动画改为直接切换。**Follow system** 跟随 macOS 或 Windows 的辅助功能设置。 +- **Reduce motion**——让侧栏滑入滑出、标签高亮滑动、对话框淡入、适应视图的 + 平移缩放等界面动画改为直接切换。**Follow system** 跟随 macOS 或 Windows 的辅助功能设置。 Linux 上读取不到系统设置,默认保留动画。 - **UI scale**——界面文字和控件的大小,按显示器分别设置。自动模式根据 显示器报告的像素密度选择物理上可读的尺寸;手动选项和