PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #2703: Go to page brings the page into view horizontally too
aiongg6431fdfb8809
diff --cc crates/ui-egui/src/canvas.rsindex 7d7fe8f6a,7747fdf00..e5319a1aa--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -2571,11 -2464,22 +2571,23 @@@ pub fn document_area(app: &mut PdfCraft} else if let Some((page, frac)) = view.goto.take() {let page = page.min(rects.len() - 1);let r = rects[page];- scroll = scroll.vertical_scroll_offset((r.top() - y_shift - GAP + frac * r.height()).max(0.0));+ // Clamped here: egui clamps only after drawing, so a page that fits was drawn MARGIN - GAP+ // too high for a frame and then hopped into place. (`avail` is the viewport, as the+ // scroll bars float.)+ let max_y = (content_h - avail.height()).max(0.0);+ scroll = scroll.vertical_scroll_offset((r.top() - y_shift - GAP + frac * r.height()).max(0.0).min(max_y));+ // Horizontally too, as Acrobat does (#2665): beside a much wider page the others sit off+ // to one side. A page already shown whole, or one filling the window's width, keeps the+ // scroll, so paging through a zoomed-in document stays on the same column. Otherwise a+ // page that fits is centred, and a wider one scrolled just far enough to fill the window.+ // The page counts with its side gutters, which keep its edge clear of the floating+ // quick-action bar as the layout does.+ let (x, w) = (view.last_scroll.x, avail.width());+ let (left, right) = (r.left() - SIDE, r.right() + SIDE);+ let target = if right - left <= w { if left >= x && right <= x + w { x } else { r.center().x - w / 2.0 } } else { x.clamp(left, right - w) };+ if (target - x).abs() > 0.5 {+ scroll = scroll.horizontal_scroll_offset(target.clamp(0.0, (content_w - w).max(0.0)));+ }}let ppp = ui.ctx().pixels_per_point();let scale = view.render_scale(ppp);