mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-27 19:48:14 -06:00
M7: Let the page range select page 1 alone
Seitenbereich „1 bis 1“ springt nicht mehr auf die letzte Seite zurück.
This commit is contained in:
@@ -28,8 +28,10 @@ pub struct PageRange {
|
||||
}
|
||||
|
||||
impl Default for PageRange {
|
||||
/// From the first page to the last: `to` starts past any page count, and the range field
|
||||
/// shows (and clamps it to) the document's last page.
|
||||
fn default() -> Self {
|
||||
Self { all: true, from: 1, to: 1, subset: Subset::All }
|
||||
Self { all: true, from: 1, to: usize::MAX, subset: Subset::All }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +55,6 @@ impl PageRange {
|
||||
widgets::radio_value(ui, &mut self.all, false, tl!("Pages from"));
|
||||
ui.add_enabled(!self.all, egui::DragValue::new(&mut self.from).range(1..=count.max(1)));
|
||||
ui.label(tl!("to"));
|
||||
if self.to == 1 && self.from == 1 {
|
||||
self.to = count.max(1);
|
||||
}
|
||||
ui.add_enabled(!self.all, egui::DragValue::new(&mut self.to).range(1..=count.max(1)));
|
||||
ui.label(tl!("Subset"));
|
||||
let label = match self.subset {
|
||||
@@ -519,6 +518,11 @@ mod tests {
|
||||
assert_eq!(r.pages(6), [1, 3, 5]);
|
||||
let r = PageRange { all: true, subset: Subset::Odd, ..PageRange::default() };
|
||||
assert_eq!(r.pages(5), [0, 2, 4]);
|
||||
// Not all pages: by default up to the last one; a single page is a range too.
|
||||
let r = PageRange { all: false, ..PageRange::default() };
|
||||
assert_eq!(r.pages(4), [0, 1, 2, 3]);
|
||||
let r = PageRange { all: false, from: 1, to: 1, subset: Subset::All };
|
||||
assert_eq!(r.pages(38), [0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -96,3 +96,37 @@ fn backgrounds_and_watermarks_from_a_file() {
|
||||
let s = h.state();
|
||||
assert_eq!(s.session.get(s.views[0].id).unwrap().can_undo(), Some("Add background"));
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[test]
|
||||
fn page_range_from_one_to_one_selects_only_the_first_page() {
|
||||
let mut h = harness();
|
||||
h.state_mut().execute("edit.background");
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().marks_draft.range.pages(3), [0, 1, 2]);
|
||||
h.get_by_label("Pages from").click();
|
||||
h.run_steps(2);
|
||||
let range = h.state().marks_draft.range;
|
||||
assert_eq!((range.from, range.to), (1, 3), "from the first page to the last");
|
||||
h.state_mut().marks_draft.range.to = 1;
|
||||
h.run_steps(3);
|
||||
let range = h.state().marks_draft.range;
|
||||
assert_eq!((range.from, range.to), (1, 1), "the range stays as typed");
|
||||
h.get_by_label("Applies to 1 page");
|
||||
h.get_by_label("OK").click();
|
||||
h.run_steps(3);
|
||||
let s = h.state();
|
||||
let doc = s.session.get(s.views[0].id).unwrap();
|
||||
assert_eq!(doc.marks(), [MarkKind::Background]);
|
||||
// Rendered: page 1 has the (default cream) background, page 2 is still blank.
|
||||
let mut r = pdfcraft_render::PageRenderer::new(doc.bytes.clone(), pdfcraft_render::RenderConfig::default());
|
||||
let corner = |r: &mut pdfcraft_render::PageRenderer, page: usize| {
|
||||
let p = r.render(pdfcraft_render::RenderRequest { page, scale: 1.0, ..Default::default() });
|
||||
assert!(p.error.is_none(), "{:?}", p.error);
|
||||
p.rgba[..4].to_vec()
|
||||
};
|
||||
assert_eq!(corner(&mut r, 0), vec![255, 255, 217, 255], "page 1 has the background");
|
||||
assert_eq!(corner(&mut r, 1), vec![255, 255, 255, 255], "page 2 does not");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user