Merge pull request #8479

Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
FredAppsandautocraft-bot[bot] authored and autocraft-bot[bot] committed 2026-12-06 08:59:10 +00:00
commit 5e5e85530e
12 files changed
+165 -25

No files matched your search

+1
View File
@@ -291,6 +291,7 @@ impl PdfCraftApp {
dock_shown: Default::default(),
command_states: Default::default(),
rail_side: craft::behavior::DockSide::End,
rail_controls_top: false,
session: Session::new(),
status_captions_lang: None,
views: Vec::new(),
+5 -1
View File
@@ -248,7 +248,8 @@ impl PdfCraftApp {
javascript: Some(self.session.javascript()),
};
// PLAN: assumed app fields `dock`, `rail_side`, `recent_view`, `recent_sort` (chrome-w13, chrome-w16)
let dock = settings::Dock { dock: json_text(&*self.dock), rail_side: name_of(&self.rail_side) };
let dock =
settings::Dock { dock: json_text(&*self.dock), rail_side: name_of(&self.rail_side), rail_controls_top: Some(self.rail_controls_top) };
let recent = settings::Recent {
recent: json_text(&self.recent.iter().take(self.recent_limit).collect::<Vec<_>>()),
recent_limit: u32::try_from(self.recent_limit).ok(),
@@ -294,6 +295,9 @@ impl PdfCraftApp {
if let Some(side) = s.rail_side.as_deref().and_then(from_name) {
self.rail_side = side;
}
if let Some(top) = s.rail_controls_top {
self.rail_controls_top = top;
}
}
/// The recent files, how Home lists them and how many are kept.
+8 -3
View File
@@ -193,6 +193,9 @@ pub struct Dock {
/// JSON text: the dock workspace.
pub dock: Option<String>,
pub rail_side: Option<String>,
/// Whether the rail's view controls (page number, page stepping, zoom, page display) sit in a bar above the
/// document instead of in the rail.
pub rail_controls_top: Option<bool>,
}
impl Dock {
@@ -731,17 +734,19 @@ pub fn import_json(text: &str) -> (PdfCraftSettings, Vec<SectionError>) {
let hotbar = Hotbar { tools: hotbar_tools };
let dock = {
let r = Reader::new(&root, Dock::KEY, &mut errors);
let mut r = Reader::new(&root, Dock::KEY, &mut errors);
let saved_side = r.text("rail_side").and_then(|t| serde_json::from_str::<String>(&t).ok());
let controls_top = r.bool("rail_controls_top");
match r.text("dock") {
Some(workspace) => Dock { dock: Some(workspace), rail_side: saved_side },
Some(workspace) => Dock { dock: Some(workspace), rail_side: saved_side, rail_controls_top: controls_top },
// Settings from before the dock keep their panels in `side_panels` or `docking`.
None => match crate::side_panels::migrate(&Value::Object(root.clone())) {
Some(m) => Dock {
dock: serde_json::to_string(&m.workspace).ok(),
rail_side: serde_json::to_value(m.rail_side).ok().and_then(|v| v.as_str().map(str::to_string)),
rail_controls_top: controls_top,
},
None => Dock { dock: None, rail_side: saved_side },
None => Dock { dock: None, rail_side: saved_side, rail_controls_top: controls_top },
},
}
};
+9 -1
View File
@@ -31,7 +31,9 @@ pub(crate) fn shell(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
let hidden = app.hidden_interface();
let modes_visible = !hidden.mode_bar(app.native_menu.is_some());
let window_ui = !hidden.window_ui;
let fallback_rail = window_ui && side_panels::rail_anchor(app).is_none();
let fallback_rail = window_ui && !app.rail_controls_top && side_panels::rail_anchor(app).is_none();
// The view controls in a bar above the document (#5240): the bar is its own row, so it never covers the page.
let controls_bar = window_ui && app.rail_controls_top && app.active_ids().is_some() && !app.full_screen_document();
let out = AppShell::new(WindowKey::main())
.toast_alignment(egui::Align2::CENTER_BOTTOM)
.screen_mode(Bind::given(app.screen_mode))
@@ -42,6 +44,12 @@ pub(crate) fn shell(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
.title_follows_lights(true)
.title_bar(|ui, _, app: &mut PdfCraftApp| title_bar(app, ui))
.top(Slot::new("modes").visible(modes_visible), |ui, _, app: &mut PdfCraftApp| mode_bar::show(app, ui))
.top(Slot::new("view-rail-top").visible(controls_bar), |ui, _, app: &mut PdfCraftApp| {
// A narrow window scrolls the row sideways, so every control stays reachable.
egui::ScrollArea::horizontal().id_salt("view-rail-top").auto_shrink([false, true]).show(ui, |ui| {
ui.horizontal(|ui| view_rail::show_top(app, ui));
});
})
.start(
Slot::new("view-rail-start").visible(fallback_rail && app.rail_side == craft::behavior::DockSide::Start),
|ui, _, app: &mut PdfCraftApp| view_rail::show(app, ui),
+42 -18
View File
@@ -15,12 +15,20 @@ use egui::Ui;
use crate::PdfCraftApp;
/// Shows the rail's view cluster; nothing without an active document or a current page to view.
/// Shows the rail's view cluster in its column; nothing without an active document or a current page to view, and
/// nothing while the controls sit in the bar above the document (#5240).
pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) {
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| controls(app, ui));
if !app.rail_controls_top {
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| controls(app, ui, false));
}
}
fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
/// Shows the same controls in a row, for the bar above the document.
pub(crate) fn show_top(app: &mut PdfCraftApp, ui: &mut Ui) {
controls(app, ui, true);
}
fn controls(app: &mut PdfCraftApp, ui: &mut Ui, top: bool) {
let Some((index, id)) = app.active_ids() else { return };
let Some(doc) = app.session.get(id) else { return };
let page_count = doc.info.pages.len();
@@ -32,22 +40,27 @@ fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
let Some(page) = doc.info.pages.get(current) else { return };
let page_size = Size::new(f64::from(page.width.max(1.0)), f64::from(page.height.max(1.0)));
if top {
// Keep the way back in the visible start of the row even at a narrow window width.
let icon = if rail_on_right { "panel_right" } else { "panel_left" };
IconButton::command(IconId::new(icon), "view.rail.in_rail").show(ui);
}
let (field_size, caption_size) = {
let env = Env::of(ui);
// The page box takes the rail's whole width, as the zoom field does, so a four-digit page number fits.
(egui::vec2(ui.available_width(), env.tokens.size.control.md), env.tokens.typography.caption.size)
let width = if top { env.tokens.size.rail.button } else { ui.available_width() };
(egui::vec2(width, env.tokens.size.control.md), env.tokens.typography.caption.size)
};
// Taken once, in the pass that shows the field, also while the field is not focused.
let reselect = std::mem::take(&mut view.page_input_reselect);
let input_id = view.page_input_id();
let (field_rect, _) = ui.allocate_exact_size(field_size, egui::Sense::hover());
let edit = TextField::new("Current page", Bind::bound(&mut view.page_input))
.id(input_id)
.centred()
.select_on_focus()
.select_all(reselect)
.submits()
.show_at(ui, field_rect);
let focus_page = ui.ctx().data_mut(|data| data.remove_temp::<bool>(input_id.with("rail-placement-focus"))).unwrap_or_default();
let page_field =
TextField::new("Current page", Bind::bound(&mut view.page_input)).id(input_id).centred().select_on_focus().select_all(reselect).submits();
let page_field = if focus_page { page_field.request_focus(focus::FocusRequest::Take) } else { page_field };
let edit = page_field.show_at(ui, field_rect);
if !edit.events.is_empty() {
view.page_input_draft = true;
}
@@ -74,8 +87,12 @@ fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
// "1488/1500" has no space to wrap at and is wider than the rail: it breaks after the slash instead.
let one_line =
ui.fonts_mut(|fonts| fonts.layout_no_wrap(position.clone(), egui::FontId::proportional(caption_size), egui::Color32::PLACEHOLDER).size().x);
let position = if one_line > ui.available_width() { position.replacen('/', "/\n", 1) } else { position };
ui.vertical_centered(|ui| Text::new(position).role(TypeRole::Caption).tooltip(of).show(ui));
if top {
Text::new(position).role(TypeRole::Caption).tooltip(of).show(ui);
} else {
let position = if one_line > ui.available_width() { position.replacen('/', "/\n", 1) } else { position };
ui.vertical_centered(|ui| Text::new(position).role(TypeRole::Caption).tooltip(of).show(ui));
}
IconButton::command(IconId::new("chevron_left"), "view.previous_view").show(ui);
IconButton::command(IconId::new("chevron_right"), "view.next_view").show(ui);
@@ -83,7 +100,9 @@ fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
IconButton::command(IconId::new("chevron_down"), "view.next_page").show(ui);
// The percent suffix and three digits need the rail's full width, not an icon button's width.
let zoom_size = egui::vec2(ui.available_width(), field_size.y);
// In a row the field takes a fixed width, not what is left.
let zoom_width = if top { field_size.x * 1.75 } else { ui.available_width() };
let zoom_size = egui::vec2(zoom_width, field_size.y);
let (zoom_rect, _) = ui.allocate_exact_size(zoom_size, egui::Sense::hover());
let field = ZoomField::new("Zoom", view.canvas_view(), page_size).scale(ZoomScale::Points).show_at(ui, zoom_rect);
if let Some(edited) = field.view.committed() {
@@ -118,9 +137,14 @@ fn controls(app: &mut PdfCraftApp, ui: &mut Ui) {
}
});
if rail_on_right {
IconButton::command(IconId::new("panel_left"), "view.rail.left").show(ui);
} else {
IconButton::command(IconId::new("panel_right"), "view.rail.right").show(ui);
if !top {
// Share one footer row so the additional action does not crowd the scrollable rail buttons.
let (icon, side_command) = if rail_on_right { ("panel_left", "view.rail.left") } else { ("panel_right", "view.rail.right") };
let row_height = Env::of(ui).tokens.size.control.md;
let (row, _) = ui.allocate_exact_size(egui::vec2(ui.available_width(), row_height), egui::Sense::hover());
let left = egui::Rect::from_min_max(row.min, egui::pos2(row.center().x, row.bottom()));
let right = egui::Rect::from_min_max(egui::pos2(row.center().x, row.top()), row.max);
IconButton::command(IconId::new(icon), side_command).show_at(ui, left);
IconButton::command(IconId::new("rows-3"), "view.rail.top").show_at(ui, right);
}
}
+14
View File
@@ -157,6 +157,19 @@ impl PdfCraftApp {
}
}
fn move_rail_controls(&mut self, ctx: &egui::Context, active: Option<usize>, top: bool) {
if top != self.rail_controls_top {
self.set_live_rail_controls_top(top);
if let Some(view) = active.and_then(|i| self.views.get(i)) {
ctx.data_mut(|data| data.insert_temp(view.page_input_id().with("rail-placement-focus"), true));
}
let message = if top { tl!("Page navigation controls moved to the top bar") } else { tl!("Page navigation controls moved to the rail") };
use craft::ui::runtime::access::{Politeness, announce};
announce(ctx, message.to_string(), Politeness::Polite);
ctx.request_repaint();
}
}
/// The handlers of the catalog ids that are not registered engine commands. `false` when
/// `fired` is not one of them.
fn run_catalog_command(&mut self, ctx: &egui::Context, fired: &Fired) -> bool {
@@ -214,6 +227,7 @@ impl PdfCraftApp {
self.notify(e);
}
}
"view.rail.top" | "view.rail.in_rail" => self.move_rail_controls(ctx, active, id == "view.rail.top"),
"home.unpin_tool" => {
// PLAN: assumed params `{ "tool": <group id> }` and `PdfCraftApp::unpin_tool(&mut self, &str)` (pdf-chrome-w9).
if let Some(tool) = fired.command.params.get("tool").and_then(|t| t.as_str()) {
+3
View File
@@ -29,6 +29,9 @@ pub(crate) const CATALOG_ONLY: &[(&str, &str, &str)] = &[
// The rail's button names the side it moves the rail to.
("view.rail.left", "Dock navigation rail on Left", "panel-left"),
("view.rail.right", "Dock navigation rail on Right", "panel-right"),
// The view controls (page number, page stepping, zoom, page display) in a bar above the document, or back in the rail.
("view.rail.top", "Show navigation controls at the Top", "rows-3"),
("view.rail.in_rail", "Show navigation controls in the Rail", "panel-right"),
("view.fit_toggle", "Toggle fit", "scan"),
("bookmark.paste", "Paste bookmarks", "clipboard-paste"),
("bookmark.expand_all", "Expand all bookmarks", "chevrons-down"),
+1
View File
@@ -148,6 +148,7 @@ impl crate::PdfCraftApp {
"left_panel": if self.left_open() { json!(format!("{:?}", self.left)) } else { Value::Null },
"tools_side": dock["tools_side"].clone(),
"rail_side": dock["rail_side"].clone(),
"rail_controls": dock["rail_controls"].clone(),
"right_panel": self.right().map(|r| format!("{r:?}")),
"hidden_interface": self.hidden_interface().to_json(),
// The top host dialog's key, else the inline window that is open.
+22
View File
@@ -125,6 +125,8 @@ struct PrefsDraft {
ui_scale: Option<f32>,
tools_right: bool,
rail_right: bool,
/// The view controls sit in a bar above the document, not in the rail.
controls_top: bool,
animation: MotionChoice,
reopen_last_session: bool,
restore_last_view: bool,
@@ -165,6 +167,7 @@ impl PrefsDraft {
ui_scale: app.ui_scale,
tools_right: crate::side_panels::tools_on_right(app),
rail_right: app.rail_side != DockSide::Start,
controls_top: app.rail_controls_top,
animation: app.animation_effects,
reopen_last_session: app.reopen_last_session,
restore_last_view: app.restore_last_view,
@@ -209,6 +212,7 @@ impl PrefsDraft {
ui_scale: None,
tools_right: false,
rail_right: true,
controls_top: false,
animation: MotionChoice::System,
reopen_last_session: false,
restore_last_view: true,
@@ -280,6 +284,14 @@ impl PdfCraftApp {
}
}
/// Applies a placement change from outside Preferences without discarding other draft edits.
pub(crate) fn set_live_rail_controls_top(&mut self, top: bool) {
self.rail_controls_top = top;
if let Some(prefs) = self.preferences.as_mut() {
prefs.draft.controls_top = top;
}
}
/// Shows the Preferences window for this pass while it is open, and closes it when answered.
pub(crate) fn show_preferences(&mut self, ui: &mut Ui) {
let Some(mut session) = self.preferences.take() else {
@@ -433,6 +445,12 @@ fn side_table<'a>() -> Table<'a, bool> {
vec![(false, "left", tl!("Left")), (true, "right", tl!("Right"))]
}
/// Where the view controls (page number, page stepping, zoom, page display) sit: in the rail, or in a bar above the
/// document.
fn controls_table<'a>() -> Table<'a, bool> {
vec![(false, "rail", tl!("In the rail")), (true, "top", tl!("In a bar at the top"))]
}
fn animation_table<'a>() -> Table<'a, MotionChoice> {
vec![
(MotionChoice::System, "system", tl_ctx!("animation effects", "Use system setting")),
@@ -542,6 +560,7 @@ impl PreferencesModel for Prefs<'_> {
("general.scale", PrefValue::Choice(id)) => d.ui_scale = id.parse::<u16>().ok().map(|p| f32::from(p) / 100.0),
("general.tools_side", PrefValue::Choice(id)) => d.tools_right = lookup(&side_table(), &id).unwrap_or(d.tools_right),
("general.rail_side", PrefValue::Choice(id)) => d.rail_right = lookup(&side_table(), &id).unwrap_or(d.rail_right),
("general.rail_controls", PrefValue::Choice(id)) => d.controls_top = lookup(&controls_table(), &id).unwrap_or(d.controls_top),
("general.animation", PrefValue::Choice(id)) => d.animation = lookup(&animation_table(), &id).unwrap_or(d.animation),
("general.reopen", PrefValue::Bool(v)) => d.reopen_last_session = v,
("general.restore_view", PrefValue::Bool(v)) => d.restore_last_view = v,
@@ -680,6 +699,7 @@ impl PreferencesModel for Prefs<'_> {
d.ui_scale = fresh.ui_scale;
d.tools_right = fresh.tools_right;
d.rail_right = fresh.rail_right;
d.controls_top = fresh.controls_top;
d.animation = fresh.animation;
d.reopen_last_session = fresh.reopen_last_session;
d.restore_last_view = fresh.restore_last_view;
@@ -781,6 +801,7 @@ impl PreferencesDraft for Prefs<'_> {
self.app.ui_scale = d.ui_scale;
crate::side_panels::set_tools_on_right(self.app, d.tools_right)?;
crate::side_panels::set_rail_side(self.app, if d.rail_right { DockSide::End } else { DockSide::Start })?;
self.app.rail_controls_top = d.controls_top;
self.app.animation_effects = d.animation;
self.app.reopen_last_session = d.reopen_last_session;
self.app.restore_last_view = d.restore_last_view;
@@ -865,6 +886,7 @@ impl Prefs<'_> {
.help(tl!("Auto follows the system's text size. Pages always render at the display's full resolution.")),
choice_row("general.tools_side", tl!("Tools panel side"), d.tools_right, &side_table()),
choice_row("general.rail_side", tl!("Navigation rail side"), d.rail_right, &side_table()),
choice_row("general.rail_controls", tl!("Page navigation controls"), d.controls_top, &controls_table()),
choice_row("general.animation", tl!("Animation effects"), d.animation, &animation_table()),
];
#[cfg(not(target_arch = "wasm32"))]
+2
View File
@@ -265,6 +265,8 @@ pub struct PdfCraftApp {
pub(crate) dock_shown: craft::ui::contract::Tracked<std::collections::BTreeSet<craft::ui::docking::PanelKey>>,
/// The side the rail of panel buttons sits on.
pub rail_side: craft::behavior::DockSide,
/// Whether the rail's view controls sit in a bar above the document instead of in the rail (#5240).
pub rail_controls_top: bool,
pub session: Session,
/// The interface language signature status captions were last drawn in.
pub(crate) status_captions_lang: Option<i18n::Lang>,
+12 -2
View File
@@ -724,6 +724,7 @@ pub fn state(app: &PdfCraftApp) -> Value {
"tools_side": edge_name(edge_of(&app.dock, PanelId::Tools)),
"tools_open": app.dock.layout().contains(&PanelId::Tools),
"rail_side": edge_name(Some(rail_edge(app.rail_side))),
"rail_controls": if app.rail_controls_top { "top" } else { "rail" },
"side_open": side.is_some(),
"side_panel": side.and_then(PanelId::side).map(|r| format!("{r:?}")),
})
@@ -823,7 +824,8 @@ fn edge_param(value: &str, key: &str) -> Result<DockEdge, String> {
}
}
/// `ui.panel {panel, open?, edge?}`, `ui.panel {rail_side}` and `ui.dock.reset` (`reset`).
/// `ui.panel {panel, open?, edge?}`, `ui.panel {rail_side}`, `ui.panel {rail_controls: "rail" | "top"}` (the view
/// controls in the rail or in a bar above the document) and `ui.dock.reset` (`reset`).
///
/// A request is checked whole before anything changes. Panel sizes are not parameters: they are the dock's, set by
/// dragging a divider or by `ui.dock.apply`.
@@ -845,8 +847,13 @@ pub fn command(app: &mut PdfCraftApp, reset: bool, params: &Value) -> Result<Val
Some(if edge == DockEdge::Start { DockSide::Start } else { DockSide::End })
}
};
let controls = match params.get("rail_controls") {
None | Some(Value::Null) => None,
Some(Value::String(place)) if place == "top" || place == "rail" => Some(place == "top"),
Some(_) => return Err("rail_controls must be \"rail\" or \"top\"".into()),
};
let panel = match params.get("panel") {
None | Some(Value::Null) if rail.is_some() => None,
None | Some(Value::Null) if rail.is_some() || controls.is_some() => None,
value => {
let name = value.and_then(Value::as_str).ok_or("panel must be \"tools\", \"toolbar\", \"side\" or a side panel's name")?;
Some(if name == "side" {
@@ -875,6 +882,9 @@ pub fn command(app: &mut PdfCraftApp, reset: bool, params: &Value) -> Result<Val
if let Some(side) = rail {
set_rail_side(app, side)?;
}
if let Some(top) = controls {
app.set_live_rail_controls_top(top);
}
Ok(json!({ "side_panels": state(app) }))
}
+46
View File
@@ -741,6 +741,52 @@ fn navigation_rail_toggles_between_right_and_left_and_persists() {
assert_eq!(side(&mut h2, "rail_side"), "left");
}
/// The view controls (page number, page stepping, zoom) can sit in a bar above the document instead of the rail
/// (#5240): the rail's button and Preferences move them, the choice persists, and the controls stay reachable in
/// either place.
#[test]
fn view_controls_move_to_a_bar_at_the_top_and_persist() {
let mut h = harness(|app| app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
assert_eq!(side(&mut h, "rail_controls"), "rail");
// In the rail the dock-side buttons are there; the way back is not.
assert!(h.query_by_label("Dock navigation rail on Left").is_some());
assert!(h.query_by_label("Show navigation controls in the Rail").is_none());
h.get_by_label("Show navigation controls at the Top").click();
h.run_steps(3);
assert_eq!(side(&mut h, "rail_controls"), "top");
// In the bar the way back is there, the rail's side buttons are not, and the page controls are still on screen.
assert!(h.query_by_label("Show navigation controls in the Rail").is_some());
assert!(h.query_by_label("Dock navigation rail on Left").is_none());
assert!(h.query_by_label("Current page").is_some(), "the page box is reachable in the top bar");
let saved = h.state().settings_snapshot();
let mut h2 = harness(move |app| {
app.apply_settings(&saved);
app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens");
});
assert_eq!(side(&mut h2, "rail_controls"), "top", "the placement came back after a restart");
h2.get_by_label("Show navigation controls in the Rail").click();
h2.run_steps(3);
assert_eq!(side(&mut h2, "rail_controls"), "rail");
h2.set_option("dialog", "preferences").unwrap();
h2.run_steps(3);
pick_preference(&mut h2, None, "Page navigation controls", "In a bar at the top");
h2.get_by_label("OK").click();
h2.run_steps(3);
assert_eq!(side(&mut h2, "rail_controls"), "top");
}
#[test]
fn external_rail_placement_survives_an_open_preferences_draft() {
let mut h = harness(|app| app.open_bytes(&egui::Context::default(), "fixture.pdf", None, FIXTURE.to_vec()).expect("fixture opens"));
h.set_option("dialog", "preferences").unwrap();
h.run_steps(3);
for place in ["top", "rail"] {
pdfcraft_ui_egui::side_panels::command(h.state_mut(), false, &serde_json::json!({"rail_controls": place})).unwrap();
h.run_steps(3);
assert_eq!(side(&mut h, "rail_controls"), place, "open Preferences must not undo the external placement");
}
}
/// Read mode hides the tools, not the navigation panes: the rail's Bookmarks button opens the
/// bookmarks when Read is the default workspace (#932), and the left tool pane stays hidden.
#[test]