Skip to content

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

fix(ui): use the shared rail viewport fix (#5677)

FredAppsd35be6fdac56
diff --git a/Cargo.lock b/Cargo.lock
index ccf080b27..78d058dcb 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1178,17 +1178,17 @@ dependencies = [
[[package]]
name = "craft-docpath"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
[[package]]
name = "craft-i18n"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"fixed_decimal",
"icu_decimal",
@@ -1211,7 +1211,7 @@ dependencies = [
[[package]]
name = "craft-keymap"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"egui",
"serde",
@@ -1221,7 +1221,7 @@ dependencies = [
[[package]]
name = "craft-menu"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"craft-keymap",
"craft-quit",
@@ -1234,7 +1234,7 @@ dependencies = [
[[package]]
name = "craft-print"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"craft-winprint-gdi",
"log",
@@ -1248,7 +1248,7 @@ dependencies = [
[[package]]
name = "craft-quit"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"dispatch2",
"egui",
@@ -1259,7 +1259,7 @@ dependencies = [
[[package]]
name = "craft-ui"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"craft-fonts-build",
"craft-i18n",
@@ -1280,7 +1280,7 @@ dependencies = [
[[package]]
name = "craft-update"
version = "0.1.0"
-source = "git+https://github.com/storytold/craft-libs?rev=c5a1cbfb5f9049f9270955caffb5bee5997aebf7#c5a1cbfb5f9049f9270955caffb5bee5997aebf7"
+source = "git+https://github.com/storytold/craft-libs?rev=787a7a0f972fd1d7a7618fdbeca3a5267a0407ff#787a7a0f972fd1d7a7618fdbeca3a5267a0407ff"
dependencies = [
"chrono",
"dunce",
diff --git a/Cargo.toml b/Cargo.toml
index c9db94b27..edd9e682b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,18 +13,18 @@ repository = "https://github.com/storytold/pdfcraft"
[workspace.dependencies]
# Shared frontend components; engines remain independent of egui.
-craft-ui = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["serde"] }
+craft-ui = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff", features = ["serde"] }
# Quit the macOS way (#1136): ⌘Q asks about unsaved changes, and closing quits through `terminate:`.
-craft-quit = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
+craft-quit = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff" }
# One menu definition for the native macOS menu bar and the in-window bar elsewhere.
-craft-menu = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
-craft-keymap = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", default-features = false }
+craft-menu = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff" }
+craft-keymap = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff", default-features = false }
# Shared system spooler; document composition remains in pdfcraft-print.
-craft-print = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
+craft-print = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff" }
# Whether a path stored in a document may be opened (GoToR link targets).
-craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
+craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
-craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["egui"] }
+craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "787a7a0f972fd1d7a7618fdbeca3a5267a0407ff", features = ["egui"] }
# internal
pdfcraft-geom = { path = "crates/geom", version = "0.17.0" }
pdfcraft-filters = { path = "crates/filters", version = "0.17.0" }
diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs
index 5be9ee506..59525aae7 100644
--- a/crates/ui-egui/src/chrome.rs
+++ b/crates/ui-egui/src/chrome.rs
@@ -577,72 +577,40 @@ pub fn right_rail(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
.show(ui, &items, app.right.as_ref(), |ui| {
// Page navigation cluster at the bottom, a panel of its own so that in a short
// window the buttons above scroll instead of running into it (#3282).
- // Let the footer measure its natural height from the top. A bottom-up child can
- // grow above the auto-sized panel's origin without reserving that space for the
- // scrolling items, especially with the extra docking button.
- ui.with_layout(Layout::top_down(Align::Center), |ui| {
+ ui.with_layout(Layout::bottom_up(Align::Center), |ui| {
ui.spacing_mut().item_spacing.y = 2.0;
- 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);
- // Navigation updates the idle display, never the text being edited.
- if !ui.memory(|m| m.has_focus(page_input_id)) {
- view.page_input = view.current_page_label(labels.get(view.current).map(String::as_str));
- } else if reselect {
- // The replacement changed the label while egui retained this editor's cursor.
- let mut state = egui::TextEdit::load_state(ui.ctx(), page_input_id).unwrap_or_default();
- let end = egui::text::CCursor::new(view.page_input.chars().count());
- state.cursor.set_char_range(Some(egui::text::CCursorRange::two(egui::text::CCursor::new(0), end)));
- state.store(ui.ctx(), page_input_id);
- }
- let edit = egui::TextEdit::singleline(&mut view.page_input)
- .id(page_input_id)
- .desired_width(34.0)
- .align(egui::Align2::CENTER_TOP)
- .font(theme::medium(12.0))
- .margin(vec2(2.0, 4.0));
- let r = egui::Frame::NONE
- .fill(t.field)
- .stroke(Stroke::new(1.0, t.border))
- .corner_radius(CornerRadius::same(5))
- .show(ui, |ui| ui.add(edit))
- .inner
- .on_hover_text(tl!("Current page — type a page number or label (such as iv) and press Enter"))
- .accessible_name(tl!("Current page"));
- if r.lost_focus() {
- if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
- // A page label first (logical page numbers, as Acrobat), then a number.
- let typed = view.page_input.clone();
- view.go_to_typed(&typed, &labels);
- }
- view.page_input = view.current_page_label(labels.get(view.current).map(String::as_str));
+ let right = app.side_panels.rail_on_right();
+ let dock_tip = if right { tl!("Dock navigation rail on Left") } else { tl!("Dock navigation rail on Right") };
+ if icons::button(ui, if right { "panel-left" } else { "panel-right" }, 32.0, false, dock_tip).clicked() {
+ app.side_panels.rail_side = if right { crate::side_panels::ToolsSide::Left } else { crate::side_panels::ToolsSide::Right };
}
- 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();
+ let tip = crate::commands::key_tip(ui.ctx(), tl!("Zoom out ({key})"), crate::commands::ZOOM_OUT);
+ if icons::button(ui, "zoom-out", 32.0, false, &tip).clicked() {
+ view.zoom_step(false);
}
- // 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);
- // History is distinct from stepping to the adjacent page, and belongs to this tab.
- for (forward, icon, label, shortcut, enabled) in [
- (false, "chevron-left", tl!("Previous view"), crate::commands::PREV_VIEW, !view.back.is_empty()),
- (true, "chevron-right", tl!("Next view"), crate::commands::NEXT_VIEW, !view.forward.is_empty()),
- ] {
- let tip = format!("{label} ({})", crate::commands::shortcut_label(ui.ctx(), shortcut));
- if ui.add_enabled_ui(enabled, |ui| icons::button(ui, icon, 30.0, false, &tip)).inner.clicked() {
- view.view_history(forward);
- }
+ let tip = crate::commands::key_tip(ui.ctx(), tl!("Zoom in ({key})"), crate::commands::ZOOM_IN);
+ if icons::button(ui, "zoom-in", 32.0, false, &tip).clicked() {
+ view.zoom_step(true);
}
- if icons::button(ui, "chevron-up", 30.0, false, tl!("Previous page")).clicked() {
- view.step_page(false);
+ // Between rotate and zoom, as in Acrobat. Its command runs once `view` is free.
+ let tip = crate::i18n::fmt(tl!("Page display: {layout}"), &[("layout", tl!(view.layout.label()))]);
+ let resp = icons::button(ui, view.layout.icon(), 32.0, false, &tip);
+ page_display = egui::Popup::menu(&resp)
+ .show(|ui| {
+ ui.set_min_width(220.0);
+ rail_view_menu(ui, view)
+ })
+ .and_then(|r| r.inner);
+ let tip = crate::commands::key_tip(ui.ctx(), tl!("Rotate view clockwise ({key})"), crate::commands::ROTATE_CW);
+ if icons::button(ui, "rotate-cw", 32.0, false, &tip).clicked() {
+ view.rotate_view(true);
}
- if icons::button(ui, "chevron-down", 30.0, false, tl!("Next page")).clicked() {
- view.step_page(true);
+ // Not `columns-2` while fitting the page: that is the two-page view's icon.
+ let fit_icon = if view.fit == Fit::Width { "maximize" } else { "maximize-2" };
+ if icons::button(ui, fit_icon, 32.0, false, tl!("Toggle fit page / fit width")).clicked() {
+ view.fit = if view.fit == Fit::Width { Fit::Page } else { Fit::Width };
+ view.goto = Some((view.current, 0.0));
}
- ui.add_space(6.0);
let id = egui::Id::unique("zoom-input");
let draft = id.with("draft");
let mut typed = ui.data(|d| d.get_temp::<String>(draft)).unwrap_or_else(|| format!("{:.0}%", view.zoom * 100.0));
@@ -673,37 +641,66 @@ pub fn right_rail(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
view.set_zoom(zoom);
}
}
- // Not `columns-2` while fitting the page: that is the two-page view's icon.
- let fit_icon = if view.fit == Fit::Width { "maximize" } else { "maximize-2" };
- if icons::button(ui, fit_icon, 32.0, false, tl!("Toggle fit page / fit width")).clicked() {
- view.fit = if view.fit == Fit::Width { Fit::Page } else { Fit::Width };
- view.goto = Some((view.current, 0.0));
+ ui.add_space(6.0);
+ if icons::button(ui, "chevron-down", 30.0, false, tl!("Next page")).clicked() {
+ view.step_page(true);
}
- let tip = crate::commands::key_tip(ui.ctx(), tl!("Rotate view clockwise ({key})"), crate::commands::ROTATE_CW);
- if icons::button(ui, "rotate-cw", 32.0, false, &tip).clicked() {
- view.rotate_view(true);
+ if icons::button(ui, "chevron-up", 30.0, false, tl!("Previous page")).clicked() {
+ view.step_page(false);
}
- // Between rotate and zoom, as in Acrobat. Its command runs once `view` is free.
- let tip = crate::i18n::fmt(tl!("Page display: {layout}"), &[("layout", tl!(view.layout.label()))]);
- let resp = icons::button(ui, view.layout.icon(), 32.0, false, &tip);
- page_display = egui::Popup::menu(&resp)
- .show(|ui| {
- ui.set_min_width(220.0);
- rail_view_menu(ui, view)
- })
- .and_then(|r| r.inner);
- let tip = crate::commands::key_tip(ui.ctx(), tl!("Zoom in ({key})"), crate::commands::ZOOM_IN);
- if icons::button(ui, "zoom-in", 32.0, false, &tip).clicked() {
- view.zoom_step(true);
+ // History is distinct from stepping to the adjacent page, and belongs to this tab.
+ for (forward, icon, label, shortcut, enabled) in [
+ (true, "chevron-right", tl!("Next view"), crate::commands::NEXT_VIEW, !view.forward.is_empty()),
+ (false, "chevron-left", tl!("Previous view"), crate::commands::PREV_VIEW, !view.back.is_empty()),
+ ] {
+ let tip = format!("{label} ({})", crate::commands::shortcut_label(ui.ctx(), shortcut));
+ if ui.add_enabled_ui(enabled, |ui| icons::button(ui, icon, 30.0, false, &tip)).inner.clicked() {
+ view.view_history(forward);
+ }
}
- let tip = crate::commands::key_tip(ui.ctx(), tl!("Zoom out ({key})"), crate::commands::ZOOM_OUT);
- if icons::button(ui, "zoom-out", 32.0, false, &tip).clicked() {
- view.zoom_step(false);
+ 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();
}
- let right = app.side_panels.rail_on_right();
- let dock_tip = if right { tl!("Dock navigation rail on Left") } else { tl!("Dock navigation rail on Right") };
- if icons::button(ui, if right { "panel-left" } else { "panel-right" }, 32.0, false, dock_tip).clicked() {
- app.side_panels.rail_side = if right { crate::side_panels::ToolsSide::Left } else { crate::side_panels::ToolsSide::Right };
+ // 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);
+ // Navigation updates the idle display, never the text being edited.
+ if !ui.memory(|m| m.has_focus(page_input_id)) {
+ view.page_input = view.current_page_label(labels.get(view.current).map(String::as_str));
+ } else if reselect {
+ // The replacement changed the label while egui retained this editor's cursor.
+ let mut state = egui::TextEdit::load_state(ui.ctx(), page_input_id).unwrap_or_default();
+ let end = egui::text::CCursor::new(view.page_input.chars().count());
+ state.cursor.set_char_range(Some(egui::text::CCursorRange::two(egui::text::CCursor::new(0), end)));
+ state.store(ui.ctx(), page_input_id);
+ }
+ let edit = egui::TextEdit::singleline(&mut view.page_input)
+ .id(page_input_id)
+ .desired_width(34.0)
+ .align(egui::Align2::CENTER_TOP)
+ .font(theme::medium(12.0))
+ .margin(vec2(2.0, 4.0));
+ let r = egui::Frame::NONE
+ .fill(t.field)
+ .stroke(Stroke::new(1.0, t.border))
+ .corner_radius(CornerRadius::same(5))
+ .show(ui, |ui| ui.add(edit))
+ .inner
+ .on_hover_text(tl!("Current page — type a page number or label (such as iv) and press Enter"))
+ .accessible_name(tl!("Current page"));
+ if r.lost_focus() {
+ if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
+ // A page label first (logical page numbers, as Acrobat), then a number.
+ let typed = view.page_input.clone();
+ view.go_to_typed(&typed, &labels);
+ }
+ view.page_input = view.current_page_label(labels.get(view.current).map(String::as_str));
}
});
});