App red round 6 g4: fixes from the g4 fixer

This commit is contained in:
Dylan M. Taylor committed 2026-11-19 09:58:22 -05:00
1 parent 072b69e0f8
commit 0c97531f76
10 files changed
+146 -74

No files matched your search

+3
View File
@@ -759,6 +759,9 @@ impl PdfCraftApp {
// The shell's body is the dock, whose document panel draws the page area or what takes its place
// (`side_panels::document_view`).
chrome::shell(self, ui);
// The keys the app reads itself, once the shell's pass has fired the commands and the tool host has taken
// its tools' keys; leaving full screen is followed in this same pass.
self.shortcuts(&ctx);
self.follow_screen_mode();
if !self.full_screen_document() && !self.ocr_verify.open {
// FitWindow and CenterWindow, once the document just opened is laid out.
+5 -2
View File
@@ -10,8 +10,11 @@ impl PdfCraftApp {
if self.modal_open() {
return;
}
// PLAN: Escape is read raw here until the plan names the signal for "the tool host did not take Escape" (a declined-key output or a catalog `app.escape` command); it then calls `escape` from that signal.
if ctx.input(|input| input.key_pressed(egui::Key::Escape)) {
// The window's Escape: the one no component took this pass (a dialog, a menu, a field, the
// canvas's tool and sessions all take theirs first). Escape moves nothing, so the
// direction does not matter.
let cancel = craft::ui::runtime::keys::with_window_intents(ctx, false, |window| window.take_exact(&craft::behavior::Intent::Cancel));
if cancel {
self.escape(ctx);
}
}
+11
View File
@@ -383,6 +383,10 @@ pub struct PageSession {
/// The rectangle being dragged on a page by Snapshot, Crop or a signature area: the page tools are built each
/// pass, so the drag lives here from its press to its release.
pub(crate) box_drag: PageBoxDrag,
/// The Hand tool and Marquee Zoom's Zoom tool: each keeps its gesture (the press, the last
/// point, a flick's glide) from pass to pass, so the page tool lends them rather than building them.
pub(crate) hand: craft::ui::canvas::HandTool,
pub(crate) marquee_zoom: craft::ui::canvas::ZoomTool,
/// What the last secondary press on a page went to, and on which page (`None` off the pages): the page's menu
/// shows its entries when it has a menu and is the one selected, or else the page's own.
pub(crate) menu_for: Option<(usize, Owner)>,
@@ -438,6 +442,8 @@ impl PageSession {
fill_selection: Default::default(),
signature_drag: Default::default(),
box_drag: PageBoxDrag::default(),
hand: craft::ui::canvas::HandTool::new(Default::default()),
marquee_zoom: craft::ui::canvas::ZoomTool::new(Default::default()),
menu_for: None,
}
}
@@ -1447,6 +1453,11 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
if out.toggle_white_space {
view.view.hide_white_space = !view.view.hide_white_space;
}
// Full screen shows the page alone, so its keys are the page's: with nothing else holding the keyboard, the page
// view takes it, and the presenter's keys reach the running tool.
if presenting && ui.ctx().memory(|m| m.focused()).is_none() {
focus::request(ui.ctx(), FocusTarget::Id(out.canvas.response.id));
}
if let Some(action) = body_out.action.take() {
view.pending_action = Some(action);
}
+18 -11
View File
@@ -130,10 +130,10 @@ pub(crate) struct ToolBench<'a> {
enum Arm<'a> {
/// Select and Column Select: the text selection and the picture pick.
Select(PageSelectTool<'a>),
/// The Hand tool.
Hand(HandTool),
/// Marquee Zoom: the framework's Zoom tool without scrubbing, so a drag draws the rectangle.
MarqueeZoom(ZoomTool),
/// The Hand tool, the session's.
Hand(&'a mut HandTool),
/// Marquee Zoom: the framework's Zoom tool without scrubbing, so a drag draws the rectangle; the session's.
MarqueeZoom(&'a mut ZoomTool),
/// A tool whose result is all in the session it borrows.
Area(Box<dyn CanvasTool + 'a>),
/// The camera quadrilateral, moved to the page a click went to.
@@ -323,11 +323,12 @@ pub(crate) fn page_tool<'a>(
}
}
}
QuickTool::Hand => Arm::Hand(HandTool::new(cx.navigation)),
QuickTool::Hand => Arm::Hand(hand(session, cx.navigation)),
QuickTool::MarqueeZoom => {
let mut options = cx.navigation;
options.scrubby_zoom = false;
Arm::MarqueeZoom(ZoomTool::new(options))
session.marquee_zoom.options = options;
Arm::MarqueeZoom(&mut session.marquee_zoom)
}
QuickTool::Measure(t) => {
Arm::Measure(MeasureTool::new(&mut session.measure, cx.doc, map, cx.info, t, cx.units, cx.author, cx.host, cx.wake.clone()))
@@ -366,7 +367,7 @@ pub(crate) fn page_tool<'a>(
map,
)),
// The library no longer holds the stamp: no click places one, and a drag pans as the Hand tool's.
None => Arm::Hand(HandTool::new(cx.navigation)),
None => Arm::Hand(hand(session, cx.navigation)),
},
QuickTool::Link => Arm::Area(Box::new(LinkTool::new(session, cx.pages, cx.info, *press))),
QuickTool::SignArea { certify } => Arm::SignArea(SignAreaTool::new(certify, &mut session.box_drag, cx.pages, cx.rotation, cx.info)),
@@ -375,12 +376,18 @@ pub(crate) fn page_tool<'a>(
PageTool { arm, tool, selects_text, released: false, presenting: cx.presenting, presenter_keys: Vec::new() }
}
/// The session's Hand tool under the user's navigation choices of this pass.
fn hand(session: &mut PageSession, navigation: NavigationOptions) -> &mut HandTool {
session.hand.options = navigation;
&mut session.hand
}
impl<'a> PageTool<'a> {
fn tool(&self) -> &(dyn CanvasTool + 'a) {
match &self.arm {
Arm::Select(t) => t,
Arm::Hand(t) => t,
Arm::MarqueeZoom(t) => t,
Arm::Hand(t) => &**t,
Arm::MarqueeZoom(t) => &**t,
Arm::Area(t) => &**t,
Arm::Camera(t) => t,
Arm::Measure(t) => t,
@@ -395,8 +402,8 @@ impl<'a> PageTool<'a> {
fn tool_mut(&mut self) -> &mut (dyn CanvasTool + 'a) {
match &mut self.arm {
Arm::Select(t) => t,
Arm::Hand(t) => t,
Arm::MarqueeZoom(t) => t,
Arm::Hand(t) => &mut **t,
Arm::MarqueeZoom(t) => &mut **t,
Arm::Area(t) => &mut **t,
Arm::Camera(t) => t,
Arm::Measure(t) => t,
+3 -2
View File
@@ -526,8 +526,9 @@ mod sidecar_tests {
jobs.run_all();
h.step();
}
assert_eq!(std::fs::read(&named).unwrap(), b"someone else's file", "the named file is untouched");
assert!(std::fs::read(&chosen).unwrap().starts_with(b"%PDF"), "the document went where the user chose");
// Saves go through the host's files, which hold what is written in memory.
assert!(files.file(&named).is_none(), "the named file is untouched");
assert!(files.file(&chosen).expect("the save wrote the chosen file").starts_with(b"%PDF"), "the document went where the user chose");
// The chosen file is the document's file now: the next Save writes it without asking.
let ctx_h = h.ctx.clone();
+7 -11
View File
@@ -187,20 +187,17 @@ fn content_row(d: &PrintDraft) -> Param {
fn paper_section(d: &PrintDraft, sizes: &[(f64, f64)], units: Unit, no_printers: bool) -> PrintSection {
let detecting = d.papers_loading();
let mut papers: Vec<(String, Label)> = d.papers.iter().enumerate().map(|(i, (name, _))| (i.to_string(), lbl(tl!(name)))).collect();
// Each paper is keyed by its name, which no two papers share: a list that changes under the
// dialog (a printer's own sizes arriving) leaves a pick on the paper it named.
let mut papers: Vec<(String, Label)> = d.papers.iter().map(|(name, _)| (name.clone(), lbl(tl!(name)))).collect();
// The line between the standard sizes and the custom ones falls before the first custom size.
let mut separator = papers.len();
papers.extend(
d.custom_papers
.iter()
.enumerate()
.map(|(i, p)| ((d.papers.len() + i).to_string(), lbl(format!("{} ({})", p.name, units.size(p.width, p.height))))),
);
papers.extend(d.custom_papers.iter().map(|p| (p.name.clone(), lbl(format!("{} ({})", p.name, units.size(p.width, p.height))))));
if detecting {
papers.insert(0, ("detecting".to_owned(), lbl(tl!("Detecting paper…"))));
separator += 1;
}
let mut paper = Param::new("paper", row_label(tl!("Paper:")), ParamKind::choice(papers, Some(d.paper.to_string())));
let mut paper = Param::new("paper", row_label(tl!("Paper:")), ParamKind::choice(papers, Some(d.paper_name())));
if !d.custom_papers.is_empty() {
paper = paper.separated_at(separator);
}
@@ -469,7 +466,7 @@ pub(super) fn fields_from_draft(d: &PrintDraft) -> DialogFields {
f.set("content", id_of(&CONTENT, d.content));
f.set("as_image", d.as_image);
f.set("dpi", (d.dpi.round() as u32).to_string());
f.set("paper", d.paper.to_string());
f.set("paper", d.paper_name());
f.set("custom_open", d.custom_new.is_some());
if let Some((name, width, height)) = &d.custom_new {
let typed = |s: &str| s.trim().parse::<f64>().unwrap_or(0.0);
@@ -525,9 +522,8 @@ pub(super) fn draft_from_fields(d: &mut PrintDraft, f: &DialogFields, edited: &[
d.set_handling(h);
}
if on("paper")
&& let Some(p) = text("paper").and_then(|t| t.parse::<usize>().ok())
&& let Some(p) = text("paper").and_then(|t| d.paper_index(t))
&& p != d.paper
&& p < d.paper_count()
{
let before = d.paper;
d.paper = p;
+34 -19
View File
@@ -314,8 +314,8 @@ fn format_validate_and_calculate_tabs() {
h.get_by_role_and_label(Role::CheckBox, "To:").click();
h.run_steps(2);
tab(&mut h, "Calculate");
choose(&mut h, "Simplified field notation:");
retype_script(&mut h, "name");
choose(&mut h, NOTATION);
retype_box(&mut h, NOTATION, "name");
h.get_by_label("OK").click();
h.run_steps(3);
let s = h.state();
@@ -382,9 +382,19 @@ fn city_calculation(h: &Harness<'static, PdfCraftApp>) -> (pdfcraft_engine::form
(f.actions.calculate, f.actions.scripts.calculate)
}
/// What each multi-line box on the tab holds.
/// The Calculate tab's box for a formula in simplified field notation.
const NOTATION: &str = "Simplified field notation:";
/// The Actions tab's box for a Run a JavaScript action's script.
const ACTION_SCRIPT: &str = "Script:";
/// What each multi-line box labelled `label` holds.
fn boxes(h: &Harness<'static, PdfCraftApp>, label: &str) -> Vec<String> {
h.query_all_by_role_and_label(Role::MultilineTextInput, label).filter_map(|n| n.value()).collect()
}
/// What each custom calculation script box on the tab holds.
fn script_boxes(h: &Harness<'static, PdfCraftApp>) -> Vec<String> {
h.query_all_by_role_and_label(Role::MultilineTextInput, CUSTOM).filter_map(|n| n.value()).collect()
boxes(h, CUSTOM)
}
/// The script box's description: what a screen reader says about it besides its text.
@@ -393,15 +403,20 @@ fn script_box_description(h: &Harness<'static, PdfCraftApp>) -> Option<String> {
h.get_by_role_and_label(Role::MultilineTextInput, CUSTOM).accesskit_node().description()
}
/// Selects everything in the script box and types `text` over it.
fn retype_script(h: &mut Harness<'static, PdfCraftApp>, text: &str) {
h.get_by_role_and_label(Role::MultilineTextInput, CUSTOM).click();
/// Selects everything in the multi-line box labelled `label` and types `text` over it.
fn retype_box(h: &mut Harness<'static, PdfCraftApp>, label: &str, text: &str) {
h.get_by_role_and_label(Role::MultilineTextInput, label).click();
h.run_steps(1);
h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);
h.get_by_role_and_label(Role::MultilineTextInput, CUSTOM).type_text(text);
h.get_by_role_and_label(Role::MultilineTextInput, label).type_text(text);
h.run_steps(2);
}
/// Selects everything in the custom calculation script box and types `text` over it.
fn retype_script(h: &mut Harness<'static, PdfCraftApp>, text: &str) {
retype_box(h, CUSTOM, text);
}
/// Pastes `text` into the script box where its cursor is.
fn paste_script(h: &mut Harness<'static, PdfCraftApp>, text: &str) {
h.get_by_role_and_label(Role::MultilineTextInput, CUSTOM).click();
@@ -563,8 +578,8 @@ fn renaming_a_field_says_how_many_calculations_now_use_the_new_name() {
h.run_steps(3);
};
open_calculate(&mut h, "city");
choose(&mut h, "Simplified field notation:");
retype_script(&mut h, "name * 2");
choose(&mut h, NOTATION);
retype_box(&mut h, NOTATION, "name * 2");
h.get_by_label("OK").click();
h.run_steps(3);
let calculation = |h: &Harness<'static, PdfCraftApp>| {
@@ -1121,7 +1136,7 @@ fn add_action(h: &mut Harness<'static, PdfCraftApp>, trigger: &str, kind: &str,
pick(h, "Select Trigger:", trigger);
pick(h, "Select Action:", kind);
if kind == "Run a JavaScript" {
retype_script(h, text);
retype_box(h, ACTION_SCRIPT, text);
} else {
retype(h, "Value:", text);
}
@@ -1182,8 +1197,8 @@ fn actions_tab_edits_the_script_of_an_existing_action() {
h.get_all_by_label("Edit").last().unwrap().click();
h.run_steps(2);
h.get_by_label("Edit Action");
assert_eq!(script_boxes(&h), [script]);
retype_script(&mut h, "app.alert('changed');");
assert_eq!(boxes(&h, ACTION_SCRIPT), [script]);
retype_box(&mut h, ACTION_SCRIPT, "app.alert('changed');");
h.get_by_label("Discard").click();
h.run_steps(2);
h.get_by_label("Add an Action");
@@ -1194,7 +1209,7 @@ fn actions_tab_edits_the_script_of_an_existing_action() {
open(&mut h);
h.get_all_by_label("Edit").last().unwrap().click();
h.run_steps(2);
retype_script(&mut h, "app.alert('changed');");
retype_box(&mut h, ACTION_SCRIPT, "app.alert('changed');");
h.get_by_label("Update").click();
h.run_steps(2);
h.get_by_label("OK").click();
@@ -1702,7 +1717,7 @@ fn a_loop_has_its_own_card_that_opens_the_formula() {
h.run_steps(3);
// Field Properties of a is open on the Calculate tab, which shows a's formula.
assert!(props_open(&h));
assert_eq!(script_boxes(&h), ["b + 1"]);
assert_eq!(boxes(&h, NOTATION), ["b + 1"]);
}
/// A radio group `shirt` of three buttons, S, M and L, with L chosen, while preparing the form.
@@ -1863,16 +1878,16 @@ fn a_notation_that_cannot_be_stored_keeps_field_properties_open() {
assert!(props_open(&h), "Field Properties is open");
retype(&mut h, "Tooltip:", "Subtotal");
tab(&mut h, "Calculate");
retype_script(&mut h, "qty EVCALC 2");
retype_box(&mut h, NOTATION, "qty EVCALC 2");
h.get_by_label("OK").click();
h.run_steps(3);
assert!(props_open(&h), "the dialog stays open");
assert_eq!(script_boxes(&h), ["qty EVCALC 2"], "as typed");
assert_eq!(boxes(&h, NOTATION), ["qty EVCALC 2"], "as typed");
tab(&mut h, "General");
assert_eq!(text_of(&h, "Tooltip:").as_deref(), Some("Subtotal"), "as typed");
assert_eq!(formula(&h), Calculate::Notation("qty * 2".into()), "the field keeps its formula");
tab(&mut h, "Calculate");
retype_script(&mut h, "qty * 3");
retype_box(&mut h, NOTATION, "qty * 3");
h.get_by_label("OK").click();
h.run_steps(3);
assert!(!props_open(&h), "applied and closed");
@@ -1927,7 +1942,7 @@ fn a_formula_reading_a_missing_field_has_its_own_card() {
h.run_steps(3);
// Field Properties of sub is open on the Calculate tab, which shows sub's formula.
assert!(props_open(&h));
assert_eq!(script_boxes(&h), ["qty - discount"]);
assert_eq!(boxes(&h, NOTATION), ["qty - discount"]);
}
#[test]
+9 -10
View File
@@ -377,7 +377,8 @@ fn print_dialog_prints_the_selected_pages() {
fn invalid_ranges_are_explained_in_the_preview() {
let mut h = harness();
h.open();
h.state_mut().print_draft.which = pdfcraft_ui_egui::PrintWhich::Range;
// The Pages box takes typing once its choice is picked, as in the dialog's row.
h.set("which", json!("range"));
h.set("range", json!("7"));
assert!(h.state().print_draft.settings(1, &[]).is_err(), "page 7 of a one-page document is out of range");
assert!(h.has_note("note.range"), "the preview says why"); // PLAN: assumed key
@@ -404,12 +405,12 @@ fn cut_stack_dialog_previews_saves_and_refuses_duplex() {
h.get_by_label("›").click();
h.run_steps(2);
assert_eq!(h.pager(), (2, 3));
h.state_mut().print_draft.duplex = Some(Duplex::LongEdge);
h.run_steps(2);
h.set("duplex", json!("long_edge"));
assert_eq!(h.state().print_draft.duplex, Some(Duplex::LongEdge));
assert!(h.has_note("note.duplex"));
let ctx_h = h.ctx.clone();
assert!(h.state_mut().print_now(&ctx_h).is_err());
h.state_mut().print_draft.duplex = Some(Duplex::Off);
h.set("duplex", json!("off"));
h.pick(None);
h.ok();
assert!(!h.is_open());
@@ -1428,8 +1429,8 @@ fn a_booklet_decides_two_sided_itself() {
h.open();
h.settle();
assert_eq!(h.destination(), Destination::Printer("Laser".into()));
h.state_mut().print_draft.duplex = Some(Duplex::LongEdge);
h.run_steps(1);
// Two-sided is the dialog's own setting, which the draft follows each pass.
h.set("duplex", json!("long_edge"));
h.state_mut().print_draft.set_handling(PrintHandling::Booklet);
h.run_steps(2);
let d = &h.state().print_draft;
@@ -1673,9 +1674,8 @@ fn each_printer_keeps_what_it_last_printed_with_across_a_restart() {
let d = &mut h.state_mut().print_draft;
d.paper = LABEL_PAPER;
d.size = SizeMode::Actual;
d.duplex = Some(Duplex::Off);
}
h.run_steps(2);
h.set("duplex", json!("off"));
assert_eq!(print(&mut h).printer.as_deref(), Some("D520BT_Z"));
h.reopen();
h.pick(Some("Office"));
@@ -1683,9 +1683,8 @@ fn each_printer_keeps_what_it_last_printed_with_across_a_restart() {
let d = &mut h.state_mut().print_draft;
d.paper = a4;
d.size = SizeMode::Fit;
d.duplex = Some(Duplex::LongEdge);
}
h.run_steps(2);
h.set("duplex", json!("long_edge"));
assert_eq!(print(&mut h).printer.as_deref(), Some("Office"));
// Choosing the label printer in the dialog brings back what it printed with.
+12 -4
View File
@@ -31,7 +31,9 @@ fn pending_pages_use_document_reading_background() {
let id = app.views[0].id;
// Deliberately differ from the app preference: the document is the source of truth.
app.session.set_reading_colors(id, colors);
// The page view runs on the framework's runtime, which knows its commands' scopes.
let ctx = Context::default();
crate::support::install_runtime(&ctx);
for page in 0..3 {
app.views[0].go_to_page(page);
// Draw the real canvas without finishing the render frame, so no texture can
@@ -55,6 +57,14 @@ fn pending_pages_use_document_reading_background() {
}
}
/// Picks `option` in the Appearance page's Reading colours row, a select whose options show once it is opened.
fn pick_reading_colours(h: &mut Harness<'static, PdfCraftApp>, option: &str) {
h.get_by_role_and_label(egui::accesskit::Role::ComboBox, "Reading colours").click();
h.run_steps(3);
h.get_all_by_label(option).last().unwrap_or_else(|| panic!("the {option:?} option is on screen")).click();
h.run_steps(3);
}
/// A small PNG for the Create ▸ Images path, which opens the document it builds.
fn png() -> Vec<u8> {
let img = craft_image_codecs::Image::from_u8(8, 4, craft_image_codecs::ChannelLayout::Rgb, vec![120u8; 8 * 4 * 3]).unwrap();
@@ -77,8 +87,7 @@ fn reading_colours_preference_round_trips() {
assert_eq!(h.state().reading_colors, ReadingColors::default());
h.get_by_label("Appearance").click();
h.run_steps(3);
h.get_by_label("White on black").click();
h.run_steps(3);
pick_reading_colours(&mut h, "White on black");
assert_eq!(h.state().reading_colors, ReadingColors::default(), "a row edits the draft, not the app");
h.get_by_label("OK").click();
h.run_steps(3);
@@ -129,8 +138,7 @@ fn reading_presets_follow_appearance_and_do_not_change_the_interface_theme() {
("Black on white", ReadingColors::BLACK_ON_WHITE),
("Off", ReadingColors::default()),
] {
h.get_by_label(label).click();
h.run_steps(3);
pick_reading_colours(&mut h, label);
h.get_by_label("OK").click();
h.run_steps(3);
assert_eq!(h.state().reading_colors, expected);
+44 -15
View File
@@ -658,6 +658,8 @@ fn preferences_turn_on_always_use_my_default_zoom_and_page_layout_updates_open_d
let ctx_h = h.ctx.clone();
h.state_mut().open_bytes(&ctx_h, "second.pdf", None, PAGES.to_vec()).expect("opens");
h.state_mut().views[1].view.continuous = false;
// A fixed zoom: no fit, at 75%.
h.state_mut().views[1].view.fit = pdfcraft_ui_egui::canvas::Fit::None;
h.state_mut().views[1].view.zoom = 0.75;
assert_eq!(h.state().views.len(), 2);
assert!(!h.state().views[0].continuous());
@@ -698,7 +700,9 @@ fn preferences_during_full_screen_updates_saved_normal_display_and_restores_on_e
assert_eq!(v0.fit(), Fit::None);
assert_eq!(v0.zoom(), 0.5);
h.state_mut().views[0].enter_presentation();
// Every view follows the window's screen mode: full screen presents it.
h.state_mut().set_full_screen(true);
h.run_steps(3);
assert!(h.state().views[0].presenting());
assert!(!h.state().views[0].continuous());
assert_eq!(h.state().views[0].fit(), Fit::Page);
@@ -717,7 +721,8 @@ fn preferences_during_full_screen_updates_saved_normal_display_and_restores_on_e
assert_eq!(v.normal_display().fit, Fit::Width, "saved normal display updated to default fit width");
}
h.state_mut().views[0].leave_presentation();
h.state_mut().set_full_screen(false);
h.run_steps(3);
{
let v = &h.state().views[0];
assert!(!v.presenting());
@@ -734,7 +739,9 @@ fn preferences_toggle_continuous_during_full_screen_updates_saved_normal_display
let mut h = harness(&[("default-continuous", "off"), ("continuous", "off")]);
assert!(!h.state().views[0].continuous());
h.state_mut().views[0].enter_presentation();
// Every view follows the window's screen mode: full screen presents it.
h.state_mut().set_full_screen(true);
h.run_steps(3);
assert!(h.state().views[0].presenting());
assert!(!h.state().views[0].continuous());
assert_eq!(h.state().views[0].fit(), Fit::Page);
@@ -752,7 +759,8 @@ fn preferences_toggle_continuous_during_full_screen_updates_saved_normal_display
assert!(v.normal_display().continuous, "saved normal display updated to continuous");
}
h.state_mut().views[0].leave_presentation();
h.state_mut().set_full_screen(false);
h.run_steps(3);
{
let v = &h.state().views[0];
assert!(!v.presenting());
@@ -1163,6 +1171,24 @@ const LOCKED: &[u8] = b"%PDF-1.7
trailer << /Root 1 0 R >>
%%EOF";
/// How many filled shapes of the frame cover the widget at `pdf` (user space, y up) on page 1 of
/// 300×400: a rectangle over its box, or a circle round its centre.
fn tints_over(h: &Harness<'static, PdfCraftApp>, pdf: [f32; 4]) -> usize {
let r = rect(h, 0).expect("page 1 on screen");
let to = |x: f32, y: f32| egui::pos2(r.min.x + r.width() * x / 300.0, r.min.y + r.height() * (1.0 - y / 400.0));
let want = egui::Rect::from_two_pos(to(pdf[0], pdf[1]), to(pdf[2], pdf[3]));
let near = |a: egui::Pos2, b: egui::Pos2| (a - b).length() < 1.0;
h.output()
.shapes
.iter()
.filter(|c| match &c.shape {
egui::Shape::Rect(s) => s.fill.a() > 0 && near(s.rect.min, want.min) && near(s.rect.max, want.max),
egui::Shape::Circle(s) => s.fill.a() > 0 && near(s.center, want.center()),
_ => false,
})
.count()
}
/// Highlight fields marks the fields that can be filled: a read-only one (a form's locked
/// box, or one its scripts have not opened yet) is left as it is drawn, as in Acrobat.
#[test]
@@ -1180,9 +1206,8 @@ fn highlight_fields_leaves_read_only_fields_alone() {
}
});
h.run_steps(6);
let tint = egui::Color32::from_rgba_unmultiplied(0x6E, 0x8E, 0xF5, 48);
let tinted = h.output().shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Rect(r) if r.fill == tint)).count();
assert_eq!(tinted, 1, "only the field that can be filled is tinted");
assert_eq!(tints_over(&h, [50.0, 300.0, 250.0, 330.0]), 1, "the field that can be filled is tinted");
assert_eq!(tints_over(&h, [50.0, 200.0, 250.0, 230.0]), 0, "the read-only field is left as drawn");
}
/// A radio group whose second button is locked on its own widget (`/Ff` 1 there), as the
@@ -1214,9 +1239,8 @@ fn highlight_fields_leaves_a_groups_read_only_button_alone() {
}
});
h.run_steps(6);
let tint = egui::Color32::from_rgba_unmultiplied(0x6E, 0x8E, 0xF5, 48);
let tinted = h.output().shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Circle(r) if r.fill == tint)).count();
assert_eq!(tinted, 1, "only the button that can be chosen is tinted");
assert_eq!(tints_over(&h, [50.0, 300.0, 90.0, 340.0]), 1, "the button that can be chosen is tinted");
assert_eq!(tints_over(&h, [150.0, 300.0, 190.0, 340.0]), 0, "the read-only button is left as drawn");
}
/// A push button and a text field, with fields highlighted.
@@ -1246,9 +1270,8 @@ fn highlight_fields_leaves_push_buttons_alone() {
}
});
h.run_steps(6);
let tint = egui::Color32::from_rgba_unmultiplied(0x6E, 0x8E, 0xF5, 48);
let tinted = h.output().shapes.iter().filter(|c| matches!(&c.shape, egui::Shape::Rect(r) if r.fill == tint)).count();
assert_eq!(tinted, 1, "only the text field is tinted");
assert_eq!(tints_over(&h, [50.0, 100.0, 250.0, 130.0]), 1, "the text field is tinted");
assert_eq!(tints_over(&h, [50.0, 200.0, 250.0, 340.0]), 0, "the push button is left as drawn");
}
/// A page whose open action starts an interval writing a counter into the console.
@@ -2073,13 +2096,18 @@ fn long_view_menu_fits_a_short_window() {
assert!(h.state().dock.layout.contains(&pdfcraft_ui_egui::side_panels::PanelId::Bookmarks), "the Bookmarks panel is open in the dock");
}
/// A click at `pos` with `modifiers` held, reported as the platform does: the held keys first,
/// then the press and release, then the keys let go.
fn click_with(h: &mut Harness<'static, PdfCraftApp>, pos: egui::Pos2, modifiers: Modifiers) {
h.hover_at(pos);
h.event(egui::Event::ModifiersChanged(modifiers));
h.run_steps(1);
for pressed in [true, false] {
h.event(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers });
}
h.run_steps(4);
h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
h.run_steps(1);
}
/// Full screen is Acrobat's Full Screen Mode (#379, #1459): one page at a time, fitted to the
@@ -2101,7 +2129,8 @@ fn full_screen_shows_one_fitted_page_and_clicks_turn_it() {
let r = rect(&h, 0).unwrap();
let vp = h.state().views[0].viewport_rect();
assert!(r.height() <= vp.height() + 1.0 && r.width() <= vp.width() + 1.0, "the page fits: {r:?} in {vp:?}");
assert!(h.query_by_label("Select (V)").is_none(), "no quick tools in full screen");
// The Select tool's button is named by its command; V is its shortcut, not part of its name.
assert!(h.query_all_by_label("Select").next().is_none(), "no quick tools in full screen");
click_with(&mut h, r.center(), Modifiers::NONE);
assert_eq!(h.state().views[0].current(), 1, "a click goes forward a page");
h.key_press(Key::ArrowRight);
@@ -2125,7 +2154,7 @@ fn full_screen_shows_one_fitted_page_and_clicks_turn_it() {
assert!((v.zoom() - 0.5).abs() < 1e-3, "zoom back to 50%: {}", v.zoom());
assert_eq!(v.current(), 1, "at the page reached in full screen");
h.run_steps(2);
assert!(h.query_by_label("Select (V)").is_some(), "the quick tools are back");
assert!(h.query_all_by_label("Select").next().is_some(), "the quick tools are back");
}
/// #2070 review: full screen survives the file being reloaded (Esc still brings the display from