dock: DockArea::continue_move hands the held press to the floating window holding a panel

This commit is contained in:
bflatastic
2026-11-22 06:38:48 +07:00
parent 67b79a74a4
commit 3bd9464c4e
2 changed files with 65 additions and 4 deletions
+23 -2
View File
@@ -141,6 +141,8 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
/// binding: the panel shows in its flyout, and the layout does not change.
#[prop]
flyout: Option<Bind<'a, Option<P>>>,
/// The panel whose floating window takes over the held press this pass, and where the window holds the pointer.
continue_move: Option<(P, Vec2)>,
}
impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
@@ -166,6 +168,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
auto_collapse: false,
locked: false,
flyout: None,
continue_move: None,
}
}
@@ -180,6 +183,16 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
) -> Self {
DockArea { locked: true, ..Self::new(label, Bind::given(Arc::clone(workspace)), specs, panels, config) }
}
/// The floating window holding `panel` takes over the held primary press in this pass, with the pointer at `grab`
/// inside the window ([`FloatingGroup::continue_move`]): the window follows the pointer and docks where it would
/// dock on release. A request of the pass: a host that floats a panel from a rail's `torn_off` keeps it for the one
/// pass after, when the window shows. Without a held press, or when no window holds `panel`, it does nothing.
#[must_use]
pub fn continue_move(mut self, panel: P, grab: Vec2) -> Self {
self.continue_move = Some((panel, grab));
self
}
}
/// What the area keeps in its root container.
@@ -277,6 +290,8 @@ struct Scene<'s, P> {
space: &'s FloatSpace<P>,
bounds: Rect,
auto_collapse: bool,
/// The panel whose window takes over the held press, with its grab point (`DockArea::continue_move`).
continue_move: Option<(&'s P, Vec2)>,
rtl: bool,
/// The docked places floating panels left, for Dock Panel.
floated: &'s [(P, Location<P>)],
@@ -409,7 +424,7 @@ struct Pass<'s, P> {
impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
/// Shows the area across the room offered.
pub fn show(self, ui: &mut Ui) -> DockAreaOutput<P> {
let DockArea { label, mut workspace, specs, panels, config, hide, maximized, auto_collapse, locked, mut flyout } = self;
let DockArea { label, mut workspace, specs, panels, config, hide, maximized, auto_collapse, locked, mut flyout, continue_move } = self;
let ctx = ui.ctx().clone();
let (rtl, window) = {
let env = Env::of(ui);
@@ -464,6 +479,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
model: key,
maximized: maximized.as_ref(),
auto_collapse,
continue_move: continue_move.as_ref().map(|(panel, grab)| (panel, *grab)),
sizes,
rtl,
};
@@ -566,6 +582,7 @@ struct Input<'i, P> {
model: ModelKey,
maximized: Option<&'i P>,
auto_collapse: bool,
continue_move: Option<(&'i P, Vec2)>,
sizes: DockSizes,
rtl: bool,
}
@@ -592,7 +609,7 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
panels: &mut dyn DockPanels<P>,
mut flyout: Option<&mut Bind<'_, Option<P>>>,
) -> Passed<P> {
let Input { id, ctx, current, config, specs, keys, hide, model, maximized, auto_collapse, sizes, rtl } = *input;
let Input { id, ctx, current, config, specs, keys, hide, model, maximized, auto_collapse, continue_move, sizes, rtl } = *input;
let shell = body.shell();
let mut memory = body.memory::<AreaMemory<P>>().clone();
let protected = |panel: &P| rights.get(panel).is_some_and(|rights| rights.is_protected());
@@ -613,6 +630,7 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
space: &space,
bounds,
auto_collapse,
continue_move,
rtl,
floated: current.floated(),
};
@@ -1359,6 +1377,9 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
if let Some(scale) = scale {
group = group.scale(scale);
}
if let Some((_, grab)) = scene.continue_move.filter(|(panel, _)| window.panels().any(|held| held == *panel)) {
group = group.continue_move(grab);
}
group = match opening.spec.clone() {
Some(window_spec) => group.native(window_spec),
None => group.bounds(scene.bounds),
@@ -62,6 +62,8 @@ struct Bed {
float_height: Rc<Cell<f32>>,
/// The height above a floating window's body (`FloatSpace::chrome`), as the area reported it.
chrome: Rc<Cell<f32>>,
/// The panel whose window the next pass asks to continue the held press, with its grab point.
hand_over: Rc<Cell<Option<(usize, Vec2)>>>,
}
fn bed(layout: Layout<usize>) -> Bed {
@@ -76,12 +78,18 @@ fn bed_with(layout: Layout<usize>, config: DockConfig) -> Bed {
let chrome = Rc::new(Cell::new(0.0));
let (held, seen_actions, shows_second, seen_height) = (Rc::clone(&workspace), Rc::clone(&actions), Rc::clone(&second), Rc::clone(&float_height));
let seen_chrome = Rc::clone(&chrome);
let hand_over: Rc<Cell<Option<(usize, Vec2)>>> = Rc::default();
let asked = Rc::clone(&hand_over);
let mut other = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![SECOND], 0)), Vec::new())));
let specs = Tracked::new(Numbered);
let mut fixture = Fixture::new(move |ui| {
let mut workspace = held.borrow().clone();
let mut panels = Panels;
let out = DockArea::new("Floating dock", Bind::bound(&mut workspace), &specs, &mut panels, config.clone()).show(ui);
let mut area = DockArea::new("Floating dock", Bind::bound(&mut workspace), &specs, &mut panels, config.clone());
if let Some((panel, grab)) = asked.take() {
area = area.continue_move(panel, grab);
}
let out = area.show(ui);
*held.borrow_mut() = workspace;
seen_actions.borrow_mut().extend(out.actions);
if let Some(space) = out.float_space {
@@ -93,7 +101,7 @@ fn bed_with(layout: Layout<usize>, config: DockConfig) -> Bed {
}
});
fixture.settle();
Bed { fixture, workspace, actions, second, float_height, chrome }
Bed { fixture, workspace, actions, second, float_height, chrome, hand_over }
}
/// A point on the floating window's title row, on its band: clear of the actions and the double arrow at its end.
@@ -221,6 +229,38 @@ fn a_dragged_floating_window_stands_under_the_pointer_in_each_frame_and_moves_on
assert!(rect.is_some_and(|rect| (rect.min - (WINDOW_AT.min + step * 4.0)).length() < SLACK), "the drop moves the window: {rect:?}");
}
/// A floating window the host asks to continue the held press takes it over from the tab it went down on: the window
/// follows the pointer at the grab point with its dock drag running, and the release lands it. Asked for a panel no
/// window holds, no window takes the press.
#[trial]
fn a_window_asked_to_continue_the_held_press_follows_the_pointer() {
let grab = Vec2::new(40.0, 12.0);
let follows = |panel: usize| {
let mut bed = bed(with_window(Some(Node::tabs(vec![DOCKED], 0))));
let tab = bed.fixture.by_role(Role::TAB).into_iter().find(|tab| !WINDOW_AT.contains(tab.center())).expect("the docked tab shows");
let from = tab.center();
bed.fixture.frame(vec![moved(from)]);
bed.fixture.frame(vec![press(from)]);
bed.hand_over.set(Some((panel, grab)));
bed.fixture.frame(Vec::new());
let to = from + Vec2::new(60.0, 120.0);
for step in 1..=4 {
bed.fixture.frame(vec![moved(from + (to - from) * (step as f32 / 4.0))]);
}
let follows = layer_rects(bed.fixture.ctx()).iter().any(|rect| (rect.min + grab - to).length() < SLACK);
(bed, follows, to)
};
let (mut bed, followed, to) = follows(WINDOW);
assert!(followed, "the window holds the pointer at its grab point: {:?}", layer_rects(bed.fixture.ctx()));
assert!(dragging(&bed), "the move runs the window's dock drag");
let before = bed.workspace.borrow().layout().clone();
bed.fixture.frame(vec![release(to)]).settle();
assert!(*bed.workspace.borrow().layout() != before, "the release lands the window: {:?}", bed.actions.borrow());
let (_, followed, _) = follows(DOCKED);
assert!(!followed, "no window holds the docked panel, so none takes the press");
}
/// A dock area's first pass leaves a drag running in another area alone.
#[trial]
fn an_areas_first_pass_keeps_a_running_drag() {