From ee5be1ccddaa4c8ca7c1cfe61f3ac03db4b5d984 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 03:33:54 +0000 Subject: [PATCH] panels-w1: written from its sheet --- crates/behavior/src/dock/apply.rs | 5 +- crates/behavior/src/dock/inner.rs | 3 +- crates/behavior/src/dock/workspace.rs | 58 +++++++++++--- crates/behavior/tests/dock_apply.rs | 35 +++++++++ crates/ui-panels/src/docking/commands/dock.rs | 46 +++++++---- crates/ui-panels/src/docking/floating.rs | 35 ++++++++- crates/ui-panels/src/docking/rail.rs | 27 +++++-- crates/ui-panels/src/docking/window_menu.rs | 3 +- crates/ui-patterns/src/patterns/dock/area.rs | 77 +++++++++++++++---- crates/ui-patterns/tests/it/docking/native.rs | 24 ++++++ 10 files changed, 262 insertions(+), 51 deletions(-) diff --git a/crates/behavior/src/dock/apply.rs b/crates/behavior/src/dock/apply.rs index 93b1d5229..6e92e556f 100644 --- a/crates/behavior/src/dock/apply.rs +++ b/crates/behavior/src/dock/apply.rs @@ -50,7 +50,10 @@ impl Layout

{ return Err(DockError::NotAllowed); } } - Action::Float { panel, .. } if !permissions(panel).floatable || !permissions(panel).movable => return Err(DockError::NotAllowed), + // Floating an absent panel opens it and moves nothing, so it works in a locked workspace too. + Action::Float { panel, .. } if self.contains(panel) && (!permissions(panel).floatable || !permissions(panel).movable) => { + return Err(DockError::NotAllowed); + } Action::Close { panel } if !permissions(panel).closable => return Err(DockError::NotAllowed), // The rectangle belongs to the whole floating window, so every panel in it must allow it. Action::MoveFloating { panel, .. } diff --git a/crates/behavior/src/dock/inner.rs b/crates/behavior/src/dock/inner.rs index 42c05772f..0cbec3de3 100644 --- a/crates/behavior/src/dock/inner.rs +++ b/crates/behavior/src/dock/inner.rs @@ -46,7 +46,8 @@ impl Layout

{ } // A window's only panel keeps the window's id. let lone = self.floating.iter().find(|w| w.contains(&panel)).filter(|w| w.panels().count() == 1).map(|w| w.id); - let entry = self.take(&panel).ok_or(DockError::MissingPanel)?; + // A panel the layout does not hold opens in the new window. + let entry = self.take(&panel).unwrap_or(StackEntry { panel: panel.clone(), open: true, height: None }); let window = Floating::single(vec![entry.panel], 0, rect); self.floating.push(Floating { id: lone.unwrap_or(window.id), ..window }); Ok(()) diff --git a/crates/behavior/src/dock/workspace.rs b/crates/behavior/src/dock/workspace.rs index e4473cdee..c7c344924 100644 --- a/crates/behavior/src/dock/workspace.rs +++ b/crates/behavior/src/dock/workspace.rs @@ -9,6 +9,7 @@ use std::{collections::HashSet, hash::Hash}; use super::{ DockSide, action::{Action, DockPlacement, Location}, + groups::PanelPlace, layout::Layout, limits::MAX_PANELS, policy::{DockError, Permissions}, @@ -129,17 +130,26 @@ impl Workspace

{ for action in actions { let closed = proposed.layout.closed_by(&action)?; let locations = close_locations(&proposed.layout, &closed); - // SetNative records where the window system has a floating window, so a lock - // does not refuse it. - if matches!(action, Action::SetNative { .. }) { - proposed.layout.apply_with_permissions(action, &permissions)?; - } else { - proposed.layout.apply_with_permissions(action, policy)?; + let before = proposed.layout.clone(); + // Opening a hidden panel puts it back where it was. + let reopened = match &action { + Action::Open { panel, .. } if proposed.hidden.iter().any(|(p, _)| p == panel) => proposed.reopen(panel)?, + _ => false, + }; + if !reopened { + // SetNative records where the window system has a floating window, so a lock + // does not refuse it. + if matches!(action, Action::SetNative { .. }) { + proposed.layout.apply_with_permissions(action, &permissions)?; + } else { + proposed.layout.apply_with_permissions(action, policy)?; + } } for (panel, location) in locations { proposed.hidden.retain(|(p, _)| p != &panel); proposed.hidden.push((panel, location)); } + proposed.track_floated(&before); all_closed.extend(closed); } let visible: HashSet

= proposed.layout.panels().into_iter().cloned().collect(); @@ -176,15 +186,35 @@ impl Workspace

{ if self.layout.contains(&panel) { return self.apply(Action::Activate { panel }, false, |_| Permissions::default()).map(drop); } + let open = Action::Open { panel: panel.clone(), anchor: fallback }; + self.apply_all([open, Action::Activate { panel }], locked, permissions).map(drop) + } + + /// Restore a hidden `panel` to its recorded place and make it the active tab. `Ok(false)` when the record + /// cannot be restored, which leaves the workspace as it was. + fn reopen(&mut self, panel: &P) -> Result { let mut layout = self.layout.clone(); - if self.restore_from_hidden(&mut layout, &panel).is_err() { - layout = self.layout.clone(); - layout.apply_with_permissions(Action::Open { panel: panel.clone(), anchor: fallback }, &permissions)?; + if self.restore_from_hidden(&mut layout, panel).is_err() { + return Ok(false); } layout.apply(Action::Activate { panel: panel.clone() })?; self.layout = layout; - self.hidden.retain(|(p, _)| p != &panel); - Ok(()) + self.hidden.retain(|(p, _)| p != panel); + Ok(true) + } + + /// Update the floated records after an action that turned `before` into the current layout: drop the records of + /// panels that no longer float, and record the docked place of each panel that floats now and did not before. + fn track_floated(&mut self, before: &Layout

) { + let layout = &self.layout; + self.floated.retain(|(p, _)| floats(layout, p)); + let fresh: Vec<(P, Location

)> = layout + .panels() + .into_iter() + .filter(|p| floats(layout, p) && before.contains(p) && !floats(before, p) && !self.floated.iter().any(|(q, _)| q == *p)) + .filter_map(|p| before.location(p).ok().map(|location| (p.clone(), location))) + .collect(); + self.floated.extend(fresh); } /// Restore `panel` where the chain of hidden anchors from its location ends, else at the @@ -243,6 +273,7 @@ impl Workspace

{ self.layout.take(panel); } self.hidden.extend(locations); + self.floated.retain(|(p, _)| registered(p)); let known: HashSet

= self.layout.panels().into_iter().chain(self.hidden.iter().map(|(p, _)| p)).cloned().collect(); let mut missing: Vec<(P, Location

)> = Vec::new(); for panel in default.layout.panels() { @@ -288,6 +319,11 @@ impl Workspace

{ } } +/// Whether `panel` is in a floating window of `layout`. +fn floats(layout: &Layout

, panel: &P) -> bool { + matches!(layout.place(panel), Some(PanelPlace::Floating { .. })) +} + /// Where each of `closed` goes back, captured as if they closed last to first. Reopening them /// first to last rebuilds the group: the first restores the group itself, the rest join it. fn close_locations(layout: &Layout

, closed: &[P]) -> Vec<(P, Location

)> { diff --git a/crates/behavior/tests/dock_apply.rs b/crates/behavior/tests/dock_apply.rs index 4dc1b25a7..58a758e6b 100644 --- a/crates/behavior/tests/dock_apply.rs +++ b/crates/behavior/tests/dock_apply.rs @@ -168,3 +168,38 @@ fn only_a_replacement_changes_the_live_revision() { let loaded: Workspace = serde_json::from_str(&serde_json::to_string(&live).unwrap()).unwrap(); assert_eq!(loaded, live, "the revision is not saved and not part of equality"); } + +/// Open of a hidden panel follows its record: a floating panel returns to its window; a record whose anchor is gone +/// falls back to the anchor Open names. +#[test] +fn opening_a_closed_floating_panel_restores_its_window_place() { + let mut workspace = Workspace::new(docked()); + workspace.apply(Action::close(8), false, allow).unwrap(); + assert!(workspace.layout.place(&8).is_none()); + workspace.apply(Action::open(8, Some(11)), false, allow).unwrap(); + assert!(matches!(workspace.layout.place(&8), Some(PanelPlace::Floating { .. })), "back in its window"); + assert!(workspace.hidden.is_empty()); + + let mut stray = workspace.layout.location(&5).unwrap(); + stray.anchor = Some(99); + workspace.hidden.push((50, stray)); + workspace.apply(Action::open(50, Some(11)), false, allow).unwrap(); + assert_eq!(group_members(&workspace.layout, 11), [11, 12, 50]); +} + +/// A panel that floats keeps its docked place until it docks or closes; floating again from the float keeps the first. +#[test] +fn a_floated_panel_keeps_where_it_was_docked_until_it_docks_or_closes() { + let mut workspace = Workspace::new(docked()); + let docked_at = workspace.layout.location(&2).unwrap(); + workspace.apply(Action::float(2, rect(10.0, 10.0, 200.0, 200.0)), false, allow).unwrap(); + assert_eq!(workspace.floated, [(2, docked_at.clone())]); + workspace.apply(Action::float(2, rect(30.0, 30.0, 200.0, 200.0)), false, allow).unwrap(); + assert_eq!(workspace.floated, [(2, docked_at)], "floating again from the float keeps the first record"); + workspace.apply(Action::move_beside(2, 11, DockPlacement::tab(None)), false, allow).unwrap(); + assert!(workspace.floated.is_empty(), "docking drops the record"); + workspace.apply(Action::float(3, rect(10.0, 10.0, 200.0, 200.0)), false, allow).unwrap(); + assert_eq!(workspace.floated.len(), 1); + workspace.apply(Action::close(3), false, allow).unwrap(); + assert!(workspace.floated.is_empty(), "closing drops the record"); +} diff --git a/crates/ui-panels/src/docking/commands/dock.rs b/crates/ui-panels/src/docking/commands/dock.rs index 23f67c720..1ee24161e 100644 --- a/crates/ui-panels/src/docking/commands/dock.rs +++ b/crates/ui-panels/src/docking/commands/dock.rs @@ -4,7 +4,7 @@ use crate::docking::drop::{beside, members, moving_panels, to_target}; use crate::docking::{DockEvent, DragUnit, FloatSpace}; use crate::runtime::commands::CommandState; use craft_behavior::DockSide; -use craft_behavior::dock::{Action, DockEdge, DockError, DockPlacement, Layout, Node, PanelPlace, Permissions, Target, node_at}; +use craft_behavior::dock::{Action, DockEdge, DockError, DockPlacement, Layout, Location, Node, PanelPlace, Permissions, Target, node_at}; use egui::{Rect, Vec2}; use std::hash::Hash; @@ -20,6 +20,9 @@ pub enum DockCommands { /// Float the panel's tab group into its own frame. #[command(label = "Float Tab Group")] FloatGroup, + /// Dock the floating panel: back where it was docked, else as a tab of the first docked panel. + #[command(label = "Dock Panel")] + DockPanel, /// Ask for a group to move the panel to; the host lists [`Layout::move_targets`] and calls [`move_actions`]. #[command(label = "Move Panel To…")] MovePanelTo, @@ -89,13 +92,21 @@ pub struct DockScene<'a, P> { source: Option, locked: bool, permissions: &'a dyn Fn(&P) -> Permissions, + floated: &'a [(P, Location

)], } impl<'a, P> DockScene<'a, P> { /// A scene over `layout`. `locked` is `WorkspaceSet::locked`; `permissions` is what the host passes to /// `Workspace::apply_all`. pub fn new(layout: &'a Layout

, space: &'a FloatSpace

, locked: bool, permissions: &'a dyn Fn(&P) -> Permissions) -> Self { - DockScene { layout, space, source: None, locked, permissions } + DockScene { layout, space, source: None, locked, permissions, floated: &[] } + } + + /// The docked places floating panels left (`Workspace::floated`), which Dock Panel returns them to. + #[must_use] + pub fn floated(mut self, records: &'a [(P, Location

)]) -> Self { + self.floated = records; + self } /// The size of the group or window the command runs from, which a float of it takes. @@ -170,23 +181,26 @@ pub fn actions(scene: &DockScene<'_, P>, command: DockComm shown()?; Ok(float_actions(scene, &DragUnit::Group(panel.clone()))) } + DockCommands::DockPanel => { + shown()?; + let back = scene.floated.iter().find(|(p, _)| p == panel).and_then(|(_, location)| { + let anchor = location.anchor.clone()?; + let docked = layout.place(&anchor).is_some_and(|place| !matches!(place, PanelPlace::Floating { .. })); + docked.then(|| Action::move_beside(panel.clone(), anchor, location.placement.clone())) + }); + match back { + Some(action) => one(action), + None => move_actions(scene, &DragUnit::Panel(panel.clone()), DockTo::Docked), + } + } DockCommands::ClosePanel => one(Action::close(panel.clone())), DockCommands::CloseOthers => one(Action::close_others(panel.clone())), DockCommands::CloseGroup => one(Action::close_group(panel.clone())), DockCommands::StepGroupUp => one(Action::step_group(panel.clone(), true)), DockCommands::StepGroupDown => one(Action::step_group(panel.clone(), false)), DockCommands::ToggleMinimized => { - let place = layout.place(panel).ok_or(DockError::MissingPanel)?; - // An accordion entry is minimized while it is closed. - let current = match &place { - PanelPlace::Node(_) => match layout.node_of(&place) { - Some(Node::Stack { entries, .. }) => entries.iter().any(|entry| &entry.panel == panel && !entry.open), - _ => false, - }, - PanelPlace::Floating { window, .. } => layout.floating.get(*window).is_some_and(|window| window.minimized), - _ => layout.group(&place).is_some_and(|group| group.minimized), - }; - one(Action::set_minimized(panel.clone(), !current)) + shown()?; + one(Action::set_minimized(panel.clone(), !crate::docking::rail::minimized(layout, panel))) } DockCommands::CollapseToIcons => { let place = layout.place(panel).ok_or(DockError::MissingPanel)?; @@ -268,6 +282,12 @@ pub fn dock_states(scene: &DockScene<'_, P>, panel: &P) -> vec![ (DockCommands::FloatPanel, enabled(floatable)), (DockCommands::FloatGroup, enabled(floatable)), + ( + DockCommands::DockPanel, + enabled( + floating && allowed.movable && layout.panels().into_iter().any(|p| !matches!(layout.place(p), Some(PanelPlace::Floating { .. }))), + ), + ), (DockCommands::MovePanelTo, enabled(movable)), (DockCommands::MoveGroupTo, enabled(movable)), (DockCommands::ClosePanel, enabled(shown && allowed.closable)), diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index 7bea6a382..beb0d449a 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -11,8 +11,8 @@ use crate::contract::BodyCx; use crate::contract::SizeLimits; use crate::contract::overlay::{PlacementChange, PlacementKind, Popup}; use crate::contract::{ - Bind, BindMut, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, Inner, Mount, NoValue, Outcome, Overlay, Pad, - Pointer as _, Props as _, Role, Show as _, ShowContainer as _, Sizing, WordSetCx as _, + Bind, BindMut, Common, Component, Container, ContainerProps, Cx, DragBand, DropMark, DropOperation, HeaderRegion, Inner, Mount, NoValue, OsFiles, + Outcome, Overlay, Pad, Pointer as _, Props as _, Role, Show as _, ShowContainer as _, Sizing, WindowDropTarget, WordSetCx as _, }; use crate::runtime::drag::OsFile; use crate::runtime::env::{Env, Label}; @@ -31,6 +31,23 @@ mod stories; /// The actions a floating group's title row shows unless `actions` says otherwise. const ACTIONS: [HeaderAction; 3] = [HeaderAction::Menu, HeaderAction::Float, HeaderAction::Close]; +/// The whole window of a native floating group as a target for files from the OS. +struct OsWindowFiles { + rect: Rect, +} + +impl WindowDropTarget for OsWindowFiles { + type Drop = OsFiles; + + fn accept(&self, payload: &OsFiles, _op: DropOperation) -> Option { + (!payload.files.is_empty()).then(|| payload.clone()) + } + + fn mark(&self, _drop: &OsFiles) -> DropMark { + DropMark::Into(self.rect) + } +} + /// The style of a floating group: the surface and padding come from the container. #[derive(Clone, Debug, Default, PartialEq, ComponentStyle)] #[non_exhaustive] @@ -124,6 +141,8 @@ pub struct FloatingGroup<'a> { take_drop: Option>, /// A move by the title began this pass. moving: bool, + /// The files dropped on the group's OS window that no target there took. + files: Vec, } type StartDrag<'a> = Box FnOnce(&'b mut Cx<'c, FloatingGroup<'a>>) + 'a>; @@ -158,6 +177,7 @@ impl<'a> FloatingGroup<'a> { start_drag: None, take_drop: None, moving: false, + files: Vec::new(), } .label(title) } @@ -254,6 +274,13 @@ impl Component for FloatingGroup<'_> { take(cx); self.take_drop = Some(take); } + // A layer float lies in the app window, whose own targets take those drops. + if self.native.is_some() { + let target = OsWindowFiles { rect: cx.rect }; + if let Some(dropped) = cx.window_drop_target::(&target) { + self.files = dropped.files; + } + } } fn finish(mut self, mut cx: Cx<'_, Self>) -> FloatingGroupOutput { @@ -273,8 +300,8 @@ impl Component for FloatingGroup<'_> { placed: self.placed, action: self.taken, minimized_toggled: self.toggled, - files: Vec::new(), - }; // P3(panels-w1): pn.C8 + files: self.files, + }; native::raise(&cx.core.ctx, &output); native::fade(&cx.core.ctx, &output); output diff --git a/crates/ui-panels/src/docking/rail.rs b/crates/ui-panels/src/docking/rail.rs index f9efd05d5..952427876 100644 --- a/crates/ui-panels/src/docking/rail.rs +++ b/crates/ui-panels/src/docking/rail.rs @@ -1,17 +1,34 @@ //! What a rail icon does for a panel and whether it shows lit, from the dock layout. -use craft_behavior::dock::{Action, Layout}; +use craft_behavior::dock::{Action, Layout, Node, PanelPlace, PanelState}; use std::hash::Hash; +/// Whether the group, window or accordion section of `panel` is minimized. An accordion entry is minimized while it +/// is closed. A panel the layout does not hold is not. +pub(crate) fn minimized(layout: &Layout

, panel: &P) -> bool { + let Some(place) = layout.place(panel) else { return false }; + match &place { + PanelPlace::Node(_) => match layout.node_of(&place) { + Some(Node::Stack { entries, .. }) => entries.iter().any(|entry| &entry.panel == panel && !entry.open), + _ => false, + }, + PanelPlace::Floating { window, .. } => layout.floating.get(*window).is_some_and(|window| window.minimized), + _ => layout.group(&place).is_some_and(|group| group.minimized), + } +} + /// The actions a click on the rail icon of `panel` takes: minimize a docked and shown panel, restore and activate a /// minimized one, close a floating one's window, open a hidden one. pub fn rail_actions(layout: &Layout

, panel: &P) -> Vec> { - let _ = (layout, panel); - todo!("pn.C3") + match layout.place(panel) { + None => vec![Action::open(panel.clone(), None)], + Some(PanelPlace::Floating { .. }) => vec![Action::close_window(panel.clone())], + Some(_) if minimized(layout, panel) => vec![Action::set_minimized(panel.clone(), false), Action::activate(panel.clone())], + Some(_) => vec![Action::set_minimized(panel.clone(), true)], + } } /// Whether the rail icon of `panel` shows lit: its group is in the layout and not minimized. pub fn rail_lit(layout: &Layout

, panel: &P) -> bool { - let _ = (layout, panel); - todo!("pn.C4") + layout.panel_state(panel) != PanelState::Hidden && !minimized(layout, panel) } diff --git a/crates/ui-panels/src/docking/window_menu.rs b/crates/ui-panels/src/docking/window_menu.rs index 4f5d7fa73..0c6037ebe 100644 --- a/crates/ui-panels/src/docking/window_menu.rs +++ b/crates/ui-panels/src/docking/window_menu.rs @@ -10,7 +10,8 @@ use std::hash::Hash; /// One check row per panel in the order the app gives, for a Window menu. A row is checked while its panel is in the /// layout (closed panels are not), and its label and icon come from [`DockPanels::spec`]. A pick returns the action /// that shows the panel (open a closed one, bring a panel behind another tab to the front) or closes it (a panel -/// showing); the app applies it through the same path as the actions of a `DockArea`. +/// showing); the app applies it through the same path as the actions of a `DockArea`. A Hidden pick's `Action::open` +/// restores the panel's last place through `Workspace::apply_all`. #[derive(crate::contract::Pattern)] #[pattern(probe(WindowMenuRows<'static, u32>))] pub struct WindowMenuRows<'a, P> { diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 71a688406..4c483ffaa 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -10,8 +10,8 @@ use crate::docking::tree::FrameRules; use crate::docking::{Arrangement, cross_window, end_replaced_drags, float_drop, native}; use crate::docking::{ DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene, DockSizes, DockSpot, - DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, GroupAt, GroupDrag, HidePanels, IconicColumn, PanelDrag, PanelKey, - PanelSpec, PanelTitle, SplitArea, actions, dock_states, fit_widths, frame, move_actions, + DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels, IconicColumn, PanelDrag, + PanelKey, PanelSpec, PanelTitle, SplitArea, actions, dock_states, fit_widths, frame, move_actions, }; use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow}; use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within}; @@ -20,7 +20,7 @@ use crate::runtime::env::{Env, Label, RevealEdge, ShellCx, ShellEntry}; use crate::runtime::memory::Remember as _; use crate::runtime::windows::WindowHost; use crate::sections::HeaderAction; -use craft_behavior::dock::{Action, Column, DockEdge, DockError, Group, Layout, Node, PanelPlace, Permissions, Workspace, node_at}; +use craft_behavior::dock::{Action, Column, DockEdge, DockError, Group, Layout, Location, Node, PanelPlace, Permissions, Workspace, node_at}; use craft_behavior::{CancelReason, DockSide, EditEvent, EditEvents, Flow, GestureId, GesturePhase, Mixed, Proposal}; use egui::{Context, Id, Pos2, Rect, Response, Ui, Vec2}; use std::cell::{Cell, RefCell}; @@ -200,6 +200,8 @@ struct Report

{ picked: Option

, flyout: Vec>>, placed: Vec<(P, Rect)>, + /// The files dropped on the floating windows that no target there took. + files: Vec, } /// What every part of one pass reads. @@ -215,6 +217,8 @@ struct Scene<'s, P> { bounds: Rect, auto_collapse: bool, rtl: bool, + /// The docked places floating panels left, for Dock Panel. + floated: &'s [(P, Location

)], } impl Scene<'_, P> { @@ -240,6 +244,7 @@ struct Passed

{ edit: EditEvents>, space: Option>, columns: Vec<(P, Rect)>, + files: Vec, } /// How a group is shown: minimized, and whether it is an accordion section (with its open state). @@ -265,6 +270,8 @@ struct ColumnWork

{ resized: Vec<(P, f32)>, /// The expanded width the user gave an expanded column, or the iconic width of an iconic one. width: Option, + /// The size the user gave an iconic column's open flyout. + flyout: Option>, } /// The parts of one pass with the host's panels and what they reported. @@ -346,7 +353,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { } passed = Some(result); }); - let Passed { actions, events, focused, picked, edit, space, columns } = passed.unwrap_or_else(|| Passed { + let Passed { actions, events, focused, picked, edit, space, columns, files } = passed.unwrap_or_else(|| Passed { actions: Vec::new(), events: Vec::new(), focused: None, @@ -354,6 +361,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { edit: EditEvents::new(), space: None, columns: Vec::new(), + files: Vec::new(), }); if shown.output.dropped.is_some() { cross_window::accept_cross_window(&ctx); @@ -367,9 +375,9 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { edit, float_space: space, columns, - window_files: Vec::new(), + window_files: files, response: shown.output.response, - } // P3(panels-w1): pn.C7 + } } } @@ -456,12 +464,33 @@ fn show_area( let layout: &Layout

= &view.layout; let bounds = shell.as_ref().map_or(body.rect, ShellCx::float_bounds); let space = float_space(bounds, &sizes, config, specs); - let scene = Scene { dock: id, sizes, config, layout, specs, permissions: rights, keys: &keys, space: &space, bounds, auto_collapse, rtl }; + let scene = Scene { + dock: id, + sizes, + config, + layout, + specs, + permissions: rights, + keys: &keys, + space: &space, + bounds, + auto_collapse, + rtl, + floated: ¤t.floated, + }; let open = open_of(&mut flyout, body, &memory); let mut pass = Pass { scene: &scene, panels, - report: Report { actions: Vec::new(), events: Vec::new(), focused: None, picked: None, flyout: Vec::new(), placed: Vec::new() }, + report: Report { + actions: Vec::new(), + events: Vec::new(), + focused: None, + picked: None, + flyout: Vec::new(), + placed: Vec::new(), + files: Vec::new(), + }, dock: id, }; @@ -529,6 +558,7 @@ fn show_area( edit, space: Some(space), columns: report.placed, + files: report.files, } } @@ -610,7 +640,11 @@ impl Pass<'_, P> { let scene = self.scene; let config = scene.config; let command = |command: DockCommands| PanelRow::Command(CommandRef::from(command)); + let floating = matches!(scene.layout.place(panel), Some(PanelPlace::Floating { .. })); let mut group = vec![command(DockCommands::FloatPanel)]; + if floating { + group.push(command(DockCommands::DockPanel)); + } let targets = scene.layout.move_targets(panel, |other| scene.permissions(other)); if scene.permissions(panel).movable && !targets.is_empty() { let rows = targets.iter().enumerate().map(|(at, target)| PanelRow::Item(Entry::new(GroupItem::MoveTo(at), scene.spec(target).label))); @@ -620,6 +654,9 @@ impl Pass<'_, P> { if config.close_menu_items { group.extend([command(DockCommands::ClosePanel), command(DockCommands::CloseGroup)]); } + if config.group_order_items && matches!(scene.layout.place(panel), Some(PanelPlace::Dock { .. })) { + group.extend([command(DockCommands::ToggleMinimized), command(DockCommands::StepGroupUp), command(DockCommands::StepGroupDown)]); + } group.push(command(DockCommands::FloatGroup)); if config.close_others_item { group.push(command(DockCommands::CloseOthers)); @@ -642,7 +679,7 @@ impl Pass<'_, P> { let scene = self.scene; let permissions = |panel: &P| scene.permissions(panel); // The area's permissions are narrowed for a locked workspace already. - let mut commands = DockScene::new(scene.layout, scene.space, false, &permissions); + let mut commands = DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated); if let Some(size) = source { commands = commands.source(size); } @@ -661,7 +698,7 @@ impl Pass<'_, P> { let scene = self.scene; let permissions = |panel: &P| scene.permissions(panel); let Some(target) = scene.layout.move_targets(panel, permissions).get(at).map(|target| (*target).clone()) else { return }; - let commands = DockScene::new(scene.layout, scene.space, false, &permissions); + let commands = DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated); if let Ok(planned) = move_actions(&commands, &DragUnit::Panel(panel.clone()), DockTo::tabs(target, None)) { self.report.actions.extend(planned); } @@ -692,7 +729,7 @@ impl Pass<'_, P> { let shown = &members[active]; let (menu, hosted) = self.menu_rows(body, shown); let permissions = |panel: &P| scene.permissions(panel); - let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions), shown); + let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &permissions).floated(scene.floated), shown); let panels = RefCell::new(&mut *self.panels); // The group with `members[at]` shown: as it shows, or as it is measured. let make = |at: usize, minimized: bool| { @@ -806,7 +843,8 @@ impl Pass<'_, P> { .auto_collapse(scene.auto_collapse) .show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at)); self.report.flyout.extend(output.edit.events); - let work = ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width }; + let work = + ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width, flyout: output.flyout }; self.column_work(column, work); } else { let output = DockColumn::new(name.clone(), scene.dock, column, &spec) @@ -816,7 +854,7 @@ impl Pass<'_, P> { .show_groups_at(ui, cell, |group, rect, ui, body| { self.group_of(ui, body, group, GroupAt::Show(rect)); }); - let work = ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width: output.width }; + let work = ColumnWork { iconic: output.iconic, picked: output.picked, resized: output.resized, width: output.width, flyout: None }; self.column_work(column, work); } } @@ -841,6 +879,14 @@ impl Pass<'_, P> { Action::resize_column(first.clone(), width) }); } + if let Some(resize) = work.flyout { + let panel = resize.panel; + self.report.actions.push(Action::resize_flyout_width(panel.clone(), Some(resize.width))); + self.report.actions.push(Action::resize_group(panel.clone(), Some(resize.height))); + if resize.offset.is_some() { + self.report.actions.push(Action::move_flyout_top(panel, resize.offset)); + } + } } /// The floating windows of the pruned layout, each a `FloatingGroup` holding its tree's groups, in an OS window @@ -880,7 +926,7 @@ impl Pass<'_, P> { target.title_bar_docks = scene.config.title_bar_docks; // The window is an instance of the group scope: its menu's command rows reach it, and run on its active // panel through the same path as a docked group's. - let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &policy), &active); + let states = dock_states(&DockScene::new(scene.layout, scene.space, false, &policy).floated(scene.floated), &active); let mut commands = Vec::new(); let spec = scene.spec(&active); let mut group = FloatingGroup::new(spec.label, opening.rect) @@ -930,6 +976,7 @@ impl Pass<'_, P> { self.report.actions.extend(split_resizes(&anchor, &window.root, edited)); } let output = shown.output; + self.report.files.extend(output.files); if let Some(dropped) = dropped.into_inner() { cross_window::accept_cross_window(&ctx); self.report.actions.push(dropped.action); @@ -950,7 +997,7 @@ impl Pass<'_, P> { self.report.actions.push(Action::close_window(anchor.clone())); } Some(HeaderAction::Float) => { - let commands = DockScene::new(scene.layout, scene.space, false, &policy); + let commands = DockScene::new(scene.layout, scene.space, false, &policy).floated(scene.floated); if let Ok(docked) = move_actions(&commands, &DragUnit::Window(anchor.clone()), DockTo::Docked) { self.report.actions.extend(docked); } diff --git a/crates/ui-patterns/tests/it/docking/native.rs b/crates/ui-patterns/tests/it/docking/native.rs index cc8fddaf5..ff9e7aa5c 100644 --- a/crates/ui-patterns/tests/it/docking/native.rs +++ b/crates/ui-patterns/tests/it/docking/native.rs @@ -349,6 +349,30 @@ fn an_app_change_of_a_native_floats_place_moves_its_window_once() { assert_eq!(placing, [&ViewportCommand::OuterPosition(to.min), &ViewportCommand::InnerSize(to.size())], "one move and one size"); } +/// OS files reach `DockAreaOutput::window_files` only from a drop on a native float's own window: with the float's +/// OS window open and nothing dropped, the dock reports no files. +// PLAN: the drop itself cannot be driven yet: the `Windows` kit (`crates/ui-test-kit/src/windows.rs`, outside this +// set) gives a child pass only `Event`s, never `RawInput::dropped_files`. Once the kit lets a frame give the child +// files, this trial drops one file no target takes and one a target takes, and asserts that only the first arrives. +#[trial] +fn a_file_dropped_on_a_native_float_reaches_window_files_once() { + let windows = Windows::new(); + windows.root_info(info(true, ROOT_AT)); + windows.child_info(info(true, PALETTE_AT)); + let mut workspace = Workspace::new(Layout::new(None, vec![float()])); + let mut opened = false; + let mut files = 0; + for _ in 0..4 { + let out = windows.frame(vec![], vec![], |ui| { + let shown = DockArea::new("Native dock", Bind::bound(&mut workspace), &mut Palettes(Permissions::ALL), DockConfig::default()).show(ui); + files += shown.window_files.len(); + }); + opened |= out.builders.iter().any(|(viewport, _)| *viewport != ViewportId::ROOT); + } + assert!(opened, "the float has its own OS window"); + assert_eq!(files, 0, "no drop, no files"); +} + /// A palette float made in the app window. fn float() -> Floating { Floating::single(vec![1], 0, Rect::from_min_size(Pos2::new(40.0, 40.0), Vec2::new(300.0, 200.0)))