diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 8171a54006..7dfc41bf62 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1001,6 +1001,8 @@ mod hidden_layer_tests; #[cfg(test)] mod warp_text_dialog_tests; +#[cfg(test)] +mod options_bar_brush_size_tests; #[cfg(test)] mod options_bar_mode_wheel_tests; diff --git a/crates/ui-egui/src/options_bar_brush_size_tests.rs b/crates/ui-egui/src/options_bar_brush_size_tests.rs new file mode 100644 index 0000000000..c7f5f22c5d --- /dev/null +++ b/crates/ui-egui/src/options_bar_brush_size_tests.rs @@ -0,0 +1,63 @@ +//! #16340: the brush picker field at the start of the options bar shows the tip over the brush size ("20" for the +//! default brush). Since the shell's options slot became a memoized view (#16118) the bar's line lost the slot's +//! height, so the two-line field was cut under the tip and the size read as a sliver. The whole field, caption +//! included, must lie inside the bar for every tool that shows it. + +use egui::accesskit::Role; +use egui::{Rect, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use photocraft_engine::Session; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::Tool; + +type H = Harness<'static, Box>; + +/// The whole app with a new document and `tool` active, after a few settled frames: the options bar runs in the +/// shell's slot, as it does for a person, not on its own. +fn app_with(tool: Tool) -> H { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 64, "height": 48})).unwrap(); + let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), s, crate::Services::default()); + app.ui.tool = tool; + app + }); + h.run_steps(8); + h +} + +/// The options bar's rect: the framework `Bar` is the group named Options (the widest one; its scrolling body is a +/// narrower group of the same name). +fn options_bar(h: &H) -> Rect { + h.query_all_by_role(Role::Group) + .filter(|node| node.accesskit_node().label().is_some_and(|label| label == "Options")) + .map(|node| node.rect()) + .max_by(|a, b| a.width().total_cmp(&b.width())) + .expect("the options bar") +} + +/// The closed brush picker field's rect: the tip over its size caption and the chevron, the group named Brush Preset. +fn brush_field(h: &H) -> Rect { + h.query_all_by_role(Role::Group) + .find(|node| node.accesskit_node().label().is_some_and(|label| label == "Brush Preset")) + .expect("the brush picker field") + .rect() +} + +/// Every tool that shows the brush picker field keeps the whole field, size caption included, inside the bar. +#[test] +fn the_brush_size_under_the_tip_lies_inside_the_options_bar() { + for tool in [Tool::Brush, Tool::Pencil, Tool::Eraser, Tool::CloneStamp, Tool::Healing, Tool::Dodge, Tool::QuickSelection] { + let h = app_with(tool); + let bar = options_bar(&h); + let field = brush_field(&h); + // A tip of the icon size over a caption line: the field is taller than a one-line control, so this checks + // the two-line content, not a bar that happens to fit a single line. + assert!(field.height() > 24.0, "{tool:?}: the field holds a tip over a caption ({field:?})"); + assert!(bar.contains_rect(field), "{tool:?}: the brush picker field {field:?} runs out of the options bar {bar:?}, so its size caption is cut"); + } +}