chrome-w7: net change of 4 commits

- chrome-w7: repair 1
- chrome-w7: finished by an agent
- chrome-w7: review fixes (review-1)
- chrome-w7: review fixes (review-1b)
This commit is contained in:
Martin Ball
2026-11-18 16:01:12 +00:00
parent 56ae57a2c1
commit 675f68e2c4
17 changed files with 319 additions and 28 deletions
+36 -6
View File
@@ -135,7 +135,7 @@ pub enum Reply {
impl Reply {
/// A `ui.accessTree` reply: held until the window's settled access tree is available.
pub fn access_tree() -> Reply {
todo!("ch.C19b")
Reply::AccessTree
}
/// A `ui.screenshot` reply for `token` of `viewport`, writing the PNG to `path` or inlining it
@@ -170,6 +170,7 @@ pub struct ControlChannel {
rx: Receiver<ControlRequest>,
input_waiters: Vec<Sender<ControlResponse>>,
job_waiters: Vec<(JobId, Sender<ControlResponse>)>,
tree_waiters: Vec<Sender<ControlResponse>>,
/// The screenshot queue; the app calls its `issue` and `drain` from its UI and logic phases.
pub captures: Captures,
}
@@ -177,7 +178,7 @@ pub struct ControlChannel {
impl ControlChannel {
/// Attach a transport's receiver (TCP, stdin, tests).
pub fn new(rx: Receiver<ControlRequest>) -> Self {
Self { rx, input_waiters: Vec::new(), job_waiters: Vec::new(), captures: Captures::default() }
Self { rx, input_waiters: Vec::new(), job_waiters: Vec::new(), tree_waiters: Vec::new(), captures: Captures::default() }
}
/// The next request to run, claimed through [`Dispatch::start`]. Expired or abandoned
@@ -205,7 +206,7 @@ impl ControlChannel {
}
Reply::AfterInput => self.input_waiters.push(reply),
Reply::AfterJob(job) => self.job_waiters.push((job, reply)),
Reply::AccessTree => todo!("ch.C19b"),
Reply::AccessTree => self.tree_waiters.push(reply),
Reply::Screenshot { token, path, viewport } => {
if let Err((reply, e)) = self.captures.admit(ScreenshotRequest { token, path, viewport, reply, document, settle_ms }, motion::now()) {
let _ = reply.send(json!({"ok": false, "error": e}));
@@ -249,8 +250,37 @@ impl ControlChannel {
/// request stays held while the host has none. Runs in the logic phase of every pass, as
/// [`poll_input`](Self::poll_input) does.
pub fn poll_access_trees(&mut self, ctx: &egui::Context) {
let _ = ctx;
todo!("ch.C19b")
if self.tree_waiters.is_empty() {
return;
}
// `ui.accessTree` takes no window: it reads the main window's tree.
let Some(update) = WindowHost::of(ctx).access_tree(egui::ViewportId::ROOT) else { return };
let nodes: Vec<Value> = update
.nodes
.iter()
.map(|(id, node)| {
let children: Vec<u64> = node.children().iter().map(|child| child.0).collect();
let mut entry = json!({"id": id.0, "role": format!("{:?}", node.role()), "children": children});
if let Some(name) = node.label() {
entry["name"] = json!(name);
}
if let Some(value) = node.value() {
entry["value"] = json!(value);
}
if let Some(selection) = node.text_selection() {
entry["textSelection"] = json!({
"anchor": {"node": selection.anchor.node.0, "character": selection.anchor.character_index},
"focus": {"node": selection.focus.node.0, "character": selection.focus.character_index},
});
}
entry
})
.collect();
let root = update.tree.as_ref().map(|tree| tree.root.0);
let reply = json!({"ok": true, "result": {"nodes": nodes, "focus": update.focus.0, "root": root}});
for waiter in self.tree_waiters.drain(..) {
let _ = waiter.send(reply.clone());
}
}
/// Drops the host's queued input and the step in flight, and fails every
@@ -293,6 +323,6 @@ impl ControlChannel {
/// Waiters of every kind, for `ui.inspect`'s `pending` count and tests.
pub fn waiting(&self) -> usize {
self.input_waiters.len() + self.job_waiters.len() + self.captures.pending()
self.input_waiters.len() + self.job_waiters.len() + self.tree_waiters.len() + self.captures.pending()
}
}
@@ -119,7 +119,8 @@ pub(crate) fn shown_placement(
let size = default.max(least).min(overlay.size_limits.max.unwrap_or(Vec2::INFINITY)).min(room);
// The layer centres, and is kept, inside the screen cut to `bounds`; bounds that miss the screen leave it whole.
let region = overlay.bounds.map(|bounds| screen.intersect(bounds)).filter(|region| region.is_positive()).unwrap_or(screen);
let pos = placement.pos.map(Pos2::from).or(float.pos).unwrap_or_else(|| region.center() - size / 2.0);
// The saved position is the layer's top left; the float's is where its corner sits.
let pos = placement.pos.map(Pos2::from).or_else(|| float.top_left(size)).unwrap_or_else(|| region.center() - size / 2.0);
let pos = super::window::keep_inside(Rect::from_min_size(pos, size), region).min;
placement.pos = Some(pos.into());
placement.size = Some(size.into());
@@ -186,7 +186,7 @@ pub(super) fn opener_anchor(opener: &Opener, opening: Opening, place: &Place) ->
return anchor.clone();
}
match (place, opening) {
(Place::Anchored { anchor: anchor @ (Anchor::Pointer | Anchor::Corner(..)), .. }, _) => anchor.clone(),
(Place::Anchored { anchor: anchor @ (Anchor::Pointer | Anchor::Corner(..) | Anchor::Parent), .. }, _) => anchor.clone(),
(_, Opening::Pointer) => Anchor::Pointer,
(_, Opening::At(rect)) => Anchor::Rect(rect),
(_, Opening::Plain) => Anchor::Response,
@@ -53,6 +53,11 @@ impl FloatPlace {
pub const fn corner_at(pos: Pos2, corner: Align2) -> Self {
FloatPlace { pos: Some(pos), corner }
}
/// The top left of a layer `size` large whose `corner` sits at `pos`; `None` for a centred layer.
pub(crate) fn top_left(&self, size: Vec2) -> Option<Pos2> {
self.pos.map(|pos| pos - self.corner.pos_in_rect(&Rect::from_min_size(Pos2::ZERO, size)).to_vec2())
}
}
/// Where an egui layer sits.
@@ -20,18 +20,27 @@ pub(crate) fn resolve_anchor(ctx: &Context, id: Id, overlay: &Overlay, own: Rect
return match opener_anchor(opener, opening, &overlay.place) {
Anchor::Rect(rect) | Anchor::Corner(rect, _) => to_screen * rect,
Anchor::Point(at) => to_screen * Rect::from_min_max(at, at),
Anchor::Parent => parent_rect(ctx).unwrap_or(to_screen * opener.rect),
_ => to_screen * opener.rect,
};
}
match &overlay.place {
Place::Anchored { anchor: Anchor::Rect(rect) | Anchor::Corner(rect, _), .. } => own_to_screen * *rect,
Place::Anchored { anchor: Anchor::Point(at), .. } => own_to_screen * Rect::from_min_max(*at, *at),
Place::Anchored { anchor: Anchor::Parent, .. } => parent_rect(ctx).unwrap_or(own_to_screen * own),
_ => own_to_screen * own,
}
}
/// The placed panel rect, in screen space, of the layer whose body is running: the parent a layer opened now has.
/// `None` outside a layer or before the parent has been placed.
fn parent_rect(ctx: &Context) -> Option<Rect> {
let parent = overlay::drawing_parent(ctx)?;
overlay::entry(ctx, parent).map(|entry| entry.rect)
}
/// The overlay with the place's anchor that of the opener that opened it, for the anchors the host reads from the
/// place (`Pointer`, `Corner`).
/// place (`Pointer`, `Corner`, `Parent`).
pub(super) fn opened_overlay(ctx: &Context, overlay: &Overlay, stored: Option<Opening>) -> Option<(Overlay, Opening)> {
let first = overlay.opener.as_ref()?;
let (opener, opening) = first.active(ctx, stored);
@@ -243,7 +252,7 @@ pub(super) fn placement(ctx: &Context, layer: &Layer<'_>, size: Option<egui::Vec
Place::Float(float) => {
let kept = within_bounds(layer.overlay, bounds);
let size = size.unwrap_or(egui::Vec2::ZERO);
let min = float.pos.unwrap_or_else(|| kept.center() - size / 2.0);
let min = float.top_left(size).unwrap_or_else(|| kept.center() - size / 2.0);
let at = crate::contract::body::keep_inside(Rect::from_min_size(min, size), kept).min;
Placed { at, side: None, room: (kept.max - at).max(egui::Vec2::ZERO).min(cap) }
}
@@ -189,7 +189,6 @@ impl Overlay {
mapped.placed = mapped.placed.map(|rect| to_screen * rect);
mapped.placed_at = mapped.placed_at.map(|pos| to_screen * pos);
mapped.bounds = mapped.bounds.map(|rect| to_screen * rect);
// P3(chrome-w7): ch.C20a: the pattern ignores the new `corner`.
if let Place::Float(FloatPlace { pos: Some(pos), .. }) = &mut mapped.place {
*pos = to_screen * *pos;
}
+62 -6
View File
@@ -15,7 +15,7 @@ use egui::FullOutput;
use egui::{Context, Id, IdMap, IdSet, ViewportId};
use std::collections::HashMap;
use super::pass;
use super::{memory, pass};
pub(crate) use node::{NodeAction, NodeSpec, Toggle, write_node};
pub(crate) use patch::{write_label_patch, write_merge_patch, write_status};
@@ -48,12 +48,68 @@ fn behind_modal(ctx: &Context, viewport: ViewportId, layer: egui::LayerId) -> bo
#[cfg(feature = "testing")]
pub type NodeId = accesskit::NodeId;
/// Settles the AccessKit update's focus: when it is not among the update's nodes, focus goes to the tree root. The
/// runtime plugin's output hook calls it once per pass.
#[allow(dead_code)] // P3(chrome-w7): ch.C18
/// Settles the AccessKit update's focus: when it is not among the update's nodes, focus goes to the tree root, or
/// to egui's root node when the update carries no tree info but holds that node. A platform adapter rejects an
/// update whose focus names no node, so no pass may hand one out. The runtime plugin's output hook calls it once per
/// pass.
pub(crate) fn settle_focus(output: &mut egui::FullOutput) {
let _ = output;
todo!("ch.C18")
let Some(update) = output.platform_output.accesskit_update.as_mut() else { return };
if update.nodes.iter().any(|(id, _)| *id == update.focus) {
return;
}
let egui_root = egui::accesskit_root_id().accesskit_id();
let root = update.tree.as_ref().map(|tree| tree.root).or_else(|| update.nodes.iter().any(|(id, _)| *id == egui_root).then_some(egui_root));
if let Some(root) = root {
update.focus = root;
}
}
/// The settled update of each viewport's last pass, the host fact `WindowHost::access_tree` reads.
#[derive(Default)]
struct Settled {
/// The viewports whose pass is ending, the innermost last. egui calls the output hook after it has left the
/// pass, when the running viewport is the parent's again, so the hook takes the viewport the pass-end step
/// recorded. A nested viewport's pass ends, hook included, inside its parent's, which keeps the order a stack.
ending: Vec<ViewportId>,
/// One update per viewport, replaced by each of its passes.
trees: HashMap<ViewportId, accesskit::TreeUpdate>,
}
/// Records that the running viewport's pass is ending, for the output hook that follows it ([`settle_output`]).
pub(crate) fn note_pass_end(ctx: &Context) {
let viewport = pass::current_viewport(ctx);
memory::with::<Settled, _>(ctx, |settled| settled.ending.push(viewport));
}
/// The output step of a pass: settles the update's focus ([`settle_focus`]) and records the settled update as the
/// ending viewport's, or forgets that viewport's update while AccessKit is off.
pub(crate) fn settle_output(ctx: &Context, output: &mut egui::FullOutput) {
settle_focus(output);
// A closed window never runs again to replace or drop its entry, so the frame's end hook prunes the store to the
// viewports that are open.
crate::runtime::frame::register_prune(ctx, std::any::TypeId::of::<Settled>(), prune_settled);
let update = output.platform_output.accesskit_update.clone();
memory::with::<Settled, _>(ctx, |settled| {
let Some(viewport) = settled.ending.pop() else { return };
match update {
Some(update) => {
settled.trees.insert(viewport, update);
}
None => {
settled.trees.remove(&viewport);
}
}
});
}
/// Drops the settled updates of the viewports that are no longer open.
fn prune_settled(ctx: &Context, live: &[ViewportId]) {
memory::with::<Settled, _>(ctx, |settled| settled.trees.retain(|viewport, _| live.contains(viewport)));
}
/// The settled update of `viewport`'s last pass; `None` while AccessKit is off or before the viewport has run.
pub(crate) fn settled_tree(ctx: &Context, viewport: ViewportId) -> Option<accesskit::TreeUpdate> {
memory::with::<Settled, _>(ctx, |settled| settled.trees.get(&viewport).cloned())
}
/// The AccessKit id of the node of `id`.
@@ -1,7 +1,7 @@
//! The plugin impl, its registration and hook order, and the plugin lock.
use crate::runtime::frame;
use egui::{Context, Plugin, RawInput, Ui};
use egui::{Context, FullOutput, Plugin, RawInput, Ui};
/// The runtime's plugin. egui holds a plugin's mutex while it calls a hook, so the struct holds no state:
/// every record lives in context data behind its own lock.
@@ -22,8 +22,13 @@ impl Plugin for RuntimePlugin {
}
fn on_end_pass(&mut self, ui: &mut Ui) {
crate::runtime::egui::access::note_pass_end(ui.ctx());
frame::end_pass(ui);
}
fn output_hook(&mut self, ctx: &Context, output: &mut FullOutput) {
crate::runtime::egui::access::settle_output(ctx, output);
}
}
/// Whether the runtime plugin is on `ctx`.
@@ -145,6 +145,8 @@ pub(crate) struct Record {
known: Option<Rect>,
/// The place the window's own pass last saw.
seen: Option<Rect>,
/// The smallest inner size its caller asks for, as the window's builder carries it.
min_size: Option<Vec2>,
}
/// Passes between searches for an OS window that was not found.
+17 -7
View File
@@ -120,8 +120,7 @@ impl WindowHost {
/// The viewport's latest settled AccessKit update, a host fact of the window as its screenshot facts are; `None`
/// while AccessKit is off.
pub fn access_tree(&self, viewport: ViewportId) -> Option<accesskit::TreeUpdate> {
let _ = viewport;
todo!("ch.C19a")
crate::runtime::egui::access::settled_tree(&self.ctx, viewport)
}
/// Queues a pointer move to `at` in `viewport` with `mods` held, delivered on a pass of its own; the modifiers stay
@@ -312,12 +311,23 @@ impl WindowHost {
}
/// Places `viewport`'s outer rect at `outer`: its position, and the inner size that leaves the window's
/// decoration as it is. False when a command could not go out.
/// decoration as it is. A minimized window is restored first, and a placement below the window's smallest inner
/// size lowers that size to the placed one, so the window takes the place it is given. False when a command could
/// not go out.
pub fn set_outer(&self, viewport: ViewportId, outer: Rect) -> bool {
let decoration = self.facts(viewport).and_then(|facts| facts.outer.map(|current| current.size() - facts.inner.size())).unwrap_or(Vec2::ZERO);
let moved = act(&self.ctx, viewport, WindowAction::SetOuterPosition(outer.min));
let sized = act(&self.ctx, viewport, WindowAction::SetInnerSize((outer.size() - decoration).max(Vec2::ZERO)));
moved && sized
let facts = self.facts(viewport);
let decoration = facts.and_then(|facts| facts.outer.map(|current| current.size() - facts.inner.size())).unwrap_or(Vec2::ZERO);
let inner = (outer.size() - decoration).max(Vec2::ZERO);
let mut sent = true;
if facts.is_some_and(|facts| facts.state == WindowState::Minimized) {
sent &= act(&self.ctx, viewport, WindowAction::Restore);
}
let least = PerViewport::<Record>::with(&self.ctx, viewport, |record| record.min_size);
if let Some(least) = least.filter(|least| inner.x < least.x || inner.y < least.y) {
sent &= act(&self.ctx, viewport, WindowAction::SetMinInnerSize(least.min(inner)));
}
sent &= act(&self.ctx, viewport, WindowAction::SetOuterPosition(outer.min));
sent & act(&self.ctx, viewport, WindowAction::SetInnerSize(inner))
}
/// The viewport of the container `id` while its window is open.
@@ -48,6 +48,10 @@ pub enum WindowAction {
SetOuterPosition(Pos2),
/// Sizes the window's inner area in points.
SetInnerSize(Vec2),
/// Restores a minimized window.
Restore,
/// Sets the smallest inner size the window can be given, in points.
SetMinInnerSize(Vec2),
/// Changes the window's level.
SetLevel(WindowLevel),
/// Changes the window's title.
@@ -93,6 +97,8 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
| WindowAction::StartMove
| WindowAction::SetOuterPosition(_)
| WindowAction::SetInnerSize(_)
| WindowAction::Restore
| WindowAction::SetMinInnerSize(_)
| WindowAction::SetLevel(_)
| WindowAction::SetTitle(_) => commands,
WindowAction::SetOpacity(_) => false,
@@ -129,6 +135,8 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
viewports::command(ctx, viewport, egui::ViewportCommand::InnerSize(size));
PerViewport::<Record>::with(ctx, viewport, |record| record.known = record.known.map(|known| Rect::from_min_size(known.min, size)));
}
WindowAction::Restore => viewports::command(ctx, viewport, egui::ViewportCommand::Minimized(false)),
WindowAction::SetMinInnerSize(size) => viewports::command(ctx, viewport, egui::ViewportCommand::MinInnerSize(size)),
WindowAction::SetLevel(level) => {
// A window opened by `show_viewport` gets its level with the next build of its viewport; any other (the
// root) is told now.
@@ -62,6 +62,7 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
record.chrome = Some(chrome);
record.captions = captions.clone();
record.resizable = Some(open.resizable);
record.min_size = open.limits.0;
record.awaiting_first_paint |= spec.shown_after_first_paint && record.facts.is_none();
if record.title.as_deref() != Some(open.title) {
record.title = Some(open.title.to_owned());
@@ -0,0 +1,65 @@
//! The settled focus of the access tree: a focus that names no node of the update is the tree root, in the tree a
//! frame hands out and in the per-viewport record the window host keeps.
use craft_ui::contract::{Props as _, Show as _};
use craft_ui::runtime::windows::WindowHost;
use craft_ui::testing::access::{NodeKey, focused_key};
use craft_ui::testing::{Frames, trial};
use craft_ui_test_kit::contract::{Probe, Seen};
use craft_ui_test_kit::windows::Windows;
use egui::{Id, Ui, ViewportBuilder, ViewportId};
use std::cell::RefCell;
/// Gives egui focus to a widget that is never shown, so it has no node in the pass's update.
fn focus_nowhere(ui: &mut Ui) {
ui.memory_mut(|memory| memory.request_focus(Id::new("a widget with no node")));
}
#[trial]
fn access_focus_outside_the_nodes_moves_to_the_tree_root() {
let seen = RefCell::new(Seen::default());
let mut frames = Frames::new();
let root = NodeKey::of(egui::accesskit_root_id());
for frame in 0..3 {
frames.frame(vec![], |ui| {
Probe::new(&seen).label("Shown").show(ui);
focus_nowhere(ui);
});
let tree = frames.tree();
assert!(tree.has(seen.borrow().id.expect("the probe ran")), "frame {frame}: the shown node is in the tree");
assert_eq!(focused_key(&tree), root, "frame {frame}: the focus names no node, so the root has it");
}
}
#[trial]
fn the_host_reports_each_viewports_settled_access_tree() {
let windows = Windows::new();
let host = WindowHost::of(&windows.ctx);
let child = ViewportId::from_hash_of("settled tree window");
let (main, kid) = (RefCell::new(Seen::default()), RefCell::new(Seen::default()));
for _ in 0..2 {
windows.frame(vec![], vec![], |ui| {
Probe::new(&main).label("Main").show(ui);
focus_nowhere(ui);
ui.ctx().show_viewport_immediate(child, ViewportBuilder::default(), |cui, _| {
Probe::new(&kid).label("Kid").show(cui);
});
});
}
let (main, kid) = (main.borrow().id.expect("the main window ran"), kid.borrow().id.expect("the second window ran"));
let root = egui::accesskit_root_id().accesskit_id();
let main_tree = host.access_tree(ViewportId::ROOT).expect("the main window's tree is recorded");
let main_nodes: Vec<u64> = main_tree.nodes.iter().map(|(id, _)| id.0).collect();
assert!(main_nodes.contains(&main.accesskit_id().0), "the main window's tree holds its node");
assert!(!main_nodes.contains(&kid.accesskit_id().0), "the main window's tree holds no node of the second window");
assert_eq!(main_tree.tree.as_ref().map(|tree| tree.root), Some(root), "the tree is rooted at egui's root");
assert_eq!(main_tree.focus, root, "the recorded tree carries the settled focus");
let kid_tree = host.access_tree(child).expect("the second window's tree is recorded");
let kid_nodes: Vec<u64> = kid_tree.nodes.iter().map(|(id, _)| id.0).collect();
assert!(kid_nodes.contains(&kid.accesskit_id().0), "the second window's tree is its own");
assert!(!kid_nodes.contains(&main.accesskit_id().0), "the second window's tree holds no node of the main window");
assert!(host.access_tree(ViewportId::from_hash_of("never opened")).is_none(), "a viewport that never ran has no tree");
}
@@ -3,6 +3,7 @@
mod bounds;
mod face_record;
mod face_state;
mod focus;
mod nodes;
mod scope;
mod static_text;
+66 -2
View File
@@ -4,7 +4,7 @@
use craft_behavior::overlay::{Align, Side};
use craft_behavior::{GesturePhase, Sense};
use craft_ui::contract::overlay::{Anchor, Place, PlacementChange, PlacementKind};
use craft_ui::contract::overlay::{Anchor, FloatPlace, Place, PlacementChange, PlacementKind};
use craft_ui::contract::{
BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, Mount, Overlay, Props as _, Role, Show as _,
ShowContainer as _, Sizing,
@@ -16,7 +16,7 @@ use craft_ui::testing::input::key_press;
use craft_ui::testing::layout::allocate;
use craft_ui::testing::{Frames, pointer, trial};
use craft_ui_test_kit::contract::{PlainStyle, Probe, Seen};
use egui::{Key, Modifiers, Pos2, Rect, Response, Ui, Vec2};
use egui::{Align2, Key, Modifiers, Pos2, Rect, Response, Ui, Vec2};
use std::cell::{Cell, RefCell};
const SLACK: f32 = 1.5;
@@ -231,3 +231,67 @@ fn a_layer_with_bounds_shows_inside_them_hung_or_placed() {
assert!(BOUNDS.expand(SLACK).contains_rect(rect), "{name}: the layer lies inside {BOUNDS:?}: {rect:?}");
}
}
/// A layer anchored `Parent` hangs from the placed panel of the layer whose body opened it, not from its own cursor.
#[trial]
fn a_layer_anchored_parent_hangs_on_the_parent_panel() {
let (parent_rect, child_rect) = (Cell::new(Rect::NOTHING), Cell::new(Rect::NOTHING));
let (log, seen, kid) = (RefCell::new(Vec::new()), RefCell::new(Seen::default()), RefCell::new(Seen::default()));
let mut show = |ui: &mut Ui| {
let props = ContainerProps::new().mount(Mount::Layer(Overlay::floating().placed(START))).sizing(Sizing::Content);
let out = Pane { common: Common::new(), props, log: &log }.id_salt("parent").show(ui, |ui, _| {
Probe::new(&seen).size(BODY).show(ui);
let overlay = Overlay::popover().place(Place::anchored(Anchor::Parent, Side::Below, Align::Start));
let props = ContainerProps::new().mount(Mount::Layer(overlay)).sizing(Sizing::Content);
let inner = Pane { common: Common::new(), props, log: &log }.id_salt("child").show(ui, |ui, _| {
Probe::new(&kid).size(Vec2::new(60.0, 20.0)).show(ui);
});
child_rect.set(inner.output.rect);
});
parent_rect.set(out.output.rect);
};
let mut frames = Frames::new();
frames.idle(6, &mut show);
let (parent, child) = (parent_rect.get(), child_rect.get());
assert!(parent.is_positive() && child.is_positive(), "both layers show: {parent:?} {child:?}");
assert!((child.left() - parent.left()).abs() < SLACK, "the child lines up with the parent panel's start: {parent:?} {child:?}");
assert!((child.top() - parent.bottom()).abs() < SLACK, "the child hangs below the parent panel: {parent:?} {child:?}");
}
/// A float placed by its right-top corner has that corner at the position, its width reaching back from it; near the
/// start edge of its bounds, where the corner's place would put the layer outside them, it is kept inside.
#[trial]
fn a_float_places_its_corner_at_the_position() {
let free = Pos2::new(500.0, 120.0);
let near_edge = Pos2::new(BOUNDS.left() + 20.0, BOUNDS.top() + 20.0);
for (name, at, bounds) in [("free", free, None), ("kept", near_edge, Some(BOUNDS))] {
let (shown, log, seen) = (Cell::new(Rect::NOTHING), RefCell::new(Vec::new()), RefCell::new(Seen::default()));
let mut show = |ui: &mut Ui| {
let overlay = Overlay::floating().place(Place::Float(FloatPlace::corner_at(at, Align2::RIGHT_TOP)));
let overlay = match bounds {
Some(bounds) => overlay.bounds(bounds),
None => overlay,
};
let props = ContainerProps::new().mount(Mount::Layer(overlay)).sizing(Sizing::Content);
let out = Pane { common: Common::new(), props, log: &log }.id_salt(name).show(ui, |ui, _| {
Probe::new(&seen).size(BODY).show(ui);
});
shown.set(out.output.rect);
};
let mut frames = Frames::new();
frames.idle(4, &mut show);
let rect = shown.get();
assert!(rect.width() >= BODY.x - SLACK, "{name}: the layer shows its body: {rect:?}");
match bounds {
None => {
assert!((rect.right_top() - at).abs().max_elem() < SLACK, "{name}: the right-top corner sits at {at:?}: {rect:?}");
assert!((rect.left() - (at.x - rect.width())).abs() < SLACK, "{name}: the layer reaches back its width: {rect:?}");
}
Some(bounds) => {
assert!(bounds.expand(SLACK).contains_rect(rect), "{name}: the layer lies inside {bounds:?}: {rect:?}");
assert!((rect.left() - bounds.left()).abs() < SLACK, "{name}: the layer is kept at the start edge: {rect:?}");
assert!((rect.top() - at.y).abs() < SLACK, "{name}: the corner's top stays at {at:?}: {rect:?}");
}
}
}
}
@@ -377,6 +377,41 @@ fn a_content_sized_window_takes_its_content_size_once_it_reported_its_place() {
);
}
/// Placing a minimized window below its smallest inner size restores it and lowers that size to the placed one, so the
/// window takes the place it is given.
#[trial]
fn placing_a_minimized_window_below_its_minimum_restores_it_at_the_placed_size() {
const PLACED: Rect = Rect { min: Pos2::new(10.0, 20.0), max: Pos2::new(50.0, 50.0) };
let windows = Windows::with(InstallSpec::new(ShellInfo::default(), Arc::new(FakeSystem::new())));
let frame = || {
windows.frame(vec![], vec![], |ui| {
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |_, _| {});
})
};
let first = frame();
let (id, _) = builder_titled(&first, "tool");
let given = Rect::from_min_size(Pos2::new(100.0, 100.0), Vec2::new(400.0, 300.0));
windows.child_info(ViewportInfo {
inner_rect: Some(given),
outer_rect: Some(given),
native_pixels_per_point: Some(1.0),
minimized: Some(true),
..ViewportInfo::default()
});
frame();
frame();
assert!(WindowHost::of(&windows.ctx).set_outer(id, PLACED), "the commands went out");
let sent: Vec<ViewportCommand> = frame().commands.into_iter().filter(|(window, _)| *window == id).map(|(_, command)| command).collect();
assert!(sent.contains(&ViewportCommand::Minimized(false)), "the window is restored: {sent:?}");
assert!(sent.contains(&ViewportCommand::InnerSize(PLACED.size())), "the window takes the placed size: {sent:?}");
let lowered = sent.iter().find_map(|command| match command {
ViewportCommand::MinInnerSize(size) => Some(*size),
_ => None,
});
let lowered = lowered.expect("the minimum went below the placed size");
assert!(lowered.x <= PLACED.width() && lowered.y <= PLACED.height(), "the minimum fits the placed size: {lowered:?}");
}
/// The OS windows the runtime opens carry the app id the app installed, as its main window does: docks and Wayland
/// compositors find the app's icon and rules by it.
#[trial]
@@ -39,7 +39,7 @@ fn a_modals_strip_stands_for_the_hit_sink() {
bar.set(TitleBar::new().show_titled(ui, Title::new("Landscape.psd"), |_, _| {}, |_, _| {}).response.rect);
let mut open = true;
let shown = Dialog::new("Grid options")
.first_place(at, Align2::LEFT_TOP) // P3(chrome-w7): ch.C20b
.first_place(at, Align2::LEFT_TOP)
.opened(Bind::bound(&mut open))
.buttons([FooterButton::new("OK", DialogRole::Accept), FooterButton::new("Cancel", DialogRole::Cancel)])
.show(ui, |ui, _| {