Dock chrome settling: a run covers its group or bar, and drop-spot registration takes Sync panel types

A group's and a bar's run take no room in flow, so the settled run's rect is the group's or the band's: the pointer over it runs it again. A run record keeps each drop-spot registration, so the registering functions ask for Sync panel types; resolving keeps its bounds.
This commit is contained in:
aiongg
2026-11-18 00:08:33 +00:00
parent b5b0e6b6fd
commit 381215eb5b
6 changed files with 67 additions and 47 deletions
+1 -1
View File
@@ -531,7 +531,7 @@ pub(super) fn column_grip<P: Value + Hash>(column: &Column<P>, spec: &dyn Fn(&P)
/// Registers the drop bands of the two edges of the column in `rect` with the dock `dock`: a drop there makes a new
/// column beside the one that holds `anchor`.
pub(super) fn register_edges<P: Clone + Send + 'static>(ctx: &Context, dock: Id, anchor: &P, rect: Rect, rtl: bool, sizes: &DockSizes) {
pub(super) fn register_edges<P: Clone + Send + Sync + 'static>(ctx: &Context, dock: Id, anchor: &P, rect: Rect, rtl: bool, sizes: &DockSizes) {
let flow = Flow::new(rect, rtl);
// A narrow column keeps a third of its width between its two edge bands, so a drop inside it still reaches its
// groups.
@@ -122,7 +122,19 @@ pub(in crate::docking) fn settled_bar(ui: &mut Ui, band: Rect, content: Option<u
Some(version) => lazy.content(version),
None => lazy,
};
ui.scope_builder(UiBuilder::new().max_rect(band).id_salt(key), |ui| lazy.show(ui, show)).inner.unwrap_or_default()
if !band.is_positive() {
return BarRecord::default();
}
ui.scope_builder(UiBuilder::new().max_rect(band).id_salt(key), |ui| {
lazy.show(ui, |ui| {
let record = show(ui);
// The grip takes no room in flow; the run covers the band, so the pointer over it runs it again.
ui.expand_to_include_rect(band);
record
})
})
.inner
.unwrap_or_default()
}
/// The name of a column's bar: the labels of its panels.
+1 -1
View File
@@ -251,7 +251,7 @@ pub fn edge_bands<P: Clone + Eq + Hash>(
/// Registers the bands as the dock's edge spots, for the next pass's drops; over a tab strip each reaches
/// `strip_reach` from its edge (`DockSizes::strip_reach`).
pub fn register_edge_bands<P: Clone + Send + 'static>(ctx: &Context, dock: Id, bands: &[EdgeBand], strip_reach: f32) {
pub fn register_edge_bands<P: Clone + Send + Sync + 'static>(ctx: &Context, dock: Id, bands: &[EdgeBand], strip_reach: f32) {
for band in bands {
DockTargets::<P>::register_band(ctx, dock, DockSpot::Edge(band.side), band.band, band.line, strip_reach);
}
+34 -31
View File
@@ -403,7 +403,7 @@ impl<P> Default for Pass<P> {
}
}
impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
impl<P: Clone + Send + 'static> DockTargets<P> {
/// Runs `f` on the registries of the running pass; `None` outside a pass.
fn with_pass<R>(ctx: &Context, f: impl FnOnce(&mut Pass<P>) -> R) -> Option<R> {
let facts = frame::running(ctx)?;
@@ -422,6 +422,39 @@ impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
))
}
/// Runs `f` on the registry of `dock` in the running pass, made empty the first time.
fn with_dock(ctx: &Context, dock: Id, f: impl FnOnce(&mut DockTargets<P>)) {
Self::with_pass(ctx, |pass| {
let at = match pass.now.iter().position(|(id, _)| *id == dock) {
Some(at) => at,
None => {
pass.now.push((dock, DockTargets::new()));
pass.now.len() - 1
}
};
f(&mut pass.now[at].1);
});
}
/// The room the dock `dock` laid its panels out in the previous pass ([`Self::register_room`]); `None` outside a
/// pass and where the dock registered none.
pub fn room(ctx: &Context, dock: Id) -> Option<Rect> {
Self::with_pass(ctx, |pass| pass.before.iter().find(|(id, _)| *id == dock).and_then(|(_, targets)| targets.room)).flatten()
}
/// The spot a drop at `at` lands on in the dock `dock`, by the spots of the previous pass, with the rect its
/// mark applies to (`DockSpot::mark` takes it); `None` outside a pass.
///
/// A dock calls it only inside its own `DropTarget::accept`, so the drag session arbitrates between the dock
/// and an app's own `DropTarget<PanelDrag>` in a panel body, and between docks, by layer order and
/// registration order.
pub fn resolve(ctx: &Context, dock: Id, at: Pos2) -> Option<(DockSpot<P>, Rect)> {
Self::with_pass(ctx, |pass| pass.before.iter().find(|(id, _)| *id == dock).and_then(|(_, targets)| targets.at(at))).flatten()
}
}
/// The registrations of a pass. A settled region's run record keeps each one to make it again, so the panel type is `Sync`.
impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
/// Registers `spot` over `rect` for the dock `dock` in the running pass of this viewport. Group and column
/// rendering call it; it does nothing outside a pass. A floating window registers on its own egui layer, and
/// the drag session orders the layers, so no registry orders them.
@@ -473,36 +506,6 @@ impl<P: Clone + Send + Sync + 'static> DockTargets<P> {
fn journal<F: Fn(&Context) + Send + Sync + 'static>(ctx: &Context, make: impl FnOnce() -> F) {
crate::runtime::replay::journal(ctx, make);
}
/// Runs `f` on the registry of `dock` in the running pass, made empty the first time.
fn with_dock(ctx: &Context, dock: Id, f: impl FnOnce(&mut DockTargets<P>)) {
Self::with_pass(ctx, |pass| {
let at = match pass.now.iter().position(|(id, _)| *id == dock) {
Some(at) => at,
None => {
pass.now.push((dock, DockTargets::new()));
pass.now.len() - 1
}
};
f(&mut pass.now[at].1);
});
}
/// The room the dock `dock` laid its panels out in the previous pass ([`Self::register_room`]); `None` outside a
/// pass and where the dock registered none.
pub fn room(ctx: &Context, dock: Id) -> Option<Rect> {
Self::with_pass(ctx, |pass| pass.before.iter().find(|(id, _)| *id == dock).and_then(|(_, targets)| targets.room)).flatten()
}
/// The spot a drop at `at` lands on in the dock `dock`, by the spots of the previous pass, with the rect its
/// mark applies to (`DockSpot::mark` takes it); `None` outside a pass.
///
/// A dock calls it only inside its own `DropTarget::accept`, so the drag session arbitrates between the dock
/// and an app's own `DropTarget<PanelDrag>` in a panel body, and between docks, by layer order and
/// registration order.
pub fn resolve(ctx: &Context, dock: Id, at: Pos2) -> Option<(DockSpot<P>, Rect)> {
Self::with_pass(ctx, |pass| pass.before.iter().find(|(id, _)| *id == dock).and_then(|(_, targets)| targets.at(at))).flatten()
}
}
/// What a drag of a whole group, window or column carries, beside `PanelDrag` for one tab. Every such drag starts
+13 -8
View File
@@ -673,7 +673,7 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
/// Registers the outer-edge bands and the new-dock bands as the dock's drop spots for the next pass, from the leaves
/// the split area placed this pass (each as its tree path and rect). A new-dock band runs along a start or end edge
/// that holds no dock.
fn register_bands<P: Clone + Eq + Hash + Send + 'static>(scene: &Scene<'_, P>, ctx: &Context, area: Rect, leaves: &[(Vec<bool>, Rect)]) {
fn register_bands<P: Clone + Eq + Hash + Send + Sync + 'static>(scene: &Scene<'_, P>, ctx: &Context, area: Rect, leaves: &[(Vec<bool>, Rect)]) {
if scene.layout.root.is_none() {
return;
}
@@ -758,15 +758,15 @@ fn panel_menu_rows<P: Clone + Eq + Hash>(
/// command states and move targets read across groups. Sizes are left out: a size reaches a region as its room.
fn chrome_key<P: Hash>(layout: &Layout<P>, version: u64, config: &DockConfig, locked: bool, auto_collapse: bool) -> u64 {
use std::hash::Hasher;
fn column<P: Hash>(column: &Column<P>, hasher: &mut impl Hasher) {
(column.iconic, column.steps, column.groups.len()).hash(hasher);
for group in &column.groups {
fn column<P: Hash>(shown: &Column<P>, hasher: &mut impl Hasher) {
(shown.iconic, shown.steps, shown.groups.len()).hash(hasher);
for group in &shown.groups {
(&group.panels, group.active, group.minimized).hash(hasher);
}
}
fn node<P: Hash>(node: &Node<P>, hasher: &mut impl Hasher) {
std::mem::discriminant(node).hash(hasher);
match node {
fn node<P: Hash>(shown: &Node<P>, hasher: &mut impl Hasher) {
std::mem::discriminant(shown).hash(hasher);
match shown {
Node::Split { first, second, .. } => {
node(first, hasher);
node(second, hasher);
@@ -974,7 +974,12 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
};
let output = ui
.scope_builder(UiBuilder::new().max_rect(rect).id_salt(key), |ui| {
lazy.show(ui, |ui| make(active, look.minimized).show_at(ui, rect, |ui, body| panel_body(&panels, shown, ui, body)).output)
lazy.show(ui, |ui| {
let output = make(active, look.minimized).show_at(ui, rect, |ui, body| panel_body(&panels, shown, ui, body)).output;
// `show_at` takes no room in flow; the run covers the group, so the pointer over it runs it again.
ui.expand_to_include_rect(rect);
output
})
})
.inner;
// A settled group replayed its last run: nothing reached it.
+5 -5
View File
@@ -198,19 +198,19 @@ fn hovering_a_tab_runs_only_its_group() {
assert_eq!(runs_of(&fixture, &["DockGroup"]), 1, "{:?}", last_pass_runs(fixture.ctx()));
}
/// An edit of the arrangement (a tab picked from outside the dock) runs every group once, and a change of the host's
/// spec version does too; the frame after settles again.
/// An edit of the arrangement (a tab picked from outside the dock) runs every group (its measuring runs included), and
/// a change of the host's spec version does too; the frame after settles again.
#[trial]
fn an_arrangement_or_spec_change_runs_every_group_once() {
fn an_arrangement_or_spec_change_runs_every_group() {
let (mut fixture, spec, workspace) = settling(side_by_side(3), None);
workspace.borrow_mut().apply(Action::activate(1), false, |_| Permissions::ALL).expect("panel 1 is shown");
fixture.frame(Vec::new());
assert_eq!(runs_of(&fixture, &["DockGroup"]), 3, "the edit runs every group");
assert!(runs_of(&fixture, &["DockGroup"]) >= 3, "the edit runs every group: {:?}", last_pass_runs(fixture.ctx()));
fixture.frame(Vec::new());
assert_eq!(runs_of(&fixture, &["DockGroup"]), 0, "and they settle at it");
spec.set(2);
fixture.frame(Vec::new());
assert_eq!(runs_of(&fixture, &["DockGroup"]), 3, "a new spec version runs every group");
assert!(runs_of(&fixture, &["DockGroup"]) >= 3, "a new spec version runs every group: {:?}", last_pass_runs(fixture.ctx()));
fixture.frame(Vec::new());
assert_eq!(runs_of(&fixture, &["DockGroup"]), 0, "and they settle at it");
}