fw sync: ui-contract compiles: one AccessKit tree store (upstream's settled tree, the port's view over it), journal calls on upstream's signature, Span strikethrough, filtered Source borrows; the settled-region rename trial on a memoized view

This commit is contained in:
Dylan M. Taylor committed 2026-11-22 23:19:58 -05:00
1 parent 308478fe00
commit 7f53dfd8b7
12 files changed
+48 -70

No files matched your search

+1 -1
View File
@@ -160,7 +160,7 @@ pub fn inspect(host: &WindowHost, viewport: ViewportId, params: &Value) -> Resul
let role = p.str_field("role")?.map(str::to_lowercase);
let focused = p.bool_field("focused")?;
let limit = usize::try_from(p.uint_field("limit")?.unwrap_or(DEFAULT_LIMIT)).unwrap_or(usize::MAX);
let tree = host.access_tree(viewport).ok_or_else(|| NO_TREE.to_owned())?;
let tree = host.access_tree_view(viewport).ok_or_else(|| NO_TREE.to_owned())?;
let reported: HashSet<NodeKey> = tree.keys().into_iter().collect();
let root = tree.root_key();
+1 -1
View File
@@ -171,7 +171,7 @@ impl Focus {
/// Queues `action` on the node `target` names in `viewport`'s kept access tree.
fn inject_node(host: &WindowHost, viewport: ViewportId, target: &NodeTarget, action: Declared) -> Result<(), String> {
let tree = host.access_tree(viewport).ok_or_else(|| NO_TREE.to_owned())?;
let tree = host.access_tree_view(viewport).ok_or_else(|| NO_TREE.to_owned())?;
let node = resolve(&tree, target, action)?;
host.inject_access(viewport, node, action);
Ok(())
+1 -1
View File
@@ -96,7 +96,7 @@ fn inspect_lists_reported_nodes_in_tree_order_with_their_filters() {
open.set(true);
fx.idle(30);
let tree = host.access_tree(ViewportId::ROOT).expect("the kept tree");
let tree = host.access_tree_view(ViewportId::ROOT).expect("the kept tree");
let behind = listed(&host, json!({}));
assert!(!labels(&behind).contains(&"Open".to_owned()), "a node behind the modal is not listed: {behind}");
assert!(labels(&behind).contains(&"Apply".to_owned()), "the modal's own button is: {behind}");
@@ -265,7 +265,7 @@ impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
let mut in_view = Vec::new();
layout.visible(ScrollPos { x: self.offset_x, y: self.offset.max(0.0) }, Vec2::new(width, high), &mut in_view);
in_view.sort_unstable();
let source = self.source;
let source = &*self.source;
// The rows of the view this pass has not measured: (row, its widths, its height).
let todo: Vec<(usize, bool, bool)> = rows::measured_this_pass(&ctx, id, |fresh| {
in_view
@@ -394,13 +394,13 @@ impl<'s, 'r, C: Collection> ItemsHooks<'s, 'r, C> {
let current = comp.items().current.as_deref().and_then(|key| key.downcast_ref::<C::Key>()).cloned();
if at_read {
Known {
placed: self.selection_at_read.placed(self.source),
placed: self.selection_at_read.placed(&*self.source),
lead: self.lead_at_read.clone(),
renaming: self.renaming_at_read.clone(),
current,
}
} else {
Known { placed: self.selection.placed(self.source), lead: self.lead.key.clone(), renaming: self.renaming.key.clone(), current }
Known { placed: self.selection.placed(&*self.source), lead: self.lead.key.clone(), renaming: self.renaming.key.clone(), current }
}
}
}
@@ -366,6 +366,7 @@ impl LayoutQuery<'_> {
shortcut: span.shortcut,
highlight: span.highlight,
underline: span.underline,
strikethrough: span.strikethrough,
strong: span.strong,
flag: span.flag,
})
+6 -41
View File
@@ -329,7 +329,7 @@ pub(crate) fn offer_context_menu(ctx: &Context, id: Id) {
if written {
ctx.accesskit_node_builder(id, |node| node.add_action(accesskit::Action::ShowContextMenu));
}
crate::runtime::replay::journal(ctx, || move |ctx: &Context| offer_context_menu(ctx, id));
crate::runtime::replay::journal(ctx, || id, |ctx, &id| offer_context_menu(ctx, id));
}
/// Whether `id` has a `Trigger::Context` opener recorded in this pass.
@@ -337,51 +337,16 @@ pub(crate) fn offers_context_menu(ctx: &Context, id: Id) -> bool {
with_emitted(ctx, |emitted| emitted.context.contains(&id))
}
/// The AccessKit trees automation reads ([`keep_trees`], [`kept_tree`]): an observation of finished output, kept
/// apart from the pass state, which no pass reads.
#[derive(Default)]
struct KeptTrees {
/// Whether trees are kept: automation asked for them.
on: bool,
/// Each viewport's tree update from its last presented pass.
trees: HashMap<ViewportId, accesskit::TreeUpdate>,
}
fn with_kept<R>(ctx: &Context, f: impl FnOnce(&mut KeptTrees) -> R) -> R {
super::memory::Service::<KeptTrees>::run(ctx, f)
}
/// Turns AccessKit output on and keeps every viewport's tree from then on. The trees of closed viewports go in the
/// frame loop's prune step.
/// Turns AccessKit output on, so every viewport's pass settles an update ([`settle_output`]) that automation reads
/// ([`kept_tree`]).
pub(crate) fn keep_trees(ctx: &Context) {
let first = with_kept(ctx, |kept| !std::mem::replace(&mut kept.on, true));
if first {
crate::runtime::frame::register_prune(ctx, std::any::TypeId::of::<KeptTrees>(), prune_kept);
}
ctx.enable_accesskit();
}
fn prune_kept(ctx: &Context, live: &[ViewportId]) {
with_kept(ctx, |kept| kept.trees.retain(|viewport, _| live.contains(viewport)));
}
/// The output hook's step: keeps a copy of the tree update `output` carries, for the viewport whose pass made it,
/// while [`keep_trees`] is on. The update itself goes on to the platform untouched. A frame that reruns a pass keeps
/// the last pass's tree, the one presented.
pub(crate) fn keep_output(ctx: &Context, output: &FullOutput) {
// AccessKit off: no update, and nothing to look up.
let Some(update) = &output.platform_output.accesskit_update else { return };
let Some(viewport) = pass_state::with::<Reported, _>(ctx, |reported| reported.ended) else { return };
with_kept(ctx, |kept| {
if kept.on {
kept.trees.insert(viewport, update.clone());
}
});
}
/// The tree [`keep_trees`] kept for `viewport`; `None` before its first presented pass or while trees are not kept.
/// The settled update of `viewport`'s last pass as a tree to walk; `None` before its first pass or while AccessKit is
/// off.
pub(crate) fn kept_tree(ctx: &Context, viewport: ViewportId) -> Option<AccessTree> {
with_kept(ctx, |kept| kept.trees.get(&viewport).cloned()).map(AccessTree::new)
settled_tree(ctx, viewport).map(AccessTree::new)
}
/// The tree update of a finished frame.
@@ -17,10 +17,6 @@ impl Plugin for RuntimePlugin {
frame::input_hook(ctx, input);
}
fn output_hook(&mut self, ctx: &Context, output: &mut FullOutput) {
crate::runtime::egui::access::keep_output(ctx, output);
}
fn on_begin_pass(&mut self, ui: &mut Ui) {
frame::begin_pass(ui);
}
+1 -1
View File
@@ -294,7 +294,7 @@ fn current<R>(ctx: &Context, f: impl FnOnce(&mut Stage) -> R) -> R {
}
pub(crate) fn register_hover_delete(ctx: &Context, id: Id) {
crate::runtime::replay::journal(ctx, || move |ctx: &Context| register_hover_delete(ctx, id));
crate::runtime::replay::journal(ctx, || id, |ctx, &id| register_hover_delete(ctx, id));
current(ctx, |stage| {
if !stage.hover_deletes.contains(&id) {
stage.hover_deletes.push(id);
@@ -233,14 +233,15 @@ impl WindowHost {
injected::inject_access(&self.ctx, viewport, node, action);
}
/// Turns AccessKit output on and, from then on, keeps each viewport's tree from the last presented frame.
/// Turns AccessKit output on, so [`access_tree`](Self::access_tree) and
/// [`access_tree_view`](Self::access_tree_view) have each viewport's settled tree from then on.
pub fn keep_access_tree(&self) {
crate::runtime::egui::access::keep_trees(&self.ctx);
}
/// The kept AccessKit tree of `viewport`: `None` before its first presented frame or without
/// [`keep_access_tree`](Self::keep_access_tree).
pub fn access_tree(&self, viewport: ViewportId) -> Option<AccessTree> {
/// [`access_tree`](Self::access_tree) as a tree to walk: `None` before the viewport's first pass or while
/// AccessKit is off ([`keep_access_tree`](Self::keep_access_tree) turns it on).
pub fn access_tree_view(&self, viewport: ViewportId) -> Option<AccessTree> {
crate::runtime::egui::access::kept_tree(&self.ctx, viewport)
}
+25 -10
View File
@@ -566,24 +566,39 @@ fn enter_on_an_untyped_rename_commits_only_a_proposed_draft() {
assert!(renamed("b").is_empty(), "a draft equal to the row's text reports no commit");
}
/// A rename requested from outside a settled region (`Lazy::settles` with a content version, as a docked panel's
/// body) runs the region, so its collection takes the request and opens the rename field.
/// The renaming list's view: its rows, its log and its Enter, which the trial reads.
#[derive(craft_ui::contract::MemoProps)]
struct RenamingPanel {}
thread_local! {
/// The log, Enter and rows the renaming panel shows: a memoized view's props are plain data.
static RENAMING_PANEL: Cell<Option<(&'static Log, &'static Cell<bool>, &'static Words)>> = const { Cell::new(None) };
}
fn renaming_panel(_: &mut RenamingPanel, ui: &mut Ui) {
let Some((log, enter, words)) = RENAMING_PANEL.with(Cell::get) else { return };
let list = Probe::new(SelectMode::Single).id_salt("list").renaming("b", enter);
log.take(list.show_items(ui, words, &mut |key, _| ProbeRow::new(*key, log)));
}
/// A rename requested from outside a settled memoized view (a docked panel's body) runs the view, so its collection
/// takes the request and opens the rename field.
#[trial]
fn a_rename_request_runs_the_settled_region_of_its_collection() {
use craft_ui::contract::Lazy;
let (log, enter, words) = (Log::new(), Cell::new(false), Words::flat(&["a", "b", "c"]));
fn a_rename_request_runs_the_settled_view_of_its_collection() {
use craft_ui::contract::MemoView;
let log = Log::new();
let enter: &'static Cell<bool> = Box::leak(Box::new(Cell::new(false)));
let words: &'static Words = Box::leak(Box::new(Words::flat(&["a", "b", "c"])));
RENAMING_PANEL.with(|panel| panel.set(Some((log, enter, words))));
let mut frames = Frames::new();
let mut show = |ui: &mut Ui| {
in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| {
Lazy::new("panel", 0.0).settles(true).content(1).show(ui, |ui| {
let list = Probe::new(SelectMode::Single).id_salt("list").renaming("b", &enter);
log.take(list.show_items(ui, &words, &mut |key, _| ProbeRow::new(*key, log)));
});
MemoView::new("panel", RenamingPanel {}, renaming_panel).show(ui);
});
};
frames.idle(30, &mut show);
request_rename(&frames.ctx, log.id(), &1_usize);
frames.idle(3, &mut show);
let begun = log.events.borrow().iter().any(|event| matches!(event, CollectionEvent::Rename(EditEvent::Begin { .. })));
assert!(begun, "the settled region ran and its collection opened the requested rename");
assert!(begun, "the settled view ran and its collection opened the requested rename");
}
+1 -1
View File
@@ -367,7 +367,7 @@ fn a_fill_child_of_a_content_sized_row_takes_its_measured_width_and_the_next_mem
/// asks every frame must not make every frame run twice (egui's "request_discard has been called N frames in a row").
#[trial]
fn a_reveal_of_a_rect_in_a_scroll_bodys_view_runs_no_second_pass() {
let owner = egui::Id::new("revealed body");
let owner = egui::Id::unique("revealed body");
let mut frames = Frames::new();
let mut show = |ui: &mut egui::Ui| {
let props = ContainerProps::new().sizing(Sizing::Fill).scroll(Scroll::vertical());
@@ -333,7 +333,7 @@ fn a_window_an_app_modal_in_another_window_blocks_takes_no_wheel() {
use craft_ui::testing::wheel::{register, take};
for open in [false, true] {
let windows = Windows::new();
let view = egui::Id::new("view");
let view = egui::Id::unique("view");
let taken = Cell::new(None);
let frame = |events: Vec<Event>| {
windows.frame(events, vec![], |ui| {
@@ -362,8 +362,8 @@ fn wheel_over_a_modal_never_reaches_a_view_under_it_during_a_drag() {
use craft_behavior::{Sense, WheelTaker};
use craft_ui::testing::wheel::{register, take};
let windows = Windows::new();
let view = egui::Id::new("dragging view");
let modal_view = egui::Id::new("modal view");
let view = egui::Id::unique("dragging view");
let modal_view = egui::Id::unique("modal view");
let taken = Cell::new(None);
let modal_taken = Cell::new(None);
let open = Cell::new(false);