mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Options bar: a test that the brush size under the tip lies inside the bar (#16340)
The brush picker field at the start of the options bar shows the tip over the brush size. Since the shell's options slot became a memoized view the bar's line lost the slot's height and the caption was cut to a sliver (#16340). The framework keeps the slot's line through a memoized view again since storytold/craft-libs#3055, which the current pin carries, so the field fits on main; this test lays out the whole app with each tool that shows the field and checks the field lies inside the Options bar, so the caption cannot be clipped again unnoticed.
This commit is contained in:
1 parent
928326271c
commit
8a549a98e9
2 files changed
+65
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
@@ -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<PhotocraftApp>>;
|
||||
|
||||
/// 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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user