mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-10 23:01:02 +00:00
Find the Weight spinner in the blank-weight tests from its rect, not fixed offsets (#5349)
This commit is contained in:
@@ -244,6 +244,15 @@ fn a_spinner_step_from_a_weight_shown_as_a_preset_moves_past_it() {
|
||||
assert_eq!(app.session.shown_stroke().unwrap().width, 1.0);
|
||||
}
|
||||
|
||||
/// The screen rect of the Weight spinner in the Stroke panel, found by its accessibility label, so
|
||||
/// the tests do not depend on where the panel puts the field.
|
||||
fn weight_spinner_rect(ctx: &egui::Context, app: &mut VectorcraftApp) -> egui::Rect {
|
||||
let out = ctx.run_ui(egui::RawInput::default(), |ui| stroke::show(app, ui));
|
||||
let nodes = &out.platform_output.accesskit_update.as_ref().expect("accessibility is on").nodes;
|
||||
let b = nodes.iter().find(|(_, n)| n.label() == Some("Step up or down")).expect("the weight spinner").1.bounds().expect("its bounds");
|
||||
egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32))
|
||||
}
|
||||
|
||||
/// With objects of different weights selected the Weight field is blank, and its spinner steps
|
||||
/// from 0.25 pt (#5349): up gives 0.5 pt and down gives 0 pt, for all of them, whatever the
|
||||
/// Units > Stroke.
|
||||
@@ -253,6 +262,7 @@ fn the_spinner_of_a_blank_weight_steps_from_a_quarter_point() {
|
||||
|
||||
for (unit, up, after) in [("points", true, 0.5), ("points", false, 0.0), ("millimeters", true, 0.5), ("millimeters", false, 0.0)] {
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut app = app_with_rect();
|
||||
app.session.prefs.units_stroke = unit.into();
|
||||
@@ -260,10 +270,10 @@ fn the_spinner_of_a_blank_weight_steps_from_a_quarter_point() {
|
||||
let b = run(&mut app, "shape.rectangle", json!({"x": 120, "y": 10, "width": 50, "height": 50}))["id"].as_u64().unwrap();
|
||||
run(&mut app, "stroke.set", json!({"ids": [b], "weight": 3}));
|
||||
run(&mut app, "select.set", json!({ "ids": [a.0, b] }));
|
||||
let t = texts(&ctx, &mut app, stroke::show);
|
||||
let r = text_rect(&t, "Weight:");
|
||||
let sp = ctx.global_style().spacing.item_spacing.x;
|
||||
let pos = egui::pos2(r.right() + sp + 8.0, r.center().y + if up { -5.0 } else { 5.0 });
|
||||
texts(&ctx, &mut app, stroke::show);
|
||||
let sr = weight_spinner_rect(&ctx, &mut app);
|
||||
// The up arrow is the upper half of the spinner, the down arrow the lower half.
|
||||
let pos = egui::pos2(sr.center().x, sr.center().y + if up { -sr.height() / 4.0 } else { sr.height() / 4.0 });
|
||||
let button = |pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
|
||||
for event in [egui::Event::PointerMoved(pos), button(true), button(false)] {
|
||||
frame_raw(&ctx, &mut app, egui::RawInput { events: vec![event], ..Default::default() }, stroke::show);
|
||||
@@ -282,17 +292,17 @@ fn the_arrow_keys_in_a_blank_weight_step_from_a_quarter_point() {
|
||||
// A new context each time: the field keeps its text in the context, and the 0.5 pt left by ArrowUp
|
||||
// would make the blank field of the next run start from 0.5 pt.
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let mut app = app_with_rect();
|
||||
let a = app.session.active().unwrap().selection.objects[0];
|
||||
let b = run(&mut app, "shape.rectangle", json!({"x": 120, "y": 10, "width": 50, "height": 50}))["id"].as_u64().unwrap();
|
||||
run(&mut app, "stroke.set", json!({"ids": [b], "weight": 3}));
|
||||
run(&mut app, "select.set", json!({ "ids": [a.0, b] }));
|
||||
let t = texts(&ctx, &mut app, stroke::show);
|
||||
let r = text_rect(&t, "Weight:");
|
||||
let sp = ctx.global_style().spacing.item_spacing.x;
|
||||
// The blank field, right of the 16 px spinner.
|
||||
click(&ctx, &mut app, egui::pos2(r.right() + 2.0 * sp + 16.0 + 30.0, r.center().y), stroke::show);
|
||||
texts(&ctx, &mut app, stroke::show);
|
||||
// The blank field, right of the spinner.
|
||||
let sr = weight_spinner_rect(&ctx, &mut app);
|
||||
click(&ctx, &mut app, egui::pos2(sr.right() + 30.0, sr.center().y), stroke::show);
|
||||
let press = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||
frame_events(&ctx, &mut app, vec![press], stroke::show);
|
||||
for id in [a.0, b] {
|
||||
|
||||
Reference in New Issue
Block a user