Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into fix/background-hidden-by-page-backdrop

alehelc11946763bda
diff --cc crates/ui-egui/src/commands.rs
index 909c97628,c0e12d5d0..78f50b49d
--- a/crates/ui-egui/src/commands.rs
+++ b/crates/ui-egui/src/commands.rs
@@@ -390,7 -390,7 +390,8 @@@ impl PdfCraftApp
K::Background
};
self.marks_draft.replace = id.ends_with(".update");
+ self.marks_draft.opened(kind);
+ self.marks_draft.preview = None;
self.dialog = Some(Dialog::Marks(kind));
}
"edit.bates" => {
diff --cc crates/ui-egui/src/marks_ui.rs
index b5f2d5bf2,fbca7bb08..b4c930e62
--- a/crates/ui-egui/src/marks_ui.rs
+++ b/crates/ui-egui/src/marks_ui.rs
@@@ -4,10 -4,10 +4,10 @@@
//! replace mode.
use egui::{Align, Color32, CornerRadius, Layout, Rect, Stroke, pos2, vec2};
-use pdfcraft_engine::{Background, Edit, FontFamily, HeaderFooter, MarkKind, Watermark};
+use pdfcraft_engine::{Backdrop, Background, DocId, Edit, FontFamily, HeaderFooter, MarkKind, Watermark};
use crate::theme::{self, Tokens};
- use crate::{PdfCraftApp, widgets};
+ use crate::{PdfCraftApp, icons, widgets};
/// How far a watermark may be moved from the page centre, in points.
const MAX_OFFSET: f64 = 20_000.0;
@@@ -197,8 -90,9 +197,11 @@@ pub struct MarksDraft
pub use_file: bool,
pub file: Option<(String, std::sync::Arc<Vec<u8>>)>,
pub file_page: usize,
+ /// Background: pages that paint their own backdrop.
+ pub backdrops: BackdropCheck,
+ /// The page (0-based) the preview was stepped to; `None` previews the current page. Reset
+ /// each time the dialog opens.
+ pub preview: Option<usize>,
}
impl Default for MarksDraft {
@@@ -216,7 -110,7 +219,8 @@@
use_file: false,
file: None,
file_page: 1,
+ backdrops: BackdropCheck::default(),
+ preview: None,
}
}
}
diff --cc crates/ui-egui/tests/it/marks.rs
index 626513f30,886131011..2c8b39d55
--- a/crates/ui-egui/tests/it/marks.rs
+++ b/crates/ui-egui/tests/it/marks.rs
@@@ -368,10 -262,38 +368,39 @@@ fn the_preview_shows_the_page_the_range
assert!(h.state_mut().execute("edit.background"));
h.run_steps(2);
let (_, _, tint) = wait_for_picture(&mut h, 1);
- assert_eq!(tint, egui::Color32::from_rgb(255, 255, 217), "the default pale yellow, opaque");
+ let [red, green, blue] = pdfcraft_engine::Background::default().color.map(|c| (c * 255.0).round() as u8);
+ assert_eq!(tint, egui::Color32::from_rgb(red, green, blue), "the default background colour, opaque");
}
+ /// The preview's page stepper, beside its "page N of M" label: the dialog's own button, not the
+ /// page navigation's of the same name.
+ fn preview_step(h: &mut Harness<'static, PdfCraftApp>, label: &str, now: &str) {
+ let row = h.get_by_label(now).rect().center().y;
+ h.query_all_by_label(label).find(|n| (n.rect().center().y - row).abs() < 15.0).unwrap_or_else(|| panic!("{label} beside {now:?}")).click();
+ h.run_steps(2);
+ }
+
+ #[test]
+ fn the_preview_steps_through_the_pages_and_starts_at_the_current_one() {
+ let mut h = harness();
+ h.state_mut().views[0].go_to_page(1);
+ h.run_steps(2);
+ assert!(h.state_mut().execute("edit.watermark"));
+ h.run_steps(2);
+ h.get_by_label("Preview: page 2 of 3");
+ preview_step(&mut h, "Next page", "Preview: page 2 of 3");
+ h.get_by_label("Preview: page 3 of 3");
+ preview_step(&mut h, "Previous page", "Preview: page 3 of 3");
+ preview_step(&mut h, "Previous page", "Preview: page 2 of 3");
+ h.get_by_label("Preview: page 1 of 3");
+ // Opened again, the preview is back at the current page.
+ h.get_by_label("Cancel").click();
+ h.run_steps(2);
+ assert!(h.state_mut().execute("edit.watermark"));
+ h.run_steps(2);
+ h.get_by_label("Preview: page 2 of 3");
+ }
+
/// Pages from 1 to 1 stays one page: the dialog used to turn "to" back into the last page on
/// every frame while both were 1, so only page 1 could not be chosen alone. The field starts on
/// the last page.