mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
Merge pull request #17576
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
de8d5faf63
3 files changed
+81
-1
No files matched your search
@@ -307,7 +307,7 @@ fn sections(fields: &DialogFields, document_profile: Option<Label>) -> Vec<Print
|
||||
position("top", tl!("Top")),
|
||||
position("left", tl!("Left")),
|
||||
Param::new("scaleToFit", tl!("Scale to Fit Media"), ParamKind::bool(false)),
|
||||
Param::new("scale", tl!("Scale (%)"), ParamKind::number(Some(1.0), Some(1000.0), 100.0, 1.0, 2))
|
||||
Param::new("scale", tl!("Scale (%)"), ParamKind::number(Some(0.01), Some(1500.0), 100.0, 1.0, 2))
|
||||
.enabled_when("scaleToFit", FieldValue::Bool(false)),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -33,6 +33,7 @@ mod magnetic_lasso_right_click;
|
||||
mod mixer_reset_defaults;
|
||||
mod paint_bucket_all_layers;
|
||||
mod pending_remove_pointer;
|
||||
mod print_scale_range;
|
||||
mod radial_blur_center;
|
||||
mod save_memory_gate;
|
||||
mod system_locale;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//! #14135 (range part): File › Print's Scale field takes up to 1500 % with 2 decimals, as the reference application
|
||||
//! does; the lower bound stays above 0 (the smallest step of 2 decimals, 0.01 %). Values are typed into the field as
|
||||
//! a user types them.
|
||||
|
||||
use egui::{Event, Key, Modifiers, PointerButton};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use photocraft_engine::print_cmds::PrintExt;
|
||||
use photocraft_ui_egui::PhotocraftApp;
|
||||
use photocraft_ui_egui::control::{ControlRequest, Reply};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
type H = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
fn harness() -> H {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), photocraft_ui_egui::Services::default());
|
||||
// Print lists this printer and does not ask the spooler.
|
||||
*app.session.printer_source_mut() =
|
||||
Some(std::sync::Arc::new(|| vec![craft::print::Printer { name: "Test printer".into(), default: true, two_sided: None, description: String::new() }]));
|
||||
app.run("file.new", json!({"width": 600, "height": 400})).unwrap();
|
||||
photocraft_engine::print_cmds::with_spooler(|| photocraft_ui_egui::file_ui::open_print(&mut app));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1000.0, 900.0))
|
||||
.with_max_steps(64)
|
||||
.with_context(app.ctx().clone())
|
||||
.build_ui_state(|ui, app: &mut Box<PhotocraftApp>| photocraft_ui_egui::dialogs::run(app, ui), app);
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// The Print dialog's `scale` as `ui.inspect` lists it.
|
||||
fn scale(h: &mut H) -> f64 {
|
||||
let (request, _) = ControlRequest::new("ui.inspect", json!({}));
|
||||
let ctx = h.ctx.clone();
|
||||
let Reply::Done(reply) = photocraft_ui_egui::control::handle(h.state_mut(), &ctx, &request) else { panic!("ui.inspect did not answer") };
|
||||
let dialogs = reply["result"]["dialogs"].as_array().cloned().unwrap_or_default();
|
||||
dialogs.iter().find_map(|d| d["fields"].get("scale").and_then(Value::as_f64)).expect("the Print dialog lists its scale")
|
||||
}
|
||||
|
||||
/// Types `text` into the Scale field and leaves it with Tab. The decimal mark is typed as the system writes it, since
|
||||
/// the field takes only that one on a system that sets it (a German system refuses a typed `.`).
|
||||
fn type_scale(h: &mut H, text: &str) {
|
||||
let text = text.replace('.', &photocraft_ui_egui::i18n::decimal_separator().unwrap_or('.').to_string());
|
||||
let pos = h.get_by_role_and_label(egui::accesskit::Role::SpinButton, "Scale (%)").rect().center();
|
||||
h.event(Event::PointerMoved(pos));
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.key_press_modifiers(Modifiers::COMMAND, Key::A);
|
||||
h.event(Event::Text(text));
|
||||
h.run_steps(1);
|
||||
h.key_press(Key::Tab);
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
/// The Scale field after typing `typed` into a freshly opened Print dialog.
|
||||
fn typed_scale(typed: &str) -> f64 {
|
||||
let mut h = harness();
|
||||
type_scale(&mut h, typed);
|
||||
scale(&mut h)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scale_defaults_to_100_and_takes_up_to_1500_with_two_decimals() {
|
||||
assert_eq!(scale(&mut harness()), 100.0);
|
||||
for (typed, want) in [("1500", 1500.0), ("1200.5", 1200.5), ("413.19", 413.19), ("2000", 1500.0), ("1500.01", 1500.0)] {
|
||||
let shown = typed_scale(typed);
|
||||
assert!((shown - want).abs() < 1e-9, "typed {typed}: {shown} (want {want})");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_lower_bound_stays_above_zero() {
|
||||
for (typed, want) in [("0.01", 0.01), ("0", 0.01), ("-5", 0.01)] {
|
||||
let shown = typed_scale(typed);
|
||||
assert!(shown > 0.0 && (shown - want).abs() < 1e-9, "typed {typed}: {shown} (want {want})");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user