An AccessKit request on a settled view's node reruns the view

A settled memoized view replayed unless a routed intent's target was one of its
egui widgets or focus stops. An AccessKit Click on a part with no stop (a tab's
close button) goes to the node's owner, a collection row's component, which is
neither, so the dock's tab row replayed and nobody read the click. A record
notes the owners of the nodes its run registered (Facts::node_owners), and a
request routed to one of them runs the view. The documents story's tabs close
again.
This commit is contained in:
aiongg
2026-11-24 18:50:22 +00:00
parent 603c4f20c5
commit 02cdd25179
5 changed files with 46 additions and 7 deletions
@@ -11,6 +11,7 @@ pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) {
// Journaled after the `register_node` it amends, so a settled view's replay leaves the row's node with the
// collection, as a run does.
crate::runtime::replay::journal(ctx, || (node, owner, part), |ctx, &(node, owner, part)| redirect_node(ctx, node, owner, part));
crate::runtime::replay::note_node_owner(ctx, owner);
current(ctx, |stage| {
if let Some(entry) = stage.nodes.get_mut(&node_key(node)) {
entry.owner = owner;
@@ -37,6 +38,7 @@ pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option<Par
|| (node, owner, part, focusable),
|ctx, &(node, owner, part, focusable)| register_node(ctx, node, owner, part, focusable),
);
crate::runtime::replay::note_node_owner(ctx, owner);
current(ctx, |stage| {
stage.nodes.insert(node_key(node), Node { owner, part, focusable, expanded: None });
});
+1 -1
View File
@@ -552,7 +552,7 @@ pub(crate) fn settled(
&& !facts.discards
&& facts.quiet(now, edited.as_ref())
&& !settled.record.focus.stop_ids().any(|stop| revealed == Some(stop) || routed.contains(&stop))
&& !routed.iter().any(|id| settled.record.widgets.contains(id))
&& !routed.iter().any(|id| settled.record.widgets.contains(id) || settled.record.facts.node_owners.contains(id))
&& !dragged.is_some_and(|widget| settled.record.widgets.contains(&widget))
&& focused.within(&settled.record.focus, &settled.record.widgets) == settled.record.held
});
+10
View File
@@ -167,6 +167,9 @@ pub(crate) struct Facts {
/// The components whose memory owners registered in the run (`memory::register_owner`): a replay needs their
/// shown-tier state still kept (`memory::ended_since`).
pub(crate) owners: Vec<egui::Id>,
/// The components that take the AccessKit requests on the nodes the run registered (`note_node_owner`): a request
/// routed to one of them is routed into the run, though the component is no egui widget (a collection's row).
pub(crate) node_owners: Vec<egui::Id>,
/// The layout memory entries the run kept (`note_layout_keep`): a replay keeps them (`layout_memory::keep`).
pub(crate) layout_keeps: Vec<egui::Id>,
/// The derived values the run asked for (`note_derived_keep`): a replay keeps them, since it asks for none.
@@ -293,6 +296,7 @@ pub(crate) fn close(ctx: &Context, layer: Layer) -> Record {
outer.facts.blocked |= open.facts.blocked;
outer.facts.discards |= open.facts.discards;
outer.facts.owners.extend(open.facts.owners.iter().copied());
outer.facts.node_owners.extend(open.facts.node_owners.iter().copied());
outer.facts.layout_keeps.extend(open.facts.layout_keeps.iter().copied());
outer.facts.derived_keeps.extend(open.facts.derived_keeps.iter().copied());
outer.facts.wake = min_wake(outer.facts.wake, open.facts.wake);
@@ -579,6 +583,12 @@ pub(crate) fn note_derived_keep(ctx: &Context, slot: egui::Id) {
with_open(ctx, |facts| facts.derived_keeps.push(slot));
}
/// Notes that `owner` takes the AccessKit requests on a node the running code registered (`keys::register_node`). A
/// replay registers the node again from its journal, which notes it in the records open around the replay.
pub(crate) fn note_node_owner(ctx: &Context, owner: egui::Id) {
with_open(ctx, |facts| facts.node_owners.push(owner));
}
/// Notes that the memory owner `owner` registered in the running code.
pub(crate) fn note_owner(ctx: &Context, owner: egui::Id) {
with_open(ctx, |facts| facts.owners.push(owner));
+11 -6
View File
@@ -120,18 +120,23 @@ fn a_panel_with_a_count_and_a_caption(ui: &mut Ui, _: &mut StoryData) -> StoryOu
DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).show(ui, |_, _| ()).output.into()
}
/// A group whose Timeline lists its open compositions as tabs after the panel tabs, each with its label colour; the
/// shown composition's tab is selected while the Timeline shows, and a pick shows another.
/// A group whose Timeline lists its open compositions as tabs after the panel tabs, each with its label colour and a
/// close button; the shown composition's tab is selected while the Timeline shows, a pick shows another and a close
/// closes it.
#[story(DockGroup<'static, usize>, covers = [Default])]
fn a_panel_with_documents(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let shown = *data.value("shown", 1_u64);
let comp = |id: u64, name: &'static str, color: Option<Srgba>| PanelDocument::new(id, name).swatch(color).shown(id == shown);
let documents = vec![comp(1, "Comp 1", Some(Srgba::rgb(0.8, 0.3, 0.3))), comp(2, "Comp 2", None)];
let panels = vec![title_of(LAYERS).documents(documents), title_of(CHANNELS)];
let output = DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).show(ui, |_, _| ()).output;
let open = data.value("open", vec![1_u64, 2]).clone();
let comp = |id: u64| {
let color = (id == 1).then(|| Srgba::rgb(0.8, 0.3, 0.3));
PanelDocument::new(id, format!("Comp {id}")).swatch(color).closable(true).shown(id == shown)
};
let panels = vec![title_of(LAYERS).documents(open.iter().map(|id| comp(*id)).collect()), title_of(CHANNELS)];
let output = DockGroup::new(LAYERS, Titles::from_content(panels.clone()), panels[0].key).closable().show(ui, |_, _| ()).output;
if let Some((_, id)) = output.picked_document {
*data.value("shown", 1_u64) = id;
}
data.value("open", vec![1_u64, 2]).retain(|id| !output.closed_documents.iter().any(|(_, closed)| closed == id));
output.into()
}
+22
View File
@@ -330,3 +330,25 @@ fn closable_panel_tabs_shrink_and_close_on_a_middle_click() {
assert_eq!(closed.get(), Some(keys[2]), "the middle click closes the tab");
assert_eq!(picked.get(), None, "the middle click does not show the tab first");
}
// An AccessKit click on a closable tab's close button closes the tab, as a click on it does, though the tab row has
// settled and replays its last run.
#[trial]
fn an_access_click_on_a_settled_tabs_close_button_closes_it() {
use craft_ui::testing::focus::AccessActionKind;
let closed = Rc::new(Cell::new(None::<PanelKey>));
let closes = Rc::clone(&closed);
let panels = vec![PanelTitle::new(PanelKey::new(1), "Color").closable(true), PanelTitle::new(PanelKey::new(2), "Swatches").closable(true)];
let key = panels[1].key;
let mut fixture = Fixture::new(move |ui| {
let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key).closable();
let out = group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), |_, _| ());
if let Some(key) = out.output.closed.first() {
closes.set(Some(*key));
}
});
fixture.idle(4);
let Some(close) = fixture.by_label("Close Swatches") else { panic!("the Swatches tab shows a close button") };
fixture.access(AccessActionKind::Click, &close).settle();
assert_eq!(closed.get(), Some(key), "the access click closes the tab");
}