mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Overlay layers: a modal layer's flag sits on its container component's node, which carries the role; the layer root stays a plain container
- report_layer writes the root without the flag; the host marks the layer's own node modal after its body ran, so the run's records hold it and a replay adds it again. NodeSpec's modal field goes. - The layer-root trial runs a modal popover too: the popover's node is modal and the root is not, in the run and in a replay.
This commit is contained in:
@@ -176,7 +176,7 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
// A popup's or a modal's layer, and any layer while it fades out, has a root node, made before its `Area` shows so
|
||||
// egui hangs the layer's content below it. A sizing pass of the `Area` reports nothing.
|
||||
if layer.exiting || matches!(overlay.rank, Rank::Popup | Rank::Modal { .. }) {
|
||||
spec.root = areas::content_rect(ctx, &spec).map(|rect| access::report_layer(ctx, layer.id, rect, overlay.rank.is_modal(), layer.exiting));
|
||||
spec.root = areas::content_rect(ctx, &spec).map(|rect| access::report_layer(ctx, layer.id, rect, layer.exiting));
|
||||
}
|
||||
// The opener of the layer's scope is the stop focused when the layer first appears: egui's modal gate takes focus
|
||||
// from the widgets below a modal layer by the first pass that shows the layer. A dropdown that keeps its anchor's key
|
||||
@@ -222,6 +222,9 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
// checks them. Without the boundary a tooltip's text was checked against the body's kept transcript, which
|
||||
// asked for a discard pass every other frame while the tooltip showed.
|
||||
access::scope::outside(ctx, || layout_memory::boundary(ctx, true, || body(ui)));
|
||||
if real && overlay.rank.is_modal() {
|
||||
access::report_modal(ctx, layer.id);
|
||||
}
|
||||
if real {
|
||||
focus::pop_scope(ctx);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub use emit::layer_root;
|
||||
pub use emit::report_sub;
|
||||
#[doc(hidden)]
|
||||
pub use emit::sub_node_id;
|
||||
pub(crate) use emit::{FaceFacts, Own, PopupShown, hide_exiting_content, report, report_layer};
|
||||
pub(crate) use emit::{FaceFacts, Own, PopupShown, hide_exiting_content, report, report_layer, report_modal};
|
||||
pub use live::announce;
|
||||
pub(crate) use live::{begin_pass as begin_live_pass, end_pass as end_live_pass};
|
||||
pub use scope::{FieldLabel, FieldLabelRole};
|
||||
|
||||
@@ -426,19 +426,25 @@ pub fn layer_root(id: Id) -> Id {
|
||||
}
|
||||
|
||||
/// Writes the root node of the overlay layer `id`, whose content takes `rect`, and returns its id. The layer's content
|
||||
/// hangs below it, and a modal layer's root is modal. An exiting layer's root is hidden from the first pass it fades
|
||||
/// out, so nothing under it is reported while it still paints; the ids stay the same if the layer reopens. Called
|
||||
/// before the layer's `Area` shows, which egui hangs below the root.
|
||||
pub(crate) fn report_layer(ctx: &Context, id: Id, rect: Rect, modal: bool, exiting: bool) -> Id {
|
||||
/// hangs below it. An exiting layer's root is hidden from the first pass it fades out, so nothing under it is reported
|
||||
/// while it still paints; the ids stay the same if the layer reopens. Called before the layer's `Area` shows, which
|
||||
/// egui hangs below the root. The root is a plain container: a modal layer's flag sits on its container component's
|
||||
/// node ([`report_modal`]), which carries the role, since screen readers drop a container without one.
|
||||
pub(crate) fn report_layer(ctx: &Context, id: Id, rect: Rect, exiting: bool) -> Id {
|
||||
let root = layer_root(id);
|
||||
let mut spec = NodeSpec::layer_root();
|
||||
spec.rect = Some(rect);
|
||||
spec.modal = modal;
|
||||
spec.hidden = exiting;
|
||||
write_node(ctx, root, &spec);
|
||||
root
|
||||
}
|
||||
|
||||
/// Marks the node of the modal overlay layer `id` modal: the node its container component wrote with the layer's id
|
||||
/// and its role. Called after the layer's body ran, so the node exists when the component reported it.
|
||||
pub(crate) fn report_modal(ctx: &Context, id: Id) {
|
||||
adapter::set_modal(ctx, id);
|
||||
}
|
||||
|
||||
/// Hides the node of the content `Ui` of an exiting overlay layer: a popup body that names its own parent can hang
|
||||
/// its content outside the layer's root.
|
||||
pub(crate) fn hide_exiting_content(ctx: &Context, content: Id) {
|
||||
|
||||
@@ -167,6 +167,13 @@ pub(crate) fn pass_through(ctx: &Context, id: Id) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Marks the node of `id` modal, when the pass has written it.
|
||||
pub(crate) fn set_modal(ctx: &Context, id: Id) {
|
||||
if ctx.has_accesskit_node(id) {
|
||||
ctx.accesskit_node_builder(id, accesskit::Node::set_modal);
|
||||
}
|
||||
}
|
||||
|
||||
/// Reports `id` as the focused node of this pass. A replay of the run that reported it reports it again: a view that
|
||||
/// holds focus replays while nothing reaches it.
|
||||
pub(crate) fn set_focus(ctx: &Context, id: Id) {
|
||||
|
||||
@@ -86,7 +86,6 @@ pub(crate) struct NodeSpec {
|
||||
pub disabled: bool,
|
||||
pub read_only: bool,
|
||||
pub required: bool,
|
||||
pub modal: bool,
|
||||
pub actions: Vec<NodeAction>,
|
||||
pub custom_actions: Vec<(i32, String)>,
|
||||
/// The content keeps its left-to-right order under a right-to-left interface.
|
||||
@@ -133,7 +132,6 @@ impl NodeSpec {
|
||||
disabled: false,
|
||||
read_only: false,
|
||||
required: false,
|
||||
modal: false,
|
||||
actions: Vec::new(),
|
||||
custom_actions: Vec::new(),
|
||||
ltr_axis: false,
|
||||
@@ -295,7 +293,6 @@ fn write_states(node: &mut accesskit::Node, spec: &NodeSpec) {
|
||||
(spec.disabled, accesskit::Node::set_disabled),
|
||||
(spec.read_only, accesskit::Node::set_read_only),
|
||||
(spec.required, accesskit::Node::set_required),
|
||||
(spec.modal, accesskit::Node::set_modal),
|
||||
] {
|
||||
if on {
|
||||
set(node);
|
||||
|
||||
@@ -14,6 +14,7 @@ use craft_ui::popover::Popover;
|
||||
use craft_ui::runtime::env::{BodyMode, RevealEdge, ShellCx, WindowKey};
|
||||
use craft_ui::runtime::focus::Initial;
|
||||
use craft_ui::runtime::memory::{SaveKey, set_saved_value};
|
||||
use craft_ui::runtime::overlay::{Backdrop, Rank};
|
||||
use craft_ui::runtime::{frame, inspect};
|
||||
use craft_ui::testing::access::{NodeKey, layer_root};
|
||||
use craft_ui::testing::in_audit_run;
|
||||
@@ -1446,9 +1447,22 @@ fn events_sent_to_a_replaying_focused_field_reach_it_in_their_frame() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A popover the rooted view shows, open, and whether its layer is modal.
|
||||
#[derive(MemoProps)]
|
||||
struct Rooted<'a> {
|
||||
open: Bind<'a, bool>,
|
||||
modal: bool,
|
||||
}
|
||||
|
||||
/// A popover the view shows, holding a line of text; returns the popover's id.
|
||||
fn rooted(props: &mut Hint<'_>, ui: &mut Ui) -> Option<Id> {
|
||||
let popover = Popover::new("Rooted", props.open.reborrowed()).at_point(POPOVER_AT).initial_focus(Initial::KeepAnchor);
|
||||
fn rooted(props: &mut Rooted<'_>, ui: &mut Ui) -> Option<Id> {
|
||||
let modal = props.modal;
|
||||
let popover = Popover::new("Rooted", props.open.reborrowed()).at_point(POPOVER_AT).initial_focus(Initial::KeepAnchor).overlay(|mut overlay| {
|
||||
if modal {
|
||||
overlay.rank = Rank::modal(Backdrop::None);
|
||||
}
|
||||
overlay
|
||||
});
|
||||
let shown = popover.show(ui, |ui, _| Text::new("Rooted").show(ui));
|
||||
shown.output.open.then_some(shown.output.response.id)
|
||||
}
|
||||
@@ -1467,27 +1481,33 @@ fn ancestors(tree: &craft_ui::testing::access::AccessTree, key: NodeKey) -> Vec<
|
||||
|
||||
/// A popover in a view hangs below its layer's root node, which has its own id, in the run and in each replay: the
|
||||
/// pass's AccessKit parents hold no cycle (every trial's pass-end check), and a replay adds the nodes where the run did.
|
||||
/// A modal layer's flag sits on the popover's own node, which carries its role, never on the root, a plain container.
|
||||
#[trial]
|
||||
fn a_popover_in_a_view_hangs_below_its_layer_root() {
|
||||
let mut frames = still_frames();
|
||||
let mut open = true;
|
||||
let mut popover = None;
|
||||
let mut frame = |frames: &mut Frames| {
|
||||
frames.frame(vec![], |ui| popover = MemoView::new("rooted", Hint { open: Bind::bound(&mut open) }, rooted).show(ui).flatten());
|
||||
let ran = last_frame_memo_runs(&frames.ctx).into_iter().any(|(_, _, run)| run == MemoRun::Ran);
|
||||
let id = popover.expect("the popover is open");
|
||||
let tree = frames.tree();
|
||||
(ran, ancestors(&tree, NodeKey::of(id)), NodeKey::of(layer_root(id)))
|
||||
};
|
||||
let (ran, above, root) = frame(&mut frames);
|
||||
assert!(ran, "the first frame runs the view");
|
||||
assert!(above.contains(&root), "the popover hangs below its layer's root: {above:?}, root {root:?}");
|
||||
for _ in 0..SETTLE {
|
||||
frame(&mut frames);
|
||||
for modal in [false, true] {
|
||||
let mut frames = still_frames();
|
||||
let mut open = true;
|
||||
let mut popover = None;
|
||||
let mut frame = |frames: &mut Frames| {
|
||||
frames.frame(vec![], |ui| popover = MemoView::new("rooted", Rooted { open: Bind::bound(&mut open), modal }, rooted).show(ui).flatten());
|
||||
let ran = last_frame_memo_runs(&frames.ctx).into_iter().any(|(_, _, run)| run == MemoRun::Ran);
|
||||
let id = popover.expect("the popover is open");
|
||||
let tree = frames.tree();
|
||||
let (node, root) = (NodeKey::of(id), NodeKey::of(layer_root(id)));
|
||||
(ran, ancestors(&tree, node), root, (tree.is_modal(node), tree.is_modal(root)))
|
||||
};
|
||||
let (ran, above, root, flags) = frame(&mut frames);
|
||||
assert!(ran, "the first frame runs the view");
|
||||
assert!(above.contains(&root), "the popover hangs below its layer's root: {above:?}, root {root:?}");
|
||||
assert_eq!(flags, (modal, false), "the modal flag sits on the popover's node only (modal {modal})");
|
||||
for _ in 0..SETTLE {
|
||||
frame(&mut frames);
|
||||
}
|
||||
let (ran, replayed, _, flags) = frame(&mut frames);
|
||||
assert!(!ran, "an idle frame replays the view (modal {modal})");
|
||||
assert_eq!(replayed, above, "the replay adds the popover's node where the run did");
|
||||
assert_eq!(flags, (modal, false), "the replay keeps the modal flag on the popover's node (modal {modal})");
|
||||
}
|
||||
let (ran, replayed, _) = frame(&mut frames);
|
||||
assert!(!ran, "an idle frame replays the view");
|
||||
assert_eq!(replayed, above, "the replay adds the popover's node where the run did");
|
||||
}
|
||||
|
||||
/// What the toast view shows: the main window's toasts, over the view's room.
|
||||
|
||||
Reference in New Issue
Block a user