From 20bec4199636f917223d758af9a7dc287adcd87e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 03:54:14 -0500 Subject: [PATCH] pdf-chrome-w7: net change of 1 commits - pdf-chrome-w7: written from its sheet --- crates/ui-canvas/src/canvas/split/mod.rs | 63 ++++++++++++-- crates/ui-canvas/src/canvas/split/stories.rs | 50 ++++++++--- crates/ui-canvas/tests/it/canvas/split.rs | 89 +++++++++++++++++++- 3 files changed, 181 insertions(+), 21 deletions(-) diff --git a/crates/ui-canvas/src/canvas/split/mod.rs b/crates/ui-canvas/src/canvas/split/mod.rs index 321fdefaf..a71c5f7b1 100644 --- a/crates/ui-canvas/src/canvas/split/mod.rs +++ b/crates/ui-canvas/src/canvas/split/mod.rs @@ -6,14 +6,17 @@ //! The panes are the cells [`arrange_rects`] gives for the arrangement the caller names, with the dividers moved to //! the [`SplitAt`] the caller binds ([`SplitAt::placed`]). A linked pane follows the active view's zoom and position //! ([`SplitViews::follow`]). +//! +//! With [`SplitViews::takes_tabs`] the views take a dragged document strip tab: an unsplit body offers its reading-end +//! half, a split body each whole pane, and the drop comes back in [`SplitViewsOutput::tab_drop`]. #[cfg(feature = "testing")] mod stories; use super::words::SplitWords; use crate::contract::{ - Access, Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, Name, Outcome, Pad, PaintUi, PartsCx, - Pointer as _, Props as _, Role, Sizing, WordSetCx as _, + Access, Bind, BindMut, Common, Component, Container, ContainerProps, Cx, DropMark, DropOperation, DropTarget, Edit as _, EditResponse, ListDrag, + Name, Outcome, Pad, PaintUi, PartsCx, Pointer as _, Props as _, Role, Sizing, WordSetCx as _, }; use crate::docking::divider::{self, Divider, Drag}; use crate::docking::{DockSizes, Splitter}; @@ -273,6 +276,41 @@ pub struct TabDrop { pub target: TabDropTarget, } +/// Where a dragged tab may land on `laid` in `rect`, in physical space: each pane of a split body, numbered as `laid` +/// numbers them, or the reading-end half of an unsplit body (the left half under right-to-left). +fn tab_areas(laid: &Laid, rect: Rect, rtl: bool) -> Vec<(TabDropTarget, Rect)> { + let flow = Flow::new(rect, rtl); + if laid.panes.len() > 1 { + laid.panes.iter().enumerate().map(|(pane, area)| (TabDropTarget::Pane(pane), flow.to_physical(*area))).collect() + } else { + let end = Rect::from_min_max(Pos2::new(rect.center().x, rect.top()), rect.max); + vec![(TabDropTarget::SplitEnd, flow.to_physical(end))] + } +} + +/// The views' target for a dragged document strip tab: the area under the pointer, when the caller's rule takes the +/// dragged documents there. The drop carries the area, which the ghost layer marks. +struct TabTarget<'t, D> { + areas: Vec<(TabDropTarget, Rect)>, + accepts: &'t dyn Fn(&[D], TabDropTarget) -> bool, +} + +impl DropTarget> for TabTarget<'_, D> { + type Drop = (TabDrop, Rect); + + fn accept(&self, payload: &ListDrag, at: Pos2, _: DropOperation) -> Option { + let &(target, area) = self.areas.iter().find(|(_, area)| area.contains(at))?; + (self.accepts)(&payload.keys, target).then(|| (TabDrop { documents: payload.keys.clone(), target }, area)) + } + + fn mark(&self, (drop, area): &Self::Drop) -> DropMark { + match drop.target { + TabDropTarget::SplitEnd => DropMark::Split(*area), + TabDropTarget::Pane(_) => DropMark::Into(*area), + } + } +} + impl Outcome for SplitViewsOutput { type Value = SplitAt; @@ -289,7 +327,8 @@ impl Outcome for SplitViewsOutput { /// One canvas area shown as views of one document, or a grid of panes the caller fills (one document each), in the /// panes of a [`SplitLayout`]. The active pane is the app's: it routes tools and keys there. An inactive pane is a /// Tab stop over its view: a press, Enter or Space on it reports it in [`SplitViewsOutput::activated`] and its view -/// gets no press. +/// gets no press. With [`takes_tabs`](SplitViews::takes_tabs) a document strip tab dropped on the views is reported in +/// [`SplitViewsOutput::tab_drop`]. #[derive(crate::contract::Component, crate::contract::Props)] #[component(container, probe(SplitViews<'static, ()>))] pub struct SplitViews<'a, D: Clone + Send + Sync + 'static = ()> { @@ -307,8 +346,9 @@ pub struct SplitViews<'a, D: Clone + Send + Sync + 'static = ()> { #[prop] count: usize, activated: Option, - #[allow(dead_code)] // P3(pdf-chrome-w7): CH-C21 accepts: Option bool + 'a>>, + /// The tab drop released over the views in this pass. + tab_drop: Option>, } impl<'a> SplitViews<'a> { @@ -316,15 +356,15 @@ impl<'a> SplitViews<'a> { /// active until [`active`](Self::active) says otherwise. pub fn new(label: impl Into