mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 04:04:25 +00:00
panels-w1: written from its sheet
This commit is contained in:
@@ -50,7 +50,10 @@ impl<P: Clone + Eq + Hash> Layout<P> {
|
||||
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, .. }
|
||||
|
||||
@@ -46,7 +46,8 @@ impl<P: Clone + Eq + Hash> Layout<P> {
|
||||
}
|
||||
// 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(())
|
||||
|
||||
@@ -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<P: Clone + Eq + Hash> Workspace<P> {
|
||||
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<P> = proposed.layout.panels().into_iter().cloned().collect();
|
||||
@@ -176,15 +186,35 @@ impl<P: Clone + Eq + Hash> Workspace<P> {
|
||||
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<bool, DockError> {
|
||||
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<P>) {
|
||||
let layout = &self.layout;
|
||||
self.floated.retain(|(p, _)| floats(layout, p));
|
||||
let fresh: Vec<(P, Location<P>)> = 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<P: Clone + Eq + Hash> Workspace<P> {
|
||||
self.layout.take(panel);
|
||||
}
|
||||
self.hidden.extend(locations);
|
||||
self.floated.retain(|(p, _)| registered(p));
|
||||
let known: HashSet<P> = self.layout.panels().into_iter().chain(self.hidden.iter().map(|(p, _)| p)).cloned().collect();
|
||||
let mut missing: Vec<(P, Location<P>)> = Vec::new();
|
||||
for panel in default.layout.panels() {
|
||||
@@ -288,6 +319,11 @@ impl<P: Clone + Eq + Hash> Workspace<P> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `panel` is in a floating window of `layout`.
|
||||
fn floats<P: Clone + Eq + Hash>(layout: &Layout<P>, 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<P: Clone + Eq + Hash>(layout: &Layout<P>, closed: &[P]) -> Vec<(P, Location<P>)> {
|
||||
|
||||
@@ -168,3 +168,38 @@ fn only_a_replacement_changes_the_live_revision() {
|
||||
let loaded: Workspace<u32> = 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");
|
||||
}
|
||||
|
||||
@@ -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<Vec2>,
|
||||
locked: bool,
|
||||
permissions: &'a dyn Fn(&P) -> Permissions,
|
||||
floated: &'a [(P, Location<P>)],
|
||||
}
|
||||
|
||||
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<P>, space: &'a FloatSpace<P>, 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<P>)]) -> 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<P: Clone + Eq + Hash>(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<P: Clone + Eq + Hash>(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)),
|
||||
|
||||
@@ -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<OsFiles> for OsWindowFiles {
|
||||
type Drop = OsFiles;
|
||||
|
||||
fn accept(&self, payload: &OsFiles, _op: DropOperation) -> Option<OsFiles> {
|
||||
(!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<TakeDrop<'a>>,
|
||||
/// 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<OsFile>,
|
||||
}
|
||||
|
||||
type StartDrag<'a> = Box<dyn for<'b, 'c> 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::<OsFiles, _>(&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
|
||||
|
||||
@@ -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<P: Clone + Eq + Hash>(layout: &Layout<P>, 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<P: Clone + Eq + Hash>(layout: &Layout<P>, panel: &P) -> Vec<Action<P>> {
|
||||
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<P: Clone + Eq + Hash>(layout: &Layout<P>, panel: &P) -> bool {
|
||||
let _ = (layout, panel);
|
||||
todo!("pn.C4")
|
||||
layout.panel_state(panel) != PanelState::Hidden && !minimized(layout, panel)
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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<P> {
|
||||
picked: Option<P>,
|
||||
flyout: Vec<EditEvent<Option<P>>>,
|
||||
placed: Vec<(P, Rect)>,
|
||||
/// The files dropped on the floating windows that no target there took.
|
||||
files: Vec<drag::OsFile>,
|
||||
}
|
||||
|
||||
/// 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<P>)],
|
||||
}
|
||||
|
||||
impl<P: Clone + Eq + Hash> Scene<'_, P> {
|
||||
@@ -240,6 +244,7 @@ struct Passed<P> {
|
||||
edit: EditEvents<Workspace<P>>,
|
||||
space: Option<FloatSpace<P>>,
|
||||
columns: Vec<(P, Rect)>,
|
||||
files: Vec<drag::OsFile>,
|
||||
}
|
||||
|
||||
/// How a group is shown: minimized, and whether it is an accordion section (with its open state).
|
||||
@@ -265,6 +270,8 @@ struct ColumnWork<P> {
|
||||
resized: Vec<(P, f32)>,
|
||||
/// The expanded width the user gave an expanded column, or the iconic width of an iconic one.
|
||||
width: Option<f32>,
|
||||
/// The size the user gave an iconic column's open flyout.
|
||||
flyout: Option<FlyoutResize<P>>,
|
||||
}
|
||||
|
||||
/// 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
|
||||
let layout: &Layout<P> = &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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
|
||||
edit,
|
||||
space: Some(space),
|
||||
columns: report.placed,
|
||||
files: report.files,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +640,11 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> 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);
|
||||
}
|
||||
|
||||
@@ -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<u32> {
|
||||
Floating::single(vec![1], 0, Rect::from_min_size(Pos2::new(40.0, 40.0), Vec2::new(300.0, 200.0)))
|
||||
|
||||
Reference in New Issue
Block a user