From ef0cf346bab0032464f926ecb358a7e8d7aa9924 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 15:20:44 -0500 Subject: [PATCH] Tools pane: 330 in a wide window, production's 272 under 900 points --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/lib.rs | 3 +++ crates/ui-egui/src/panels/side_panels.rs | 31 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index c552212b8a..719d8de9f1 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -275,6 +275,7 @@ impl PdfCraftApp { last_right: RightPanel::Comments, notice_inset: 0.0, toolbar_tools_open: true, + window_narrow: false, right_before_read: None, comments_panel_closed: false, right_panel_closed: false, diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 3324cc3fe5..19638c96b4 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -279,6 +279,9 @@ pub struct PdfCraftApp { /// Whether the Tools pane was in the dock when the floating toolbar was last placed: the toolbar follows the page area's /// left edge as the pane closes and opens. pub(crate) toolbar_tools_open: bool, + /// Whether the window was narrow (under [`panels::side_panels::NARROW_WINDOW`]) when the Tools pane's width was last set: a + /// narrow window keeps the pane at production's width, a wide one gives it the width Format text needs. + pub(crate) window_narrow: bool, /// The right panel that was open when the user switched to Read mode, which starts with the /// panes closed; leaving Read mode brings it back unless the user opened or closed a pane in /// Read mode meanwhile. diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs index aaa29b5fe6..5d95f2e10b 100644 --- a/crates/ui-egui/src/panels/side_panels.rs +++ b/crates/ui-egui/src/panels/side_panels.rs @@ -169,6 +169,10 @@ const PAGE_SHARE: f32 = 0.8; /// 10-point gaps need about 55 more for Format text's size field to keep room for its value beside the colour well, the list /// buttons and the alignment menu (the field takes what the row leaves). const TOOLS_WIDTH: f32 = 330.0; +/// The Tools pane's width in a narrow window, as production opened it. +const TOOLS_WIDTH_NARROW: f32 = 272.0; +/// Windows narrower than this keep the Tools pane at [`TOOLS_WIDTH_NARROW`]: a wider pane would leave the page area too little. +pub(crate) const NARROW_WINDOW: f32 = 900.0; /// The arrangement of a new install: Tools at the start edge, the side-panel rail at the window edge, /// and the toolbar floating at the start of the page area. The side panels form one collapsed group. @@ -203,6 +207,32 @@ fn keep_toolbar_in_the_margin(app: &mut PdfCraftApp) { } } +/// The Tools pane's width follows the window across [`NARROW_WINDOW`]: production's narrower pane in a small window, the +/// wider default in a large one. Only the crossing changes it, so a width the user dragged to is kept. +fn fit_tools_to_window(app: &mut PdfCraftApp, window_width: f32) { + let narrow = window_width.is_finite() && window_width < NARROW_WINDOW; + if narrow == app.window_narrow { + return; + } + app.window_narrow = narrow; + if !app.dock.layout.contains(&PanelId::Tools) { + return; + } + let width = if narrow { TOOLS_WIDTH_NARROW } else { TOOLS_WIDTH }; + // A refused resize (a locked layout) leaves the width as it is. + if app.dock.apply(Action::resize_column(PanelId::Tools, width), false, permissions).is_err() { + return; + } + // The floating toolbar sits in the page area's margin, which moved with the pane's edge. + let shift = if narrow { TOOLS_WIDTH_NARROW - TOOLS_WIDTH } else { TOOLS_WIDTH - TOOLS_WIDTH_NARROW }; + if app.toolbar_tools_open + && let Some(window) = app.dock.layout.floating.iter_mut().find(|window| window.contains(&PanelId::Toolbar)) + && window.rect.min.x >= TOOLS_WIDTH_NARROW + { + window.rect = window.rect.translate(egui::vec2(shift, 0.0)); + } +} + /// The window edge whose dock holds `panel`, `None` when it is closed or floating. fn edge_of(workspace: &Workspace, panel: PanelId) -> Option { let mut pending: Vec<(&Node, usize)> = workspace.layout.root.iter().map(|node| (node, 0)).collect(); @@ -506,6 +536,7 @@ pub fn dock(app: &mut PdfCraftApp, ui: &mut Ui) { let toolbar = active && !app.hotbar_hidden() && !organizing && !expanded; let anchor = rail_anchor(app); keep_toolbar_in_the_margin(app); + fit_tools_to_window(app, ui.ctx().content_rect().width()); 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.