Keep page controls in the navigation rail

This commit is contained in:
Dylan M. Taylor
2026-11-20 20:10:45 -05:00
parent 01bc2081b6
commit 2b5ea17257
3 changed files with 102 additions and 53 deletions
+9 -1
View File
@@ -27,13 +27,21 @@ 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 out = AppShell::new(WindowKey::main())
.toast_alignment(egui::Align2::CENTER_BOTTOM)
.screen_mode(Bind::given(app.screen_mode))
// A presentation shows the page and nothing else, so no reveal brings the bars back.
.allow_reveal(false)
.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))
.end(Slot::new("view-rail").visible(window_ui), |ui, _, app: &mut PdfCraftApp| view_rail::show(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),
)
.end(Slot::new("view-rail").visible(fallback_rail && app.rail_side == craft::behavior::DockSide::End), |ui, _, app: &mut PdfCraftApp| {
view_rail::show(app, ui)
})
.body(|ui, _, app: &mut PdfCraftApp| window_body(app, ui))
.show(ui, app);
// PLAN: assumed `set_screen_mode(&mut self, ScreenMode)` (pdf-shell-w8)
+57 -47
View File
@@ -9,7 +9,7 @@ use craft::ui::buttons::IconButton;
use craft::ui::contract::{Bind, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger};
use craft::ui::display::Text;
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::runtime::focus;
use craft::ui::runtime::{env::Env, focus};
use craft::ui::text::{TextField, ZoomField, ZoomScale};
use egui::Ui;
@@ -28,11 +28,59 @@ pub(crate) fn show(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 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);
let field_size = {
let env = Env::of(ui);
egui::vec2(env.tokens.size.rail.button, env.tokens.size.control.md)
};
// 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)
.select_on_focus()
.select_all(reselect)
.submits()
.show_at(ui, field_rect);
if !edit.events.is_empty() {
view.page_input_draft = true;
}
if edit.submitted {
let typed = view.page_input.clone();
view.go_to_typed(&typed, &labels);
view.page_input_draft = false;
}
if edit.escaped {
view.page_input_draft = false;
}
// Navigation updates the box, never text being typed into it: the field keeps the focus after Enter, and its
// focus is on its text part, which counts as the field.
if !(view.page_input_draft && focus::is_focused(ui.ctx(), edit.response.id)) {
view.page_input_draft = false;
view.page_input = view.current_page_label(labels.get(view.current()).map(String::as_str));
}
let label = labels.get(current).map_or("", String::as_str);
// Out of range (an empty document) reads "Page 0 of 0", never past the end.
let shown = if current < page_count { current + 1 } else { page_count };
let of = crate::i18n::fmt(crate::i18n::t("Page {p} of {n}"), &[("p", &shown.to_string()), ("n", &page_count.to_string())]);
Text::new(super::page_position(current, page_count, label)).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);
IconButton::command(IconId::new("chevron_up"), "view.previous_page").show(ui);
IconButton::command(IconId::new("chevron_down"), "view.next_page").show(ui);
let (zoom_rect, _) = ui.allocate_exact_size(field_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() {
view.apply_canvas_view(edited);
}
IconButton::command(IconId::new("zoom_in"), "view.zoom.in").show(ui);
IconButton::command(IconId::new("zoom_out"), "view.zoom.out").show(ui);
IconButton::command(IconId::new("maximize_2"), "view.fit_toggle").show(ui);
IconButton::command(IconId::new("rotate_cw"), "view.rotate.cw").show(ui);
// The rows' marks come from the commands' checked state (the catalog), not from here.
let display_icon = if view.view.display == PageDisplay::Single { "file-text" } else { "columns-2" };
@@ -56,47 +104,9 @@ pub(crate) fn show(app: &mut PdfCraftApp, ui: &mut Ui) {
}
});
IconButton::command(IconId::new("rotate_cw"), "view.rotate.cw").show(ui);
IconButton::command(IconId::new("maximize_2"), "view.fit_toggle").show(ui);
IconButton::command(IconId::new("zoom_out"), "view.zoom.out").show(ui);
IconButton::command(IconId::new("zoom_in"), "view.zoom.in").show(ui);
let field = ZoomField::new("Zoom", view.canvas_view(), page_size).scale(ZoomScale::Points).show(ui);
if let Some(edited) = field.view.committed() {
view.apply_canvas_view(edited);
}
IconButton::command(IconId::new("chevron_down"), "view.next_page").show(ui);
IconButton::command(IconId::new("chevron_up"), "view.previous_page").show(ui);
IconButton::command(IconId::new("chevron_right"), "view.next_view").show(ui);
IconButton::command(IconId::new("chevron_left"), "view.previous_view").show(ui);
let label = labels.get(current).map_or("", String::as_str);
// Out of range (an empty document) reads "Page 0 of 0", never past the end.
let shown = if current < page_count { current + 1 } else { page_count };
let of = crate::i18n::fmt(crate::i18n::t("Page {p} of {n}"), &[("p", &shown.to_string()), ("n", &page_count.to_string())]);
Text::new(super::page_position(current, page_count, label)).role(TypeRole::Caption).tooltip(of).show(ui);
// 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 edit =
TextField::new("Current page", Bind::bound(&mut view.page_input)).id(input_id).select_on_focus().select_all(reselect).submits().show(ui);
if !edit.events.is_empty() {
view.page_input_draft = true;
}
if edit.submitted {
let typed = view.page_input.clone();
view.go_to_typed(&typed, &labels);
view.page_input_draft = false;
}
if edit.escaped {
view.page_input_draft = false;
}
// Navigation updates the box, never text being typed into it: the field keeps the focus after Enter, and its
// focus is on its text part, which counts as the field.
if !(view.page_input_draft && focus::is_focused(ui.ctx(), edit.response.id)) {
view.page_input_draft = false;
view.page_input = view.current_page_label(labels.get(view.current()).map(String::as_str));
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);
}
}
+36 -5
View File
@@ -168,8 +168,8 @@ const PAGE_SHARE: f32 = 0.8;
/// The Tools pane's default width, as production opened it.
const TOOLS_WIDTH: f32 = 272.0;
/// The arrangement of a new install: Tools at the start edge, the toolbar at the rail's edge, the page area between
/// the docks, and the side panels as one group in a column inward of the toolbar's, collapsed to their icons.
/// The arrangement of a new install: Tools at the start edge, the side-panel rail at the window edge, the toolbar inward of it, and the page area between
/// the docks. The side panels form one group, collapsed to their icons.
pub fn default_workspace(rail_side: DockSide) -> Workspace<PanelId> {
let single = |panel| Column::new(vec![Group::new(vec![panel], 0)]);
// The rail is one tool column wide: its column keeps the toolbar's grid, never the theme's column width.
@@ -177,7 +177,7 @@ pub fn default_workspace(rail_side: DockSide) -> Workspace<PanelId> {
let (tools, toolbar) = (single(PanelId::Tools).with_width(TOOLS_WIDTH), single(PanelId::Toolbar).with_steps(1));
let side = Column::new(vec![Group::new(SIDE.to_vec(), 0)]).with_iconic(true);
let (start, end) =
if rail_edge(rail_side) == DockEdge::Start { (vec![toolbar, side, tools], Vec::new()) } else { (vec![tools], vec![toolbar, side]) };
if rail_edge(rail_side) == DockEdge::Start { (vec![side, toolbar, tools], Vec::new()) } else { (vec![tools], vec![side, toolbar]) };
let page = Node::split(Axis::X, SplitSize::Ratio(PAGE_SHARE), Node::tabs(vec![PanelId::Document], 0), Node::dock(DockEdge::End, end));
let root = Node::split(Axis::X, SplitSize::Ratio(START_SHARE), Node::dock(DockEdge::Start, start), page);
Workspace::new(Layout::new(Some(root), Vec::new()))
@@ -325,6 +325,10 @@ impl DockPanels<PanelId> for Panels<'_> {
}
}
fn rail_footer(&mut self, _: &PanelId, ui: &mut Ui, _: &mut BodyCx<'_>) {
crate::chrome::view_rail::show(self.app, ui);
}
fn permissions(&self, panel: &PanelId) -> Permissions {
permissions(panel)
}
@@ -441,6 +445,24 @@ impl DockPanels<PanelId> for Rules {
fn body(&mut self, _panel: &PanelId, _ui: &mut Ui, _cx: &mut BodyCx<'_>) {}
}
/// A visible panel in the navigation rail anchors the fixed view controls. If all panels have
/// moved away or are hidden, the shell keeps the controls available on its own rail.
pub(crate) fn rail_anchor(app: &PdfCraftApp) -> Option<PanelId> {
if app.active.is_none() || app.full_screen_document() || app.hidden_interface().window_ui || (app.mode == Mode::AllTools && app.all_tools_full) {
return None;
}
let open = open_side(&app.dock);
let checked = app.active_ids().is_some_and(|(_, id)| app.a11y.report.as_ref().is_some_and(|(d, _)| *d == id));
dock_columns(&app.dock, rail_edge(app.rail_side)).iter().flat_map(|column| column.panels()).copied().find(|panel| {
SIDE.contains(panel)
&& match panel {
PanelId::Accessibility => checked || open == Some(*panel),
PanelId::Search | PanelId::Compare => open == Some(*panel),
_ => true,
}
})
}
/// Draws the dock. Call after the top bars and before the central panel.
///
/// The area gets a copy of the workspace and reports every change of the pass; they are applied to `app.dock` here,
@@ -454,6 +476,7 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) {
// in its tab (ISO 32000-2 Table 147); the tab strip stays, and F8 brings the rest back (`viewer_prefs`).
let bare = app.full_screen_document() || app.hidden_interface().window_ui;
let toolbar = active && !app.hotbar_hidden();
let anchor = rail_anchor(app);
let workspace = app.dock.clone();
// The rail lists the Accessibility Checker once the document has a report, and Search and Compare only while
// they show; their commands open them.
@@ -477,7 +500,11 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) {
// The side panels' icons are production's rail: they stay beside the expanded column, a click on one opens its
// panel docked, and a click on the open panel's icon closes it.
let config = DockConfig::default().native_windows(false).iconic_mode(IconicMode::Rail);
let output = DockArea::new("Dock", Bind::given(workspace), &mut panels, config).hide(HidePanels::Except(&shown)).show(ui);
let area = DockArea::new("Dock", Bind::given(workspace), &mut panels, config).hide(HidePanels::Except(&shown));
let output = match anchor {
Some(panel) => area.rail_footer(panel).show(ui),
None => area.show(ui),
};
let before = right_of(&app.dock);
for action in output.actions.into_iter().chain(output.requested) {
// The area drops what the workspace refuses; one refused here is stale, not the user's mistake.
@@ -557,7 +584,11 @@ fn move_to_edge(app: &mut PdfCraftApp, panel: PanelId, edge: DockEdge) -> Result
if edge_of(&app.dock, panel) == Some(edge) {
return Ok(());
}
let to = edge_target(&app.dock, edge);
let to = if SIDE.contains(&panel) && edge_of(&app.dock, PanelId::Toolbar) == Some(edge) {
Target::at(PanelId::Toolbar, DockPlacement::column(false))
} else {
edge_target(&app.dock, edge)
};
app.dock.apply(Action::move_column(panel, to), false, permissions).map(drop).map_err(|_| refused())
}