mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
A dragged layer stands under the pointer in the frame of each step
The layer host shows a layer whose move band is being dragged at the drag's rect for this pass: the rect the layer had when the band was pressed, moved by the pointer's travel, within its bounds. window_drag runs the drag from the same rect. A caller that places the layer (placed, placed_at, or an anchored layer it places once moved) writes its place once, on the Commit. - The task bar writes its place on the drop only: one edit, no lag. - A floating dock window in the app window reaches the workspace on the drop only; resizes and keyboard moves keep their gesture edits. - A layer root inside an opener's arena steps its press machine early, as its steps 6 to 16 sense in its own arena: the host reads this pass's band press before it places the layer. Trials: a dragged task bar and a dragged floating window stand under the pointer in each frame, in one pass, and are placed once, on the drop.
This commit is contained in:
1 parent
d73c1c337f
commit
658bbcb6bd
9 files changed
+188
-51
No files matched your search
@@ -20,7 +20,7 @@ use crate::runtime::overlay::CloseReason;
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_behavior::overlay::{Align, Side};
|
||||
use craft_behavior::{EditEvent, IconId, Metrics, Mixed, Sense};
|
||||
use craft_behavior::{EditEvent, GesturePhase, IconId, Metrics, Mixed, Sense};
|
||||
use egui::{Pos2, Rect, Response, Ui};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -245,8 +245,7 @@ impl<'a> TaskBar<'a> {
|
||||
let rect = shown.output.response.rect;
|
||||
let pick = menu.pick;
|
||||
if shows && kind == TaskBarKind::Task {
|
||||
let moved = shown.output.moved.filter(|moved| moved.min != rect.min);
|
||||
let next = settled(held, rect, area, moved, pick);
|
||||
let next = settled(held, rect, area, shown.output.moved, pick);
|
||||
if next != held {
|
||||
let word = match pick {
|
||||
Some(MenuPick::Reset) => &words.task_bar_reset,
|
||||
@@ -303,8 +302,8 @@ fn layer_overlay(held: &TaskBarPlace, hang: Option<Rect>, area: Rect, side: Side
|
||||
}
|
||||
}
|
||||
|
||||
/// The place after a pass that showed the bar at `shown`. A move (`moved`, a rect other than `shown`) keeps the bar
|
||||
/// where it was dropped; Reset clears the place; Pin, and a pinned bar with no place, keep the bar at `shown`. A
|
||||
/// The place after a pass that showed the bar at `shown`. A move that ended (`moved`, where it was dropped) keeps the
|
||||
/// bar there; Reset clears the place; Pin, and a pinned bar with no place, keep the bar at `shown`. A
|
||||
/// non-finite place is cleared. With no move and no pick, the place stays unchanged; the overlay host keeps the layer
|
||||
/// inside the area.
|
||||
fn settled(held: TaskBarPlace, shown: Rect, area: Rect, moved: Option<Rect>, pick: Option<MenuPick>) -> TaskBarPlace {
|
||||
@@ -333,7 +332,7 @@ pub struct TaskBarLayerStyle {
|
||||
metrics: Metrics,
|
||||
}
|
||||
|
||||
/// What the task bar's layer reports: its response, the last move of this pass and why it closed.
|
||||
/// What the task bar's layer reports: its response, the move that ended in this pass and why it closed.
|
||||
#[derive(Debug)]
|
||||
struct TaskBarLayerOutput {
|
||||
response: Response,
|
||||
@@ -361,6 +360,8 @@ struct TaskBarLayer {
|
||||
props: ContainerProps,
|
||||
/// Open while the bar shows; the caller shows the bar again each pass it wants it.
|
||||
open: Bind<'static, bool>,
|
||||
/// Where a move by the grip ended in this pass. The layer host shows the bar under the pointer while the move
|
||||
/// runs, so the place is written once, on the drop.
|
||||
moved: Option<Rect>,
|
||||
/// Why the layer closed, once it has.
|
||||
closed: Option<CloseReason>,
|
||||
@@ -411,7 +412,7 @@ impl Container for TaskBarLayer {
|
||||
}
|
||||
|
||||
fn placement_changed(&mut self, change: &PlacementChange) {
|
||||
if change.kind == PlacementKind::Move {
|
||||
if change.kind == PlacementKind::Move && change.phase == GesturePhase::Commit {
|
||||
self.moved = Some(change.rect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use craft_ui::buttons::Button;
|
||||
use craft_ui::canvas_controls::{TaskBar, TaskBarDismiss, TaskBarPlace};
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::testing::canvas_story::on_canvas;
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use std::cell::RefCell;
|
||||
@@ -272,3 +273,39 @@ fn the_grip_sits_on_the_members_line() {
|
||||
let dropped = seen(&scene);
|
||||
assert!((dropped.rect.min - (bar.min + by)).length() < 2.0 * SLACK, "a drag on the grip moves the bar: {:?}", dropped.rect);
|
||||
}
|
||||
|
||||
/// A drag of the grip moves the bar under the pointer in the frame of each step, in one pass, and writes its place
|
||||
/// once, on the drop: one edit for the whole move.
|
||||
#[trial]
|
||||
fn a_dragged_task_bar_stands_under_the_pointer_in_each_frame_and_writes_its_place_on_the_drop() {
|
||||
let scene = Rc::new(RefCell::new(Scene {
|
||||
anchor: frame(DocVec::ZERO),
|
||||
place: TaskBarPlace::default(),
|
||||
bounds: Rect::NOTHING,
|
||||
area: Rect::NOTHING,
|
||||
rect: Rect::NOTHING,
|
||||
}));
|
||||
let mut fixture = fixture(&scene);
|
||||
fixture.settle();
|
||||
let start = seen(&scene).rect;
|
||||
let from = fixture.by_label("Move bar").expect("the grip is named").center();
|
||||
fixture.frame(vec![moved(from)]);
|
||||
fixture.frame(vec![press(from)]);
|
||||
let step = Vec2::new(-30.0, 15.0);
|
||||
for n in 1..=4 {
|
||||
let to = start.min + step * n as f32;
|
||||
fixture.frame(vec![moved(from + step * n as f32)]);
|
||||
let now = seen(&scene);
|
||||
assert!((now.rect.min - to).length() < SLACK, "step {n}: the bar stands under the pointer in its frame: {:?}, wanted {to:?}", now.rect);
|
||||
assert_eq!(fixture.passes(), 1, "step {n}: the frame runs one pass");
|
||||
assert_eq!(now.place, TaskBarPlace::default(), "step {n}: the place is not written while the drag runs");
|
||||
}
|
||||
let dropped_at = start.min + step * 4.0;
|
||||
fixture.frame(vec![release(from + step * 4.0)]);
|
||||
let dropped = seen(&scene);
|
||||
assert!((dropped.rect.min - dropped_at).length() < SLACK, "the bar stays where it was dropped: {:?}", dropped.rect);
|
||||
let at = dropped.place.at.map(|at| dropped.area.min + Vec2::from(at));
|
||||
assert!(at.is_some_and(|at| (at - dropped_at).length() < SLACK), "the drop writes the place: {:?}", dropped.place);
|
||||
fixture.settle();
|
||||
assert!((seen(&scene).rect.min - dropped_at).length() < SLACK, "the written place keeps the bar there: {:?}", seen(&scene).rect);
|
||||
}
|
||||
@@ -68,7 +68,9 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
}
|
||||
|
||||
fn host(&mut self, comp: &C, at: crate::contract::run::HostCx<'_>) -> Box<dyn crate::contract::run::Host> {
|
||||
let mounted = crate::contract::mount::host(comp.props(Internal::new()), &at, self.open, at.label);
|
||||
let props = comp.props(Internal::new());
|
||||
let moving = overlay_of(props).filter(|overlay| overlay.movable).and_then(|_| self.mode.running_move(at.ui.ctx(), at.id));
|
||||
let mounted = crate::contract::mount::host(props, &at, self.open, at.label, moving);
|
||||
if mounted.exiting {
|
||||
self.exiting = true;
|
||||
self.open = true;
|
||||
@@ -185,7 +187,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
Mount::Layer(_) | Mount::Viewport { .. } => {
|
||||
let placement = overlay_of(props).map_or_else(Placement::default, |overlay| {
|
||||
let screen = crate::contract::overlay::screen_for(&ctx, env, overlay);
|
||||
shown_placement(&ctx, id, save.as_ref(), overlay, screen, env.tokens.space.inset.screen)
|
||||
shown_placement(&ctx, id, save.as_ref(), overlay, None, screen, env.tokens.space.inset.screen)
|
||||
});
|
||||
// A layer the user sized takes that size, at its saved position or where its anchor places it.
|
||||
placement.size.is_some()
|
||||
|
||||
@@ -28,8 +28,7 @@ impl Placement {
|
||||
|
||||
/// The placement the caller of `overlay` gives, when it places the layer.
|
||||
fn given(overlay: &crate::contract::Overlay) -> Option<Placement> {
|
||||
let kept = |rect: Rect| overlay.bounds.map_or(rect, |bounds| super::window::keep_inside(rect, bounds));
|
||||
overlay.placed.map(|rect| Placement::at(kept(rect))).or_else(|| overlay.placed_at.map(Placement::at_pos))
|
||||
overlay.placed.map(|rect| Placement::at(super::window::kept_in(rect, overlay.bounds))).or_else(|| overlay.placed_at.map(Placement::at_pos))
|
||||
}
|
||||
|
||||
/// The rect it names, taking the position and size it lacks from `rect`.
|
||||
@@ -46,7 +45,9 @@ pub(crate) fn placement_id(id: Id) -> Id {
|
||||
/// is `placed` has the caller's rect instead: the slot reads it and writes nothing, since the caller owns the
|
||||
/// placement and learns of the user's changes from `PlacementChange` reports. A layer hung from its anchor keeps only
|
||||
/// its size, whether or not the user can move it: each opening places it from its anchor at that size, and a caller
|
||||
/// that keeps a moved layer where it was dropped places it (`placed_at`) from the change it was told of.
|
||||
/// that keeps a moved layer where it was dropped places it (`placed_at`) from the change it was told of. While the
|
||||
/// user drags the move band, the layer host shows the layer at the drag's rect whatever the slot holds
|
||||
/// ([`shown_placement`]), so a caller places it from the drag's `Commit` alone.
|
||||
pub(super) struct PlacementSlot<'s> {
|
||||
stage: &'s mut MemoryStage,
|
||||
id: Id,
|
||||
@@ -96,7 +97,28 @@ fn placement_of(ctx: &Context, id: Id, save: Option<&SaveKey>) -> Placement {
|
||||
/// floating resizable layer with a default size (`Overlay::size`) that size, within the screen less `screen_inset` on
|
||||
/// each side, centred or at the overlay's float position. A saved size and position win over the default. A size with
|
||||
/// no position places an anchored layer from its anchor at that size.
|
||||
///
|
||||
/// While a drag of the layer's move band runs, `moving` is the rect it puts the layer at in this pass
|
||||
/// (`WindowMode::running_move`): the layer shows there, within its bounds, at the size the placement gives. The
|
||||
/// caller's place, the stored one or the anchor applies again once the drag ends.
|
||||
pub(crate) fn shown_placement(
|
||||
ctx: &Context,
|
||||
id: Id,
|
||||
save: Option<&SaveKey>,
|
||||
overlay: &crate::contract::Overlay,
|
||||
moving: Option<Rect>,
|
||||
screen: Rect,
|
||||
screen_inset: f32,
|
||||
) -> Placement {
|
||||
let mut placement = resting_placement(ctx, id, save, overlay, screen, screen_inset);
|
||||
if let Some(moving) = moving {
|
||||
placement.pos = Some(super::window::kept_in(moving, overlay.bounds).min.into());
|
||||
}
|
||||
placement
|
||||
}
|
||||
|
||||
/// The placement a layer is shown at while no drag moves it ([`shown_placement`]).
|
||||
fn resting_placement(
|
||||
ctx: &Context,
|
||||
id: Id,
|
||||
save: Option<&SaveKey>,
|
||||
|
||||
@@ -124,6 +124,9 @@ pub(super) struct WindowMode {
|
||||
kind: Option<WindowModeKind>,
|
||||
restore: Placement,
|
||||
began: Option<Rect>,
|
||||
/// The rect the layer had when a press went down on its move band or a grip, until the press ends: a drag that
|
||||
/// starts from the press runs from it.
|
||||
pressed: Option<Rect>,
|
||||
moving: Option<WindowMove>,
|
||||
sizing: Option<WindowSize>,
|
||||
/// The index in `GRIPS` of the grip a drag holds, from its `DragStart` to its release: `move_parts` keeps it
|
||||
@@ -136,6 +139,23 @@ impl WindowMode {
|
||||
pub(super) fn held(&self) -> Option<usize> {
|
||||
self.held
|
||||
}
|
||||
|
||||
/// The rect a drag of the move band of the layer `id` puts the layer at in this pass, before the bounds keep it:
|
||||
/// the rect the layer had when the press went down, moved by the pointer's travel since. `window_drag` reports the
|
||||
/// same rect for the step. `None` while no move by the band runs. The layer host shows the layer there
|
||||
/// (`shown_placement`) before the container's pass runs, so the layer stands under the pointer in the frame of
|
||||
/// each step, whoever owns its placement.
|
||||
pub(super) fn running_move(&self, ctx: &Context, id: Id) -> Option<Rect> {
|
||||
if self.pressed.is_none() && self.began.is_none() {
|
||||
return None;
|
||||
}
|
||||
let (began, start, pos) = match crate::primitives::sensing::part_press(ctx, id, MOVE_BAND.into()).press.phase {
|
||||
PressPhase::DragStart { start, pos, .. } => (self.pressed?, start, pos),
|
||||
PressPhase::Drag { start, pos, .. } | PressPhase::Release { start, pos, .. } => (self.began?, start, pos),
|
||||
_ => return None,
|
||||
};
|
||||
Some(began.translate(pos - start.origin))
|
||||
}
|
||||
}
|
||||
|
||||
/// A move of a viewport mount's OS window that the app runs (`Overlay::moved_by_app`), from its Begin to its Commit
|
||||
@@ -200,6 +220,11 @@ pub(crate) fn keep_inside(rect: Rect, bounds: Rect) -> Rect {
|
||||
rect.translate(Vec2::new(keep(rect.min.x, rect.max.x, bounds.min.x, bounds.max.x), keep(rect.min.y, rect.max.y, bounds.min.y, bounds.max.y)))
|
||||
}
|
||||
|
||||
/// `rect` kept inside `bounds`, when the layer has bounds.
|
||||
pub(super) fn kept_in(rect: Rect, bounds: Option<Rect>) -> Rect {
|
||||
bounds.map_or(rect, |bounds| keep_inside(rect, bounds))
|
||||
}
|
||||
|
||||
/// What every change of a layer's rect keeps to: the least and most size, and the rect it stays inside.
|
||||
struct Limits {
|
||||
min: Vec2,
|
||||
@@ -214,8 +239,7 @@ impl Limits {
|
||||
|
||||
/// `rect` moved by `delta`, kept inside the bounds.
|
||||
fn moved(&self, rect: Rect, delta: Vec2) -> Rect {
|
||||
let rect = rect.translate(delta);
|
||||
self.bounds.map_or(rect, |bounds| keep_inside(rect, bounds))
|
||||
kept_in(rect.translate(delta), self.bounds)
|
||||
}
|
||||
|
||||
/// `rect` with the edges `dx` and `dy` (-1: low edge, 1: high edge, 0: none) moved by `delta`, within the size
|
||||
@@ -377,14 +401,7 @@ impl BodyHooks<'_> {
|
||||
if mode.kind == Some(kind) {
|
||||
mode = WindowMode::default();
|
||||
} else {
|
||||
mode = WindowMode {
|
||||
kind: Some(kind),
|
||||
restore: current.clone(),
|
||||
began: Some(current.rect_over(rect)),
|
||||
moving: None,
|
||||
sizing: None,
|
||||
held: None,
|
||||
};
|
||||
mode = WindowMode { kind: Some(kind), restore: current.clone(), began: Some(current.rect_over(rect)), ..WindowMode::default() };
|
||||
self.reports.push(step(current.rect_over(rect), GesturePhase::Begin));
|
||||
}
|
||||
}
|
||||
@@ -436,7 +453,8 @@ impl BodyHooks<'_> {
|
||||
}
|
||||
|
||||
/// A drag of the move band or a grip of a layer (not an OS window): the layer follows the pointer within the
|
||||
/// limits, and each step is reported. Escape, which cancels the press, restores the placement from before.
|
||||
/// limits, and each step is reported. The drag runs from the rect the layer had when the press went down. Escape,
|
||||
/// which cancels the press, restores the placement from before.
|
||||
pub(super) fn window_drag<C: Container>(&mut self, props: &ContainerProps, cx: &mut Cx<'_, C>) {
|
||||
let Some(overlay) = overlay_of(props) else { return };
|
||||
// A band that moves the window below starts the OS move of the window the layer is shown in.
|
||||
@@ -455,9 +473,11 @@ impl BodyHooks<'_> {
|
||||
let mut pressed = vec![(None, phase((MOVE_BAND, None)))];
|
||||
pressed.extend((0..GRIPS.len()).map(|index| (Some(index), phase((GRIP, Some(index as u64))))));
|
||||
let Some((grip, phase)) = pressed.into_iter().find_map(|(grip, phase)| match phase? {
|
||||
phase @ (PressPhase::DragStart { .. } | PressPhase::Drag { .. } | PressPhase::Release { .. } | PressPhase::Cancel { .. }) => {
|
||||
Some((grip, phase))
|
||||
}
|
||||
phase @ (PressPhase::Down { .. }
|
||||
| PressPhase::DragStart { .. }
|
||||
| PressPhase::Drag { .. }
|
||||
| PressPhase::Release { .. }
|
||||
| PressPhase::Cancel { .. }) => Some((grip, phase)),
|
||||
_ => None,
|
||||
}) else {
|
||||
return;
|
||||
@@ -465,8 +485,14 @@ impl BodyHooks<'_> {
|
||||
let mut slot = PlacementSlot::new(&mut *cx.core.memory, id, self.save.as_ref(), overlay);
|
||||
let current = slot.read();
|
||||
let (origin, pos, gesture) = match phase {
|
||||
PressPhase::Down { .. } => {
|
||||
self.mode.pressed = Some(current.rect_over(rect));
|
||||
return;
|
||||
}
|
||||
PressPhase::DragStart { start, pos, .. } => {
|
||||
self.mode.began = Some(current.rect_over(rect));
|
||||
// The layer host shows this pass at the step's rect already (`running_move`): the drag runs from where
|
||||
// the layer stood at the press.
|
||||
self.mode.began = Some(self.mode.pressed.unwrap_or_else(|| current.rect_over(rect)));
|
||||
self.mode.restore = current.clone();
|
||||
self.mode.held = grip;
|
||||
(start.origin, Some(pos), GesturePhase::Begin)
|
||||
@@ -476,6 +502,9 @@ impl BodyHooks<'_> {
|
||||
PressPhase::Cancel { start, .. } => (start.origin, None, GesturePhase::Cancel),
|
||||
_ => return,
|
||||
};
|
||||
if matches!(gesture, GesturePhase::Commit | GesturePhase::Cancel) {
|
||||
self.mode.pressed = None;
|
||||
}
|
||||
let Some(began) = self.mode.began else { return };
|
||||
let (dx, dy, _) = grip.map_or((0, 0, CursorIcon::Grab), |index| GRIPS[index]);
|
||||
let kind = if grip.is_some() { PlacementKind::Size(edge_of(dx, dy)) } else { PlacementKind::Move };
|
||||
|
||||
@@ -26,7 +26,8 @@ pub(super) struct Mounted {
|
||||
}
|
||||
|
||||
/// The host for `props.mount`. A layer-like mount of a closed container shows nothing once its exit fade ended.
|
||||
pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: &Label) -> Mounted {
|
||||
/// `moving` is the rect a running drag of the container's move band puts its layer at in this pass.
|
||||
pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: &Label, moving: Option<Rect>) -> Mounted {
|
||||
let ctx = at.ui.ctx();
|
||||
let layer = |overlay: &Overlay| {
|
||||
let presence = if at.ui.is_sizing_pass() {
|
||||
@@ -46,7 +47,7 @@ pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: &
|
||||
Mount::Pane(pane) => Mounted { host: Box::new(PaneHost(*pane)), exiting: false },
|
||||
Mount::Window { .. } => Mounted { host: Box::new(WindowContentHost), exiting: false },
|
||||
Mount::Layer(overlay) => match layer(overlay) {
|
||||
(Some(fade), exiting) => Mounted { host: Box::new(LayerHost::new(overlay.clone(), props, exiting, fade, at.size)), exiting },
|
||||
(Some(fade), exiting) => Mounted { host: Box::new(LayerHost::new(overlay.clone(), props, exiting, fade, at.size, moving)), exiting },
|
||||
(None, _) => closed(),
|
||||
},
|
||||
Mount::FullWindow => full_window(props.focus),
|
||||
@@ -57,7 +58,9 @@ pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: &
|
||||
full_window(fallback.focus)
|
||||
} else if !viewports {
|
||||
match layer(fallback) {
|
||||
(Some(fade), exiting) => Mounted { host: Box::new(LayerHost::new(fallback.clone(), props, exiting, fade, at.size)), exiting },
|
||||
(Some(fade), exiting) => {
|
||||
Mounted { host: Box::new(LayerHost::new(fallback.clone(), props, exiting, fade, at.size, moving)), exiting }
|
||||
}
|
||||
(None, _) => closed(),
|
||||
}
|
||||
} else if open {
|
||||
@@ -196,12 +199,14 @@ struct LayerHost {
|
||||
fade: f32,
|
||||
/// The size the container measured for this pass.
|
||||
size: Vec2,
|
||||
/// The rect a running drag of the move band puts the layer at in this pass, in screen space.
|
||||
moving: Option<Rect>,
|
||||
dismissed: Option<CloseReason>,
|
||||
}
|
||||
|
||||
impl LayerHost {
|
||||
fn new(overlay: Overlay, props: &ContainerProps, exiting: bool, fade: f32, size: Vec2) -> Self {
|
||||
LayerHost { overlay, save: props.save.clone(), owner: props.owner, exiting, fade, size, dismissed: None }
|
||||
fn new(overlay: Overlay, props: &ContainerProps, exiting: bool, fade: f32, size: Vec2, moving: Option<Rect>) -> Self {
|
||||
LayerHost { overlay, save: props.save.clone(), owner: props.owner, exiting, fade, size, moving, dismissed: None }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +232,7 @@ impl Host for LayerHost {
|
||||
overlay = mapped;
|
||||
}
|
||||
let screen = overlay::screen_for(&ctx, env, &overlay);
|
||||
let placement = shown_placement(&ctx, id, self.save.as_ref(), &overlay, screen, env.tokens.space.inset.screen);
|
||||
let placement = shown_placement(&ctx, id, self.save.as_ref(), &overlay, self.moving, screen, env.tokens.space.inset.screen);
|
||||
// An anchored resizable layer has no position to seed: its default size is held as its minimum until the
|
||||
// user resizes it.
|
||||
if overlay.fit == overlay::OverlayFit::Resizable
|
||||
|
||||
@@ -1609,8 +1609,11 @@ fn extent_step(
|
||||
let (ctx, facts, shape, sizing, id) = (&begun.ctx, &begun.facts, begun.shape, begun.sizing, begun.id);
|
||||
let env = begun.env();
|
||||
// A body root with parts steps its press machine before its measuring run, so the body reads this pass's part
|
||||
// presses in both runs (`BodyCx::part_press`). Step 8 finds the outcome. A member of another arena senses at step 8.
|
||||
if !sizing && shape == ShapeKind::Body && (facts.parts || t.declares_parts()) && (t.arena() || facts.text() || env.arena.is_none()) {
|
||||
// presses in both runs (`BodyCx::part_press`) and its host reads them before it places the body. Step 8 finds the
|
||||
// outcome. A member of another arena senses at step 8. A root its host shows on a layer of its own (not in flow)
|
||||
// senses in its own arena: its steps 6 to 16 run in the layer's env, which is outside its opener's arena.
|
||||
let own_arena = t.arena() || facts.text() || env.arena.is_none() || !t.in_flow();
|
||||
if !sizing && shape == ShapeKind::Body && (facts.parts || t.declares_parts()) && own_arena {
|
||||
sensing::sense_early(ctx, id, resolved.enabled);
|
||||
}
|
||||
let scx = steps::style_cx(ctx, &begun.env, &begun.step1);
|
||||
|
||||
@@ -167,7 +167,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
|
||||
struct AreaMemory<P> {
|
||||
/// The open flyout when the host binds none.
|
||||
open: Option<P>,
|
||||
/// The running move or resize of a floating window.
|
||||
/// The running resize or keyboard move of a floating window.
|
||||
moving: Option<Moving<P>>,
|
||||
}
|
||||
|
||||
@@ -1333,8 +1333,11 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let reported = native::reported(&ctx, window, viewport, |shown| kept.kept(shown, opening.rect, chrome, scene.rtl));
|
||||
self.report.actions.extend(reported);
|
||||
}
|
||||
} else if let Some(mut change) = output.placed {
|
||||
// A collapsed window keeps the edge its move began with until the move ends where its strip was dropped.
|
||||
} else if let Some(mut change) = output.placed.filter(|change| change.kind != PlacementKind::Move || change.phase == GesturePhase::Commit)
|
||||
{
|
||||
// The layer host shows a window its title row moves under the pointer, so the move reaches the workspace
|
||||
// once, when it ends: one edit. A collapsed window keeps its edge until then, and the move ends where its
|
||||
// strip was dropped.
|
||||
let mut keeps = shape.collapsed.map(|_| edge);
|
||||
if change.phase == GesturePhase::Commit && output.collapsed_width.is_none() {
|
||||
(change.rect, keeps) = shape.dropped(change.rect, scene.bounds, scene.rtl);
|
||||
@@ -1397,8 +1400,9 @@ fn split_changes<P>(from: &Node<P>, to: &Node<P>) -> Vec<(Vec<bool>, SplitSize)>
|
||||
|
||||
/// The workspace edit of a floating window's move or resize, the step `phase` of a gesture that `action`
|
||||
/// (`Action::MoveFloating`) places the window by: the gesture runs from the window's `Begin` to its `Commit`, so one
|
||||
/// drag is one undo step. `moving` holds the gesture and the workspace it began on; `rights` are the panels'
|
||||
/// permissions with the lock applied, which refuse the move of a locked workspace.
|
||||
/// drag is one undo step. A move by the title row arrives only as its `Commit`, which sets the place. `moving` holds
|
||||
/// the gesture and the workspace it began on; `rights` are the panels' permissions with the lock applied, which refuse
|
||||
/// the move of a locked workspace.
|
||||
fn window_edit<P: Clone + Eq + Hash>(
|
||||
ctx: &Context,
|
||||
current: &Workspace<P>,
|
||||
|
||||
@@ -73,6 +73,10 @@ struct Bed {
|
||||
}
|
||||
|
||||
fn bed(layout: Layout<usize>, rights: fn(&usize) -> Permissions) -> Bed {
|
||||
bed_with(layout, rights, DockConfig::default())
|
||||
}
|
||||
|
||||
fn bed_with(layout: Layout<usize>, rights: fn(&usize) -> Permissions, config: DockConfig) -> Bed {
|
||||
let workspace = Rc::new(RefCell::new(Workspace::new(layout)));
|
||||
let actions: Rc<RefCell<Vec<Action<usize>>>> = Rc::default();
|
||||
let second = Rc::new(Cell::new(false));
|
||||
@@ -84,7 +88,7 @@ fn bed(layout: Layout<usize>, rights: fn(&usize) -> Permissions) -> Bed {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut workspace = held.borrow().clone();
|
||||
let mut panels = Panels { rights };
|
||||
let out = DockArea::new("Floating dock", Bind::bound(&mut workspace), &mut panels, DockConfig::default()).show(ui);
|
||||
let out = DockArea::new("Floating dock", Bind::bound(&mut workspace), &mut panels, config.clone()).show(ui);
|
||||
*held.borrow_mut() = workspace;
|
||||
seen_actions.borrow_mut().extend(out.actions);
|
||||
if let Some(space) = out.float_space {
|
||||
@@ -145,15 +149,13 @@ fn a_tab_dragged_over_a_floating_window_marks_and_joins_the_window() {
|
||||
assert!(window.panels().any(|panel| *panel == SECOND), "the tab joined the window: {:?}", bed.actions.borrow());
|
||||
}
|
||||
|
||||
/// A window's move is the area's own edit, written each pass, and keeps its drag; a host that replaces the workspace
|
||||
/// ends the drag, and the release drops nothing.
|
||||
/// A host that replaces the workspace while a window's move runs ends the drag, and the release drops nothing.
|
||||
#[trial]
|
||||
fn a_replaced_workspace_ends_the_drag_that_the_areas_own_edits_keep() {
|
||||
fn a_replaced_workspace_ends_a_window_drag() {
|
||||
let mut bed = bed(with_window(Some(Node::tabs(vec![DOCKED], 0))), |_| Permissions::ALL);
|
||||
let by = Vec2::new(-40.0, 30.0);
|
||||
press_and_move(&mut bed.fixture, window_title(), by);
|
||||
let moved_to = bed.workspace.borrow().layout.floating[0].rect;
|
||||
assert!(dragging(&bed) && moved_to != WINDOW_AT, "the window moves under its drag: {moved_to:?}");
|
||||
assert!(dragging(&bed), "the window's drag runs");
|
||||
bed.workspace.borrow_mut().replace(Workspace::new(with_window(Some(Node::tabs(vec![DOCKED, SECOND], 0)))));
|
||||
bed.fixture.frame(vec![moved(window_title() + by * 1.25)]);
|
||||
assert!(!dragging(&bed), "the replacement ended the drag");
|
||||
@@ -186,7 +188,7 @@ fn a_given_workspace_gets_the_window_move_and_the_bodies_requests_as_actions() {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let given = held.borrow().clone();
|
||||
let mut panels = Requesting;
|
||||
let out = DockArea::new("Given dock", Bind::given(given), &mut panels, DockConfig::default()).show(ui);
|
||||
let out = DockArea::new("Given dock", Bind::given(given), &mut panels, DockConfig::default().title_bar_docks(false)).show(ui);
|
||||
held.borrow_mut().apply_all(out.actions, false, |_| Permissions::ALL).expect("the area's actions apply");
|
||||
seen.borrow_mut().extend(out.requested);
|
||||
});
|
||||
@@ -196,11 +198,40 @@ fn a_given_workspace_gets_the_window_move_and_the_bodies_requests_as_actions() {
|
||||
let own = |action: &Action<usize>| *action == Action::activate(DOCKED) || *action == Action::activate(WINDOW);
|
||||
assert!(!asked.is_empty() && asked.iter().all(own), "each body's request came back: {asked:?}");
|
||||
assert_eq!(workspace.borrow().layout.floating[0].rect, WINDOW_AT, "nothing moved yet");
|
||||
press_and_move(&mut fixture, window_title(), Vec2::new(-40.0, 30.0));
|
||||
let by = Vec2::new(-40.0, 30.0);
|
||||
press_and_move(&mut fixture, window_title(), by);
|
||||
fixture.frame(vec![release(window_title() + by)]);
|
||||
fixture.settle();
|
||||
let moved_to = workspace.borrow().layout.floating[0].rect;
|
||||
assert!(moved_to != WINDOW_AT, "the host's copy took the window's move: {moved_to:?}");
|
||||
}
|
||||
|
||||
/// A drag of a floating window's title row shows the window under the pointer in the frame of each step, in one pass;
|
||||
/// the workspace takes the move once, on the drop.
|
||||
#[trial]
|
||||
fn a_dragged_floating_window_stands_under_the_pointer_in_each_frame_and_moves_on_the_drop() {
|
||||
let mut bed = bed(with_window(None), |_| Permissions::ALL);
|
||||
let from = window_title();
|
||||
let step = Vec2::new(-10.0, 8.0);
|
||||
bed.fixture.frame(vec![moved(from)]);
|
||||
bed.fixture.frame(vec![press(from)]);
|
||||
for n in 1..=4 {
|
||||
let to = WINDOW_AT.translate(step * n as f32);
|
||||
bed.fixture.frame(vec![moved(from + step * n as f32)]);
|
||||
let shown = layer_rects(bed.fixture.ctx());
|
||||
assert!(
|
||||
shown.iter().any(|rect| (rect.min - to.min).length() < SLACK && (rect.size() - to.size()).length() < SLACK),
|
||||
"step {n}: the window stands under the pointer in its frame: {shown:?}, wanted {to:?}"
|
||||
);
|
||||
assert_eq!(bed.fixture.passes(), 1, "step {n}: the frame runs one pass");
|
||||
assert_eq!(bed.workspace.borrow().layout.floating[0].rect, WINDOW_AT, "step {n}: the workspace is not written while the move runs");
|
||||
}
|
||||
bed.fixture.frame(vec![release(from + step * 4.0)]);
|
||||
bed.fixture.settle();
|
||||
let rect = bed.workspace.borrow().layout.floating.first().map(|window| window.rect);
|
||||
assert!(rect.is_some_and(|rect| (rect.min - (WINDOW_AT.min + step * 4.0)).length() < SLACK), "the drop moves the window: {rect:?}");
|
||||
}
|
||||
|
||||
/// A dock area's first pass leaves a drag running in another area alone.
|
||||
#[trial]
|
||||
fn an_areas_first_pass_keeps_a_running_drag() {
|
||||
@@ -258,11 +289,14 @@ fn a_floating_windows_group_starts_under_the_chrome_the_area_sizes_windows_by()
|
||||
);
|
||||
}
|
||||
|
||||
/// The window's rect while a press at `from` drags by `by`, before the release, which would dock a window moved over
|
||||
/// the docked group.
|
||||
/// The window's rect after a press at `from` drags by `by` and releases, in an area whose title-row drags only move a
|
||||
/// window, so the release docks nothing.
|
||||
fn dragged_from(from: Pos2, by: Vec2) -> Rect {
|
||||
let mut bed = bed(with_window(Some(Node::tabs(vec![DOCKED], 0))), |_| Permissions::ALL);
|
||||
let config = DockConfig::default().title_bar_docks(false);
|
||||
let mut bed = bed_with(with_window(Some(Node::tabs(vec![DOCKED], 0))), |_| Permissions::ALL, config);
|
||||
press_and_move(&mut bed.fixture, from, by);
|
||||
bed.fixture.frame(vec![release(from + by)]);
|
||||
bed.fixture.settle();
|
||||
bed.workspace.borrow().layout.floating[0].rect
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user