mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Docking: a tool rail's grip strip is a memoized view (photocraft#16333)
The grip strip under a host-shown rail's column bar (#2934) ran its GroupGrip in every pass, also when the only input was the pointer moving elsewhere, where the column bars and tab rows replay. It is now a MemoView held to the strip, keyed by the rail's group, with the drag's start leaving through an outbox; the group's size goes on the drag outside the view as the column bar does it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
cec6d87ff2
commit
058df7d51a
@@ -5,8 +5,8 @@ use super::hide::{self, PruneKey};
|
||||
use crate::contract::Revision;
|
||||
use crate::contract::overlay::{PlacementChange, PlacementKind};
|
||||
use crate::contract::{
|
||||
Bind, BindMut, BodyCx, Cx, Entry, MemoKey, NoValue, Outcome, Pad, Pointer as _, Props as _, Show as _, ShowContainer as _, Sizing, Tracked,
|
||||
WordSetCx as _,
|
||||
Bind, BindMut, BodyCx, Cx, Entry, MemoKey, MemoProps, MemoView, NoValue, Outbox, Outcome, Pad, Pointer as _, Props as _, Show as _,
|
||||
ShowContainer as _, Sizing, Tracked, WordSetCx as _,
|
||||
};
|
||||
use crate::docking::SplitFramesCx as _;
|
||||
use crate::docking::stack::{StackSection, StackSections, section_heights};
|
||||
@@ -917,17 +917,25 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
}
|
||||
|
||||
/// The grip strip on top of a tool rail the host shows itself: the dock's grip marks over a band that drags the
|
||||
/// group, which floats at `size`, the group's size.
|
||||
/// group, which floats at `size`, the group's size. A memoized view ([`rail_grip`]) held to the strip, so a frame
|
||||
/// whose input is elsewhere replays it, as the column bars and the groups' tab rows replay.
|
||||
fn rail_grip(&mut self, ui: &mut Ui, anchor: &P, shown: &P, strip: Rect, size: Vec2) {
|
||||
let scene = self.scene;
|
||||
let label = Label::from(scene.spec(shown).label.as_str().to_owned());
|
||||
let held = GroupGrip::new(DragUnit::Group(anchor.clone()), PanelKey::of(shown))
|
||||
.ticks(true)
|
||||
.movable(scene.permissions(shown).movable)
|
||||
.ghost(label.clone())
|
||||
.label(label)
|
||||
.show_at(ui, strip);
|
||||
if held.drag_started {
|
||||
let mut sent = Vec::new();
|
||||
ui.scope_builder(UiBuilder::new().max_rect(strip), |ui| {
|
||||
let props = RailGrip {
|
||||
unit: DragUnit::Group(anchor.clone()),
|
||||
active: PanelKey::of(shown),
|
||||
movable: scene.permissions(shown).movable,
|
||||
label,
|
||||
sent: Outbox::new(&mut sent),
|
||||
};
|
||||
// Keyed by the rail's group: unique among the rails a dock area shows.
|
||||
let _ = MemoView::new(("rail grip", PanelKey::of(anchor)), props, rail_grip::<P>).show(ui);
|
||||
});
|
||||
// The group's size goes on the drag here, outside the view, whose measuring runs see no size.
|
||||
if !sent.is_empty() {
|
||||
drag::amend::<GroupDrag<P>>(ui.ctx(), |drag| drag.source = Some(size));
|
||||
}
|
||||
}
|
||||
@@ -1560,3 +1568,30 @@ fn window_edit<P: Clone + Eq + Hash>(
|
||||
fn panel_body<'p, P: Hash>(panels: &RefCell<&mut (dyn DockPanels<P> + 'p)>, panel: &P, ui: &mut Ui, body: &mut BodyCx<'_>) {
|
||||
panels.borrow_mut().body(panel, ui, body);
|
||||
}
|
||||
|
||||
/// The props of a tool rail's grip strip: the group it drags, its name, and the outbox the drag's start goes to.
|
||||
#[derive(MemoProps)]
|
||||
struct RailGrip<'a, P> {
|
||||
#[memo_props(hash = "a dock's panels are plain values it keys by their hash")]
|
||||
unit: DragUnit<P>,
|
||||
active: PanelKey,
|
||||
movable: bool,
|
||||
label: Label,
|
||||
sent: Outbox<'a, ()>,
|
||||
}
|
||||
|
||||
/// A tool rail's grip strip: the dock's grip marks over the view's room, which a drag moves the rail's group by.
|
||||
fn rail_grip<P: Clone + Hash + Send + Sync + 'static>(props: &mut RailGrip<'_, P>, ui: &mut Ui) {
|
||||
let strip = ui.max_rect();
|
||||
let held = GroupGrip::new(props.unit.clone(), props.active)
|
||||
.ticks(true)
|
||||
.movable(props.movable)
|
||||
.ghost(props.label.clone())
|
||||
.label(props.label.clone())
|
||||
.show_at(ui, strip);
|
||||
if held.drag_started {
|
||||
props.sent.send(());
|
||||
}
|
||||
// The grip takes no room in flow; the run covers the strip, so the pointer over it runs it again.
|
||||
ui.expand_to_include_rect(strip);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use craft_ui::contract::{Bind, BodyCx, PlainData, Tracked};
|
||||
use craft_ui::docking::{DockConfig, DockGrid, DockPanels, DockSizes, DragUnit, GroupAt, GroupDrag, PanelSpec, PanelSpecs};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::drag;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui::testing::{Fixture, last_pass_runs, pointer, trial};
|
||||
use egui::{Rect, Shape, Ui, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
@@ -144,3 +144,24 @@ fn a_tool_rail_shown_by_its_host_has_a_grip_strip_that_drags_it() {
|
||||
assert_eq!(unit, Some(DragUnit::Group(RAIL)), "a drag on the grip moves the rail's group");
|
||||
fixture.release_at(strip.center() + Vec2::new(200.0, 0.0)).settle();
|
||||
}
|
||||
|
||||
/// The rail's grip strip is a memoized view: a pointer moving elsewhere in the window replays it, as it replays the
|
||||
/// column bars and the tab rows, and runs no grip (photocraft#16333).
|
||||
#[trial]
|
||||
fn a_tool_rails_grip_strip_replays_while_the_pointer_moves_elsewhere() {
|
||||
let seen = Rc::new(Cell::new(None));
|
||||
let dock = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![RAIL], 0)]).with_steps(1)]);
|
||||
let root = Node::split(Axis::X, SplitSize::FixedFirst(120.0), dock, Node::tabs(vec![1], 0));
|
||||
let mut workspace = Arc::new(Workspace::new(Layout::new(Some(root), Vec::new())));
|
||||
let (mut panels, specs) = (RailPanels { seen: seen.clone() }, Tracked::new(RailSpecs));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let _ = DockArea::new("Rail dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default()).show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(800.0, 600.0)).settle();
|
||||
let grips =
|
||||
|fixture: &Fixture| last_pass_runs(fixture.ctx()).into_iter().filter(|(ty, _)| ty.contains("GroupGrip<")).map(|(_, runs)| runs).sum::<u32>();
|
||||
for step in 1..=3 {
|
||||
fixture.frame(vec![pointer::moved(egui::pos2(500.0 + step as f32, 300.0))]);
|
||||
assert_eq!(grips(&fixture), 0, "pointer step {step}: the rail's grip replays its last run");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user