From 3846cbbaac749f7c5eb856490a087f995001141b Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 21:26:36 +0700 Subject: [PATCH] chrome-w2: net change of 2 commits - chrome-w2: written from its sheet - chrome-w2: repair 1 --- crates/ui-contract/src/runtime/env/shell.rs | 23 +++-- crates/ui-contract/src/runtime/frame.rs | 5 +- .../src/runtime/windows/viewport.rs | 8 +- crates/ui-contract/tests/it/runtime/wheel.rs | 86 ++++++++++++++++++- crates/ui-patterns/src/patterns/dock/area.rs | 4 +- crates/ui-patterns/src/patterns/dock/hide.rs | 79 +++++++++++++---- crates/ui-patterns/src/patterns/dock/panes.rs | 28 +++--- .../tests/it/docking/drop_session.rs | 44 +++++++++- crates/ui-patterns/tests/it/docking/hidden.rs | 18 +++- docs/ui-docking.md | 2 +- 10 files changed, 247 insertions(+), 50 deletions(-) diff --git a/crates/ui-contract/src/runtime/env/shell.rs b/crates/ui-contract/src/runtime/env/shell.rs index d72ccb11f..7d514d5d3 100644 --- a/crates/ui-contract/src/runtime/env/shell.rs +++ b/crates/ui-contract/src/runtime/env/shell.rs @@ -243,11 +243,16 @@ impl ShellCx { self.inner.panels_hidden } - /// Whether the dock at `edge` shows: in normal mode, during the Tab reveal and, for the `Start` and `End` edges, - /// while that edge's reveal is on, unless the panels are hidden. + /// Whether the dock at `edge` shows: in normal mode and during the Tab reveal unless the panels are hidden, and the + /// `Start` and `End` docks also while that edge's reveal is on, in body-only mode or while the panels are hidden. pub fn dock_visible(&self, edge: super::PaneEdge) -> bool { - let _ = edge; // P3(chrome-w2): ch.K1 - !self.inner.panels_hidden && (self.inner.mode == BodyMode::Normal || self.inner.tab_reveal || self.edge_revealed(RevealEdge::End)) + let inner = &*self.inner; + let base = !inner.panels_hidden && (inner.mode == BodyMode::Normal || inner.tab_reveal); + base || match edge { + super::PaneEdge::Start => self.edge_revealed(RevealEdge::Start), + super::PaneEdge::End => self.edge_revealed(RevealEdge::End), + _ => false, + } } /// Whether floating frames show: in normal mode; in body-only mode only during the Tab reveal; never while the @@ -290,16 +295,18 @@ impl ShellCx { self.inner.mode == BodyMode::Normal && self.inner.tabs } - /// Are slots shown by a reveal (Tab or edge) on this pass? Only body-only mode reveals. + /// Are slots shown by a reveal (Tab or edge) on this pass? Only body-only mode reveals with Tab; an edge reveals in + /// body-only mode and while the panels are hidden. pub fn revealed(&self) -> bool { let inner = &*self.inner; - inner.mode == BodyMode::Only && (inner.tab_reveal || inner.edges.iter().any(|on| *on)) + let body_only = inner.mode == BodyMode::Only; + (body_only && inner.tab_reveal) || ((body_only || inner.panels_hidden) && inner.edges.iter().any(|on| *on)) } - /// Is the edge reveal on for `edge`? False in normal mode and during the Tab reveal. + /// Is the edge reveal on for `edge`? False while the panels show in normal mode, and during the Tab reveal. pub fn edge_revealed(&self, edge: RevealEdge) -> bool { let inner = &*self.inner; - inner.mode == BodyMode::Only && !inner.tab_reveal && inner.edges[edge.index()] + (inner.mode == BodyMode::Only || inner.panels_hidden) && !inner.tab_reveal && inner.edges[edge.index()] } /// The body rect and the shown slots of this pass. diff --git a/crates/ui-contract/src/runtime/frame.rs b/crates/ui-contract/src/runtime/frame.rs index dcce0604f..7fe9f7000 100644 --- a/crates/ui-contract/src/runtime/frame.rs +++ b/crates/ui-contract/src/runtime/frame.rs @@ -400,8 +400,7 @@ pub(crate) fn note_removed_gesture(ctx: &Context, id: GestureId) { /// Adds a component whose live preview ended to the next `FrameOutput`. pub(crate) fn note_ended_preview(ctx: &Context, id: Id) { - let _ = (ctx, id); - todo!("ty.X1") + pass_state::with::(ctx, |state| state.output.ended_previews.push(id)); } /// Adds a step of an outer gesture to the next `FrameOutput`. @@ -556,7 +555,7 @@ pub(crate) fn facts(ctx: &Context) -> PassFacts { }) } -/// The running pass's time in seconds, read once by the begin hook: what an app waits on. +/// The running pass's time in seconds, the same on every pass of a frame: for app code that times a wait. pub fn clock(ctx: &Context) -> f64 { match running(ctx) { Some(facts) => facts.now, diff --git a/crates/ui-contract/src/runtime/windows/viewport.rs b/crates/ui-contract/src/runtime/windows/viewport.rs index 71302239c..04bb5d4fe 100644 --- a/crates/ui-contract/src/runtime/windows/viewport.rs +++ b/crates/ui-contract/src/runtime/windows/viewport.rs @@ -3,7 +3,7 @@ use super::native::{WindowAction, act, route_hit_test}; use super::placement::{record_placement, saved_placement}; use super::shell::{app_id, os_of, refresh}; -use super::spec::{WindowSpec, frame_of_spec}; +use super::spec::{WindowLevel, WindowSpec, frame_of_spec}; use super::{Record, refuse_close_under_modal, shared}; use crate::runtime::egui::viewports; use crate::runtime::frame::PerViewport; @@ -77,6 +77,8 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im record.level.get_or_insert(spec.level).for_egui(active, os) }); let app = app_id(ctx); + // PLAN: `Shared::palettes_yield` is written by shell-w1 (ch.K8); a palette built while it holds opens hidden. + let yielding = shared(ctx, |shared| shared.palettes_yield); let opens = viewports::Spec { title: open.title, // The builder carries the place only until the window opens: egui would send each change of it as a command. @@ -92,7 +94,9 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im level, resizable: open.resizable, taskbar: spec.taskbar, - hidden: PerViewport::::with(ctx, viewport, |record| record.awaiting_first_paint), + hidden: PerViewport::::with(ctx, viewport, |record| { + record.awaiting_first_paint || (yielding && record.level == Some(WindowLevel::Palette)) + }), app_id: &app, }; viewports::show_immediate(ctx, viewport, &opens, |ui| { diff --git a/crates/ui-contract/tests/it/runtime/wheel.rs b/crates/ui-contract/tests/it/runtime/wheel.rs index 56b6e4090..7677cca18 100644 --- a/crates/ui-contract/tests/it/runtime/wheel.rs +++ b/crates/ui-contract/tests/it/runtime/wheel.rs @@ -1,12 +1,17 @@ //! The wheel service: the begin hook splits the pass's wheel input among last pass's takers. +use craft_behavior::overlay::{Align, Side}; use craft_behavior::{GESTURE_GAP, Sense, Wheel, WheelPhase, WheelTaker}; use craft_host::target::Os; +use craft_ui::contract::overlay::{Anchor, Place}; +use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Show as _, ShowContainer as _, Sizing}; +use craft_ui::style::StyleCx; use craft_ui::testing::pointer; use craft_ui::testing::sensing::{ProbeRoot, show}; use craft_ui::testing::wheel::{register, take, take_share}; use craft_ui::testing::{Fixture, Frames, trial}; -use egui::{Event, Id, Modifiers, MouseWheelSource, MouseWheelUnit, Pos2, Rect, TouchPhase, Vec2}; +use craft_ui_test_kit::contract::{PlainStyle, Probe, Seen}; +use egui::{Event, Id, Modifiers, MouseWheelSource, MouseWheelUnit, Pos2, Rect, Response, TouchPhase, Ui, Vec2}; use std::cell::RefCell; use std::rc::Rc; @@ -184,3 +189,82 @@ fn a_wheel_gesture_ends_for_a_value_control_in_any_wheel_scope_and_not_for_a_scr assert_eq!(ends(&close(&mut frames, &mut show_frame)), [owner], "the device's end reaches the gesture's owner once"); } } + +/// A popup layer that holds one probe. +#[derive(craft_ui::contract::Component)] +#[component(container)] +struct Popup { + #[common] + common: Common, + #[container] + props: ContainerProps, +} + +impl Component for Popup { + const ROLE: Role = Role::GROUP; + type Style = PlainStyle; + type Output = Response; + + fn style(_: &StyleCx<'_>, _: PopupStyleKey) -> PlainStyle { + PlainStyle::default() + } + + fn finish(self, cx: Cx<'_, Self>) -> Response { + cx.response.clone() + } +} + +impl Container for Popup {} + +#[trial] +fn a_wheel_over_an_open_popup_goes_to_the_popup_and_not_to_the_region_under_it() { + let anchor = Rect::from_min_size(Pos2::new(200.0, 100.0), Vec2::new(30.0, 20.0)); + let (field_seen, popup_seen) = (RefCell::new(Seen::default()), RefCell::new(Seen::default())); + let open = std::cell::Cell::new(false); + let popup_rect = std::cell::Cell::new(Rect::NOTHING); + let field = std::cell::Cell::new(Id::NULL); + let popup = Id::unique("wheel_popup"); + let panel = Id::unique("wheel_panel"); + let shares: RefCell> = RefCell::new(Vec::new()); + let mut show_frame = |ui: &mut Ui| { + let ctx = ui.ctx().clone(); + let field_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 20.0)); + field.set(Probe::new(&field_seen).size(field_rect.size()).sense(Sense::CLICK | Sense::FOCUS).show(ui).id); + if open.get() { + let overlay = Overlay::popover().place(Place::anchored(Anchor::Rect(anchor), Side::Below, Align::Start)); + let props = ContainerProps::new().mount(Mount::Layer(overlay)).sizing(Sizing::Content); + let out = Popup { common: Common::new(), props }.id_salt("wheel_popup_layer").show(ui, |ui, _| { + Probe::new(&popup_seen).size(Vec2::new(120.0, 60.0)).show(ui); + }); + popup_rect.set(out.output.rect); + } + register(&ctx, WheelTaker::new(panel, Rect::from_min_size(Pos2::ZERO, Vec2::splat(400.0))).vertical(true).scrolls(true)); + register(&ctx, WheelTaker::new(field.get(), field_rect).vertical(true).field(true)); + if open.get() { + register(&ctx, WheelTaker::new(popup, popup_rect.get()).vertical(true).scrolls(true)); + } + for id in [panel, field.get(), popup] { + if let Some(share) = take_share(&ctx, id) { + shares.borrow_mut().push((id, share)); + } + } + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show_frame); + pointer::click(&mut frames, Pos2::new(50.0, 10.0), &mut show_frame); + let mut wheel_at = |frames: &mut Frames, at: Pos2, show_frame: &mut dyn FnMut(&mut Ui)| -> Vec { + frames.frame(vec![pointer::moved(at)], &mut *show_frame); + shares.borrow_mut().clear(); + frames.frame(vec![pointer::wheel(-30.0)], &mut *show_frame); + shares.borrow().iter().map(|(id, _)| *id).collect() + }; + + let beside = Pos2::new(300.0, 300.0); + assert_eq!(wheel_at(&mut frames, beside, &mut show_frame), [field.get()], "the focused field takes the wheel over the region"); + + open.set(true); + frames.idle(4, &mut show_frame); + assert!(popup_rect.get().is_positive(), "the popup shows: {:?}", popup_rect.get()); + let on_popup = popup_rect.get().center(); + assert_eq!(wheel_at(&mut frames, on_popup, &mut show_frame), [popup], "the popup under the pointer takes the wheel, not the focused field or the region"); +} diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index ce90c6617..4419f6ac7 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -207,13 +207,13 @@ impl Drops<'_, P> { let space = float_space(bounds, &sizes, self.config, self.specs); let spec = |panel: &P| spec_in(self.specs, panel); let protected = |panel: &P| (self.permissions)(panel).is_protected(); - let (hide, _) = hide::resolved(self.hide, shell.as_ref(), None); // P3(chrome-w2): ch.K7 + let prune = hide::Prune::new(self.layout, self.hide, shell.as_ref()); let mut target = DockDropTarget::new(&ctx, self.dock, self.layout, self.permissions); target.rtl = self.rtl; target.space = Some(&space); target.float_on_empty = self.config.float_on_empty_drop; target.title_bar_docks = self.config.title_bar_docks; - target.placing = Some(Placing::new(sizes, &spec, &protected).shown(hide, self.maximized)); + target.placing = Some(Placing::new(sizes, &spec, &protected).shown(prune.hide(), self.maximized)); cx.drop_target::, _>(&target).or_else(|| cx.drop_target::(&target)) } } diff --git a/crates/ui-patterns/src/patterns/dock/hide.rs b/crates/ui-patterns/src/patterns/dock/hide.rs index 808d8c8f3..2e530ab4e 100644 --- a/crates/ui-patterns/src/patterns/dock/hide.rs +++ b/crates/ui-patterns/src/patterns/dock/hide.rs @@ -4,7 +4,7 @@ use crate::docking::HidePanels; use crate::docking::frame::{FrameView, maximize}; use crate::runtime::env::{PaneEdge, ShellCx}; -use craft_behavior::dock::{DockEdge, Layout}; +use craft_behavior::dock::{DockEdge, Layout, Node, PanelPlace, node_at}; use std::hash::Hash; /// The layout as the area shows it, and whether its floating windows show. @@ -16,9 +16,10 @@ pub(super) struct Shown<'a, P: Clone> { } /// `layout` with the host's `hide`, the shell's panel visibility and the frame of `maximized` applied. Protected -/// panels always stay, so a canvas shows while the dock is hidden. While the shell hides the panels and keeps the -/// tools (Shift+Tab), the panels the host's `HidePanels::Except` names stay, docked or floating, and every other panel -/// hides; while the shell hides the dock (Tab, body-only mode), every panel hides. Size edits made on the view go back +/// panels always stay, so a canvas shows while the dock is hidden. The shell decides per dock (see [`resolved`]): a +/// dock that shows keeps the host's `hide`; while the shell hides the panels and keeps the tools (Shift+Tab), the +/// panels the host's `HidePanels::Except` names stay, docked or floating, and every other panel of a hidden dock hides; +/// while the shell hides the dock (Tab, body-only mode), every panel of it hides. Size edits made on the view go back /// through `FrameView::write_back`. pub(super) fn shown<'a, P: Clone + Eq + Hash>( layout: &'a Layout

, @@ -27,22 +28,70 @@ pub(super) fn shown<'a, P: Clone + Eq + Hash>( shell: Option<&ShellCx>, protected: &dyn Fn(&P) -> bool, ) -> Shown<'a, P> { - let (hide, floating) = resolved(hide, shell, None); - Shown { view: maximize(layout, maximized, hide, protected), floating } + let prune = Prune::new(layout, hide, shell); + Shown { view: maximize(layout, maximized, prune.hide(), protected), floating: prune.floating } } -/// The panels the area hides, the host's `hide` with the shell's panel visibility applied, and whether floating windows -/// show (see [`shown`]). `side` is the dock the panels sit in; `None` is panels outside every dock. +/// The host's `hide` with the shell's per-dock visibility applied over a layout. `maximize` takes one `HidePanels` for +/// the whole layout, so a shell that hides a dock turns it into a per-panel keep. +pub(super) struct Prune<'a, P> { + hide: HidePanels<'a, P>, + keep: Option bool + 'a>>, + /// Floating windows show. + pub(super) floating: bool, +} + +impl<'a, P: Clone + Eq + Hash> Prune<'a, P> { + /// The prune of `layout` under `shell`. When every dock shows the host's `hide` goes through unchanged, so + /// `maximize` can skip the prune. + pub(super) fn new(layout: &'a Layout

, hide: HidePanels<'a, P>, shell: Option<&ShellCx>) -> Self { + let floating = resolved(hide, shell, None).1; + let Some(shell) = shell.filter(|shell| !shell.dock_visible(PaneEdge::Top)) else { + return Prune { hide, keep: None, floating }; + }; + let shell = shell.clone(); + let keep = move |panel: &P| match resolved(hide, Some(&shell), dock_side(layout, panel)).0 { + HidePanels::None => true, + HidePanels::All => false, + HidePanels::Except(keep) => keep(panel), + }; + Prune { hide, keep: Some(Box::new(keep)), floating } + } + + /// The panels the area hides. + pub(super) fn hide(&self) -> HidePanels<'_, P> { + match &self.keep { + Some(keep) => HidePanels::Except(&**keep), + None => self.hide, + } + } +} + +/// The side of the dock `panel` sits in; `None` for a panel outside every dock. +fn dock_side(layout: &Layout

, panel: &P) -> Option { + let PanelPlace::Dock { path, .. } = layout.place(panel)? else { return None }; + match layout.root.as_ref().and_then(|root| node_at(root, &path))? { + Node::Dock { side, .. } => Some(*side), + _ => None, + } +} + +/// The panels the area hides in the dock at `side` (`None`: panels outside every dock), the host's `hide` with the +/// shell's panel visibility applied, and whether floating windows show. A dock whose edge shows keeps the host's +/// `hide`; a hidden one keeps the host's `Except` while the shell hides only the panels (Shift+Tab) and nothing under +/// Tab. pub(super) fn resolved<'h, P>(hide: HidePanels<'h, P>, shell: Option<&ShellCx>, side: Option) -> (HidePanels<'h, P>, bool) { - // P3(chrome-w2): ch.K7 -- `DockEdge` has no `From` into the shell's `PaneEdge`; the writer replaces this mapping. + let Some(shell) = shell else { return (hide, true) }; let edge = match side { Some(DockEdge::Start) => PaneEdge::Start, Some(DockEdge::End) => PaneEdge::End, - _ => PaneEdge::Center, + _ => PaneEdge::Top, }; - match shell { - None => (hide, true), - Some(shell) if shell.panels_hidden() => (if let HidePanels::Except(keep) = hide { HidePanels::Except(keep) } else { HidePanels::All }, true), - Some(shell) => (if shell.dock_visible(edge) { hide } else { HidePanels::All }, shell.floating_visible()), - } + let floating = shell.panels_hidden() || shell.floating_visible(); + let hide = match hide { + _ if shell.dock_visible(edge) => hide, + HidePanels::Except(_) if shell.panels_hidden() => hide, + _ => HidePanels::All, + }; + (hide, floating) } diff --git a/crates/ui-patterns/src/patterns/dock/panes.rs b/crates/ui-patterns/src/patterns/dock/panes.rs index 104c250bc..d76c69c2d 100644 --- a/crates/ui-patterns/src/patterns/dock/panes.rs +++ b/crates/ui-patterns/src/patterns/dock/panes.rs @@ -639,23 +639,25 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> PaneArea<'a, P> { let shown_root = root.show(ui, |ui, cx| { let Some(sizes) = cx.style::>>>().map(|style| *style.sizes()) else { return }; - let (docks, floats) = cx.shell().as_ref().map_or((true, true), |shell| (shell.dock_visible(PaneEdge::Center), shell.floating_visible())); // P3(chrome-w2): ch.K1 - let bounds = cx.shell().map_or(cx.rect, |shell| shell.float_bounds()); + let shell = cx.shell(); + let floats = shell.as_ref().is_none_or(|shell| shell.floating_visible()); + let bounds = shell.as_ref().map_or(cx.rect, |shell| shell.float_bounds()); let mut order = [PaneEdge::Bottom, PaneEdge::Top, PaneEdge::Start, PaneEdge::End]; if rtl { order.swap(2, 3); } - if docks { - for edge in order { - let on_edge: Vec<&Shown

> = shown.iter().filter(|s| s.docked_at() == Some(edge)).collect(); - let slot = on_edge.iter().rposition(|s| s.spec.closable); - for (at, pane) in on_edge.iter().enumerate() { - if policy == SidePolicy::OneSlot && pane.spec.closable && slot != Some(at) { - continue; - } - if show_docked(ui, &pass, pane, edge) { - *pass.focused.borrow_mut() = Some(pane.pane.clone()); - } + for edge in order { + if !shell.as_ref().is_none_or(|shell| shell.dock_visible(edge)) { + continue; + } + let on_edge: Vec<&Shown

> = shown.iter().filter(|s| s.docked_at() == Some(edge)).collect(); + let slot = on_edge.iter().rposition(|s| s.spec.closable); + for (at, pane) in on_edge.iter().enumerate() { + if policy == SidePolicy::OneSlot && pane.spec.closable && slot != Some(at) { + continue; + } + if show_docked(ui, &pass, pane, edge) { + *pass.focused.borrow_mut() = Some(pane.pane.clone()); } } } diff --git a/crates/ui-patterns/tests/it/docking/drop_session.rs b/crates/ui-patterns/tests/it/docking/drop_session.rs index 21677b6d8..25c862cdd 100644 --- a/crates/ui-patterns/tests/it/docking/drop_session.rs +++ b/crates/ui-patterns/tests/it/docking/drop_session.rs @@ -2,16 +2,19 @@ //! and the released drop applies to the layout. use craft_behavior::Axis; -use craft_behavior::dock::{Layout, Node, Permissions, SplitSize}; +use craft_behavior::dock::{Layout, Node, Permissions, SplitSize, Workspace}; use craft_ui::contract::SizeLimits; -use craft_ui::contract::{Bind, Common, Component, Cx, MeasureCx, Pointer as _, Role, Show as _, ShowContainer as _}; +use craft_ui::contract::{Bind, BodyCx, Common, Component, Cx, MeasureCx, Pointer as _, Role, Show as _, ShowContainer as _}; use craft_ui::docking::tree::{self, FrameRules}; -use craft_ui::docking::{DockDropTarget, DockDropped, DockGroup, DockSizes, GroupDrag, PanelDrag, PanelKey, PanelTitle, SplitArea}; +use craft_ui::docking::{ + DockConfig, DockDropTarget, DockDropped, DockGroup, DockPanels, DockSizes, GroupDrag, PanelDrag, PanelKey, PanelSpec, PanelTitle, SplitArea, +}; +use craft_ui::patterns::dock::DockArea; use craft_ui::runtime::drag; use craft_ui::style::{ComponentStyle, StyleCx}; use craft_ui::testing::pointer::{moved, press, release}; use craft_ui::testing::{Fixture, trial}; -use egui::{Id, Pos2, Rect, Response, Vec2}; +use egui::{Id, Pos2, Rect, Response, Ui, Vec2}; use std::cell::RefCell; use std::rc::Rc; @@ -171,3 +174,36 @@ fn a_header_drag_shows_the_drop_mark_over_a_group_side_and_docks_on_release() { assert_eq!(groups(&layout.borrow()).len(), 2, "the group moved beside the right group"); assert_eq!(groups(&layout.borrow())[1], panels(&["Layers", "Channels"])); } + +/// Panels with no body: the drag is all the trial needs. +struct Named; + +impl DockPanels for Named { + fn spec(&self, panel: &String) -> PanelSpec { + PanelSpec::new(panel.clone()) + } + + fn body(&mut self, _: &String, _: &mut Ui, _: &mut BodyCx<'_>) {} +} + +#[trial] +fn a_drag_started_under_another_workspace_revision_ends_when_the_workspace_is_replaced() { + let workspace = Rc::new(RefCell::new(Workspace::new(wide_left_group()))); + let shared = Rc::clone(&workspace); + let mut fixture = Fixture::new(move |ui| { + let mut held = shared.borrow_mut(); + DockArea::new("Replaced dock", Bind::bound(&mut *held), &mut Named, DockConfig::default()).show(ui); + }); + fixture.settle(); + let grip = left_grip(&fixture); + hold_and_move(&mut fixture, grip, Pos2::new(395.0, 150.0)); + assert!(drag::active::>(fixture.ctx()).is_some(), "the header drag started a group drag in the dock"); + fixture.frame(Vec::new()); + assert!(drag::active::>(fixture.ctx()).is_some(), "the dock's own passes keep the drag"); + let replacement = Workspace::new(Layout::new(Some(Node::tabs(panels(&["Properties"]), 0)), Vec::new())); + workspace.borrow_mut().replace(replacement); + fixture.frame(Vec::new()); + fixture.idle(1); + assert!(drag::active::>(fixture.ctx()).is_none(), "replacing the workspace ended the drag"); + assert_eq!(groups(&workspace.borrow().layout), vec![panels(&["Properties"])], "the new workspace's layout stays as it was set"); +} diff --git a/crates/ui-patterns/tests/it/docking/hidden.rs b/crates/ui-patterns/tests/it/docking/hidden.rs index dcc2cfc09..130e2d719 100644 --- a/crates/ui-patterns/tests/it/docking/hidden.rs +++ b/crates/ui-patterns/tests/it/docking/hidden.rs @@ -5,7 +5,7 @@ use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, Perm use craft_ui::contract::{Bind, BodyCx}; use craft_ui::docking::{DockConfig, DockPanels, HidePanels, PanelSpec}; use craft_ui::patterns::dock::DockArea; -use craft_ui::runtime::env::{BodyMode, ShellCx, ShellEntry, WindowKey}; +use craft_ui::runtime::env::{BodyMode, RevealEdge, ShellCx, ShellEntry, WindowKey}; use craft_ui::testing::{Fixture, trial}; use egui::{Pos2, Rect, Ui, Vec2}; use std::cell::RefCell; @@ -83,3 +83,19 @@ fn shift_tab_keeps_the_panels_the_host_names_docked_and_floating_and_tab_hides_t let tab = ShellCx::detached(WindowKey::main(), BodyMode::Only, room); assert_eq!(shown_under(tab, true), BTreeSet::from([CANVAS]), "Tab keeps the canvas only, whatever the host names"); } + +#[trial] +fn a_revealed_edge_shows_its_dock_alone_under_tab_and_shift_tab() { + let room = Rect::from_min_size(Pos2::ZERO, Vec2::new(400.0, 300.0)); + let tab = ShellCx::detached(WindowKey::main(), BodyMode::Only, room); + let shift_tab = ShellCx::detached(WindowKey::main(), BodyMode::Normal, room).with_panels_hidden(true); + for (keys, hiding) in [("Tab", tab), ("Shift+Tab", shift_tab)] { + let under = |edge: Option| match edge { + Some(edge) => shown_under(hiding.clone().with_edge_reveal(edge, true), false), + None => shown_under(hiding.clone(), false), + }; + assert_eq!(under(Some(RevealEdge::Start)), BTreeSet::from([CANVAS, TOOLBAR]), "{keys}: the start edge shows the start dock alone"); + assert_eq!(under(Some(RevealEdge::End)), BTreeSet::from([CANVAS, LAYERS]), "{keys}: the end edge shows the end dock alone"); + assert_eq!(under(None), BTreeSet::from([CANVAS]), "{keys}: with no edge revealed no dock shows"); + } +} diff --git a/docs/ui-docking.md b/docs/ui-docking.md index ae8016407..b9a7f004c 100644 --- a/docs/ui-docking.md +++ b/docs/ui-docking.md @@ -65,7 +65,7 @@ The binding decides who applies the edits. With `Bind::bound` the area writes ev A panel body, or code a body calls, changes the workspace during the pass with `docking::request_actions(ctx, actions)`, never by writing the workspace the area shows. The running area takes them unapplied and returns them in `DockAreaOutput::requested`, in order, for the host to apply after `actions` in the same frame. With no area over that panel type running, `request_actions` hands the actions back for the caller to apply. -Props: `hide` (`HidePanels::None`, `All` or `Except`), `maximized`, `auto_collapse`, `locked`, and `flyout`, which binds the open flyout to the host's value (the area keeps it otherwise). A hidden panel keeps its place for restore. Inside an `AppShell`, the shell's hiding wins over `hide`: while it hides the panels and keeps the tools (Shift+Tab, `ShellCx::panels_hidden`), only the panels an `Except` names stay, docked or floating (a toolbar); while it hides the dock (Tab), no panel shows. Protected panels always show. +Props: `hide` (`HidePanels::None`, `All` or `Except`), `maximized`, `auto_collapse`, `locked`, and `flyout`, which binds the open flyout to the host's value (the area keeps it otherwise). A hidden panel keeps its place for restore. Inside an `AppShell`, the shell's hiding wins over `hide`: while it hides the panels and keeps the tools (Shift+Tab, `ShellCx::panels_hidden`), only the panels an `Except` names stay, docked or floating (a toolbar); while it hides the dock (Tab), no panel shows. Under Tab and Shift+Tab, an edge the pointer reveals (`ShellCx::edge_revealed`) shows its `Start` or `End` dock, with the host's `hide` applied to it. Protected panels always show. A panel in a column collapsed to icons shows in its flyout (`Layout::opens_in_flyout`). The host opens and closes it by writing the `flyout` binding, not the layout: `WindowMenuRows` checks such a panel's row while its flyout is open (`WindowMenuRows::flyout`) and reports a pick in `WindowMenuRowsOutput::flyout`.