mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-27 03:27:21 -06:00
This commit is contained in:
@@ -753,7 +753,15 @@ pub fn right_rail(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
view.view_history(forward);
|
||||
}
|
||||
}
|
||||
ui.label(egui::RichText::new(page_count.to_string()).font(theme::regular(11.0)).color(t.text_muted));
|
||||
let font = theme::regular(11.0);
|
||||
let mut position = page_position(view.current, page_count, labels.get(view.current).map_or("", String::as_str));
|
||||
if widgets::text_width(ui, &position, &font) > ui.available_width() {
|
||||
position = page_count.to_string();
|
||||
}
|
||||
// Out of range (an empty document), like `page_position`: "Page 0 of 0", never past the end.
|
||||
let shown = if view.current < page_count { view.current + 1 } else { page_count };
|
||||
let of = crate::i18n::fmt(tl!("Page {p} of {n}"), &[("p", &shown.to_string()), ("n", &page_count.to_string())]);
|
||||
ui.label(egui::RichText::new(position).font(font).color(t.text_muted)).on_hover_text(of);
|
||||
let page_input_id = view.page_input_id();
|
||||
// Consume replacement selection once, including when the editor has lost focus.
|
||||
let reselect = std::mem::take(&mut view.page_input_reselect);
|
||||
@@ -795,6 +803,13 @@ pub fn right_rail(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
|
||||
});
|
||||
}
|
||||
|
||||
/// What the rail shows under the page box: the page count, or, when the current page's label is
|
||||
/// not its physical number (front matter numbered i, ii, …), its position as "3/180" (#2834).
|
||||
fn page_position(current: usize, count: usize, label: &str) -> String {
|
||||
let number = current.saturating_add(1).to_string();
|
||||
if label.is_empty() || label == number || current >= count { count.to_string() } else { format!("{number}/{count}") }
|
||||
}
|
||||
|
||||
/// View ▸ Page display and the rail's Page display menu: the layouts and the cover page.
|
||||
/// Returns the command a click asks for, for the caller to run.
|
||||
fn page_display_menu(ui: &mut egui::Ui, view: &DocView) -> Option<&'static str> {
|
||||
@@ -857,6 +872,21 @@ fn rail_view_menu(ui: &mut egui::Ui, view: &mut DocView) -> Option<&'static str>
|
||||
picked
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod page_position_tests {
|
||||
use super::page_position;
|
||||
|
||||
#[test]
|
||||
fn position_shows_only_when_the_label_is_not_the_page_number() {
|
||||
assert_eq!(page_position(0, 180, "i"), "1/180");
|
||||
assert_eq!(page_position(2, 180, "1"), "3/180");
|
||||
assert_eq!(page_position(2, 180, "3"), "180");
|
||||
assert_eq!(page_position(2, 180, ""), "180");
|
||||
assert_eq!(page_position(0, 0, "i"), "0");
|
||||
assert_eq!(page_position(usize::MAX, 3, "x"), "3");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tab_widths {
|
||||
use super::{MAC_CONTENT_LEFT, MAC_LIGHT, MAC_LIGHT_PITCH, MAC_LIGHTS_LEFT, MAC_TITLE_BAR, tab_cap};
|
||||
|
||||
@@ -330,6 +330,9 @@ fn layouts_fit_height_labels_and_system_theme() {
|
||||
assert_eq!(labels[1], "ii");
|
||||
assert!(h.state_mut().views[0].go_to_typed("ii", &labels));
|
||||
assert_eq!(h.state().views[0].current, 1);
|
||||
// Under the box, the physical position, since "ii" does not say which page it is (#2834).
|
||||
h.run_steps(2);
|
||||
h.get(By::new().label(&format!("2/{}", labels.len())));
|
||||
assert!(!h.state_mut().views[0].go_to_typed("xx", &labels));
|
||||
// Follow the system theme.
|
||||
h.state_mut().set_option("theme", "system").unwrap();
|
||||
|
||||
@@ -1155,7 +1155,7 @@ status = "shipped"
|
||||
commands = []
|
||||
tools = []
|
||||
evidence = ["crates/ui-egui/tests/viewer.rs::layouts_fit_height_labels_and_system_theme"]
|
||||
notes = "the page box takes labels (iv, A-1) before numbers"
|
||||
notes = "the page box shows the current page's label and takes labels (iv, A-1) before numbers; where the label is not the page number the rail shows the physical position under it (3/180, dropped to the page count when it does not fit). Not yet: a preference to show physical numbers only, and labels in the organize bar's Page n of m"
|
||||
|
||||
[[feature]]
|
||||
id = "view.view-history"
|
||||
|
||||
Reference in New Issue
Block a user