PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge main into fix/quick-bar-centred-in-margin
RiceDeebcff9a39489d
diff --cc crates/ui-egui/src/canvas.rsindex 62fc39cca,a22064442..8d13b77e9--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -3486,9 -4055,8 +4055,10 @@@ fn apply_frame_requests(app: &mut PdfCr// Read mode hides the tools (#2646), and full screen is the page and nothing else (#1459);// the quick tools come back with the window.if app.mode != crate::Mode::Read && !app.full_screen {- quick_bar(app, avail, ui);+ // The page nearest the left edge, whose margin the bar sits in.+ let page_left = app.views[index].screen_rects.iter().map(|(_, r)| r.left()).reduce(f32::min);+ quick_bar(app, avail, page_left, ui);+ crate::hotbar::show(app, avail, ui.ctx());}if let Some((source, file, destination)) = remote_open {app.open_remote_link(source, file, destination);diff --cc crates/ui-egui/src/canvas/bars.rsindex c3ddd4b9e,4ad2bf05d..5ea5e4a19--- a/crates/ui-egui/src/canvas/bars.rs+++ b/crates/ui-egui/src/canvas/bars.rs@@@ -276,30 -276,19 +276,39 @@@ fn notice_bar(ui: &mut egui::Ui, t: &To});}-/// The floating quick-action bar at the left edge of the document area.-pub(super) fn quick_bar(app: &mut PdfCraftApp, area: Rect, ui: &mut egui::Ui) {+/// The bar's narrowest form: one 32 pt button, 6 pt margins and a 1 pt border each side.+const QUICK_BAR_WIDTH: f32 = 46.0;+const QUICK_BAR_EDGE: f32 = 14.0;++/// How far from the side panel the quick-action bar stands, given the width of the margin between+/// the panel and the page and the bar's own width: centred in the margin when it holds the bar,+/// else 14 pt in (a page filling the width). With no page on screen the caller passes a margin of 0,+/// which is 14 pt too.+fn quick_bar_offset(margin: f32, width: f32) -> f32 {+ // shortcut: centred in at most 100 pt of margin, so a wide margin keeps the bar by the panel.+ // `f32::min` returns the other operand for NaN, which would pass the fit check below.+ let margin = if margin.is_nan() { 0.0 } else { margin.min(100.0) };+ if margin >= width + 2.0 * 8.0 { (margin - width) / 2.0 } else { QUICK_BAR_EDGE }+}++/// The floating quick-action bar in the margin between the side panel and the page.+pub(super) fn quick_bar(app: &mut PdfCraftApp, area: Rect, page_left: Option<f32>, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());+ let mut offset = vec2(0.0, 0.0);+ if app.hotbar.full_side {+ match app.hotbar.dock.as_deref() {+ Some("left") => offset.x += app.hotbar.button_size + 14.0,+ Some("top") => offset.y += app.hotbar.button_size + 14.0,+ _ => {}+ }+ }- let pos = area.left_top() + vec2(14.0, 14.0) + offset;- egui::Area::new(egui::Id::unique("quick-bar")).order(egui::Order::Middle).fixed_pos(pos).show(ui.ctx(), |ui| {+ let id = egui::Id::unique("quick-bar");+ // Last frame's bar: Fill & Sign's Text and Date tools add a wider row of controls to it.+ let width = ui.ctx().memory(|m| m.area_rect(id)).map_or(QUICK_BAR_WIDTH, |bar| bar.width().max(QUICK_BAR_WIDTH));- let x = quick_bar_offset(page_left.map_or(0.0, |left| left - area.left()), width);- let pos = area.left_top() + vec2(x, QUICK_BAR_EDGE);++ // The margin starts past a hotbar docked on the left.++ let x = quick_bar_offset(page_left.map_or(0.0, |left| left - area.left() - offset.x), width);++ let pos = area.left_top() + vec2(x, QUICK_BAR_EDGE) + offset;+ egui::Area::new(id).order(egui::Order::Middle).fixed_pos(pos).show(ui.ctx(), |ui| {egui::Frame::NONE.fill(t.card).stroke(Stroke::new(1.0, t.border))