Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(ui): prevent panel resize handle collision with scrollbar (#5730)

Combiler018baae14c34e3
diff --git a/crates/ui-egui/src/panels/side_panels.rs b/crates/ui-egui/src/panels/side_panels.rs
index 447aeac9f..c54625147 100644
--- a/crates/ui-egui/src/panels/side_panels.rs
+++ b/crates/ui-egui/src/panels/side_panels.rs
@@ -415,6 +415,22 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
.frame(egui::Frame::NONE.fill(t.panel))
.body_margin(egui::Margin::ZERO)
.show(ui, &open, |pane| Some(state_of(&panels, *pane)), &mut Content { app });
+
+ // Ensure panel resize handles do not bleed inward over panel interiors and scrollbars.
+ // The handle's active target is kept to the divider strip centered on the border.
+ for pane in &open {
+ let host_id = egui::Id::unique("pdfcraft-side-panels");
+ let s_id = host_id.with(("pane", *pane));
+ let resize_id = s_id.with("resize");
+ if let Some(resp) = ui.ctx().read_response(resize_id) {
+ let edge_layer = egui::LayerId::new(ui.layer_id().order, s_id.with("resize-layer"));
+ let edge_ui = ui.new_child(egui::UiBuilder::new().layer_id(edge_layer));
+ let old_rect = resp.rect;
+ let border = (old_rect.min.x + old_rect.max.x) / 2.0;
+ let new_rect = egui::Rect::from_x_y_ranges((border - 2.0)..=(border + 2.0), old_rect.y_range());
+ edge_ui.interact(new_rect, resize_id, egui::Sense::drag());
+ }
+ }
for request in output.requests {
match request {
PaneRequest::Resize(pane, width) => app.side_panels.set_width(pane, width),
diff --git a/crates/ui-egui/src/panels/tools.rs b/crates/ui-egui/src/panels/tools.rs
index 73326fe57..81695dc25 100644
--- a/crates/ui-egui/src/panels/tools.rs
+++ b/crates/ui-egui/src/panels/tools.rs
@@ -17,7 +17,7 @@ pub fn left_panel(app: &mut PdfCraftApp, ui: &mut egui::Ui) {
if app.left == LeftPanel::Tool("organize") && app.active.and_then(|i| app.views.get(i)).is_some_and(|v| !v.organize) {
app.left = crate::organize_panel::workspace_panel(app.mode);
}
- egui::Frame::NONE.fill(t.panel).inner_margin(egui::Margin { left: 14, right: 10, top: 12, bottom: 10 }).stroke(Stroke::new(1.0, t.divider)).show(
+ egui::Frame::NONE.fill(t.panel).inner_margin(egui::Margin { left: 14, right: 14, top: 12, bottom: 10 }).stroke(Stroke::new(1.0, t.divider)).show(
ui,
|ui| match app.left {
// Organize pages has its own panel whenever the grid shows (with a document open).
diff --git a/crates/ui-egui/tests/it/side_panels.rs b/crates/ui-egui/tests/it/side_panels.rs
index 2436d41b6..6febd2670 100644
--- a/crates/ui-egui/tests/it/side_panels.rs
+++ b/crates/ui-egui/tests/it/side_panels.rs
@@ -15,8 +15,8 @@ trailer << /Root 1 0 R >>
const WIDTH: f32 = 1400.0;
const NO_BOOKMARKS: &str = "This document has no bookmarks.";
-fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
- let mut h = Harness::builder().with_size(egui::vec2(WIDTH, 900.0)).build_eframe(move |_cc| {
+fn harness_sized(size: egui::Vec2, setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
+ let mut h = Harness::builder().with_size(size).build_eframe(move |_cc| {
let mut app = PdfCraftApp::new();
app.set_option("language", "en").unwrap();
app.open_bytes("doc.pdf", None, FIXTURE.to_vec()).unwrap();
@@ -27,6 +27,10 @@ fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, P
h
}
+fn harness(setup: impl FnOnce(&mut PdfCraftApp) + 'static) -> Harness<'static, PdfCraftApp> {
+ harness_sized(egui::vec2(WIDTH, 900.0), setup)
+}
+
fn rail(h: &Harness<'static, PdfCraftApp>) -> egui::Rect {
h.get_by_role_and_label(Role::Button, "Bookmarks").rect()
}
@@ -131,3 +135,101 @@ fn f4_toggles_the_side_panel_and_shift_f4_the_tools_panel() {
h.run_steps(3);
h.get_by_label("Expand all tools");
}
+
+#[test]
+fn scrollbar_and_panel_resize_handle_do_not_collide_on_either_dock_side() {
+ // 1. Left docking: tools panel on the left (resize handle on the right, scrollbar on the right).
+ let mut h = harness_sized(egui::vec2(1200.0, 450.0), |app| {
+ app.all_tools_expanded = true;
+ });
+ h.run_steps(4);
+
+ let splitters: Vec<_> = h.get_all_by_label("Resize panels").collect();
+ assert!(!splitters.is_empty(), "Splitter handle should exist");
+ let splitter_rect = splitters[0].rect();
+
+ // Find the scrollbar belonging to the Tools panel (left side of the window).
+ let sb_node = h.get_all_by_role(Role::ScrollBar).find(|s| s.rect().max.x < 300.0).expect("Tools panel scrollbar should exist");
+ let sb_rect = sb_node.rect();
+
+ // The scrollbar must sit strictly inside the panel, with clear gutter before the splitter.
+ assert!(sb_rect.max.x < splitter_rect.min.x);
+ assert!(splitter_rect.min.x - sb_rect.max.x >= 12.0, "Gutter must be at least 12px");
+
+ // Hovering directly over the scrollbar must NOT trigger panel resize cursor.
+ for x in [sb_rect.min.x, sb_rect.center().x, sb_rect.max.x - 0.5] {
+ h.hover_at(egui::pos2(x, sb_rect.center().y));
+ h.run_steps(1);
+ let cursor = h.output().platform_output.cursor_icon;
+ assert_ne!(cursor, egui::CursorIcon::ResizeHorizontal, "Hovering scrollbar at x={x} should not trigger resize handle");
+ }
+
+ // Hovering directly on the splitter handle MUST trigger panel resize cursor.
+ h.hover_at(splitter_rect.center());
+ h.run_steps(1);
+ assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::ResizeHorizontal);
+
+ // Dragging the scrollbar down scrolls the content up without resizing the panel.
+ let initial_width = h.state().side_panels.tools_width;
+ let first_row_before = h.get_by_label("Edit a PDF").rect().top();
+ h.hover_at(sb_rect.center());
+ h.run_steps(1);
+ h.drag_at(sb_rect.center());
+ h.run_steps(1);
+ h.hover_at(sb_rect.center() + egui::vec2(0.0, 60.0));
+ h.run_steps(1);
+ h.drop_at(sb_rect.center() + egui::vec2(0.0, 60.0));
+ h.run_steps(2);
+ let first_row_after = h.get_by_label("Edit a PDF").rect().top();
+ assert!(first_row_after < first_row_before, "Content should scroll up when dragging scrollbar down");
+ assert_eq!(h.state().side_panels.tools_width, initial_width, "Dragging scrollbar must not resize the panel");
+
+ // Dragging the splitter smoothly resizes the panel.
+ h.hover_at(splitter_rect.center());
+ h.run_steps(1);
+ h.drag_at(splitter_rect.center());
+ h.run_steps(1);
+ h.hover_at(splitter_rect.center() + egui::vec2(40.0, 0.0));
+ h.run_steps(1);
+ h.drop_at(splitter_rect.center() + egui::vec2(40.0, 0.0));
+ h.run_steps(2);
+ let after_width = h.state().side_panels.tools_width;
+ assert!(after_width > initial_width);
+ assert!((after_width - (initial_width + 40.0)).abs() <= 5.0);
+
+ // 2. Right docking: tools panel on the right (resize handle on the left).
+ let mut h_right = harness_sized(egui::vec2(1200.0, 450.0), |app| {
+ app.set_option("tools-side", "right").unwrap();
+ app.all_tools_expanded = true;
+ });
+ h_right.run_steps(4);
+
+ let splitters_right: Vec<_> = h_right.get_all_by_label("Resize panels").collect();
+ assert!(!splitters_right.is_empty());
+ let right_splitter_rect = splitters_right[0].rect();
+
+ // Splitter is at the left boundary of the right-docked pane.
+ h_right.hover_at(right_splitter_rect.center());
+ h_right.run_steps(1);
+ assert_eq!(h_right.output().platform_output.cursor_icon, egui::CursorIcon::ResizeHorizontal);
+
+ // Dragging the splitter on right-docked pane smoothly resizes.
+ let initial_right_width = h_right.state().side_panels.tools_width;
+ h_right.hover_at(right_splitter_rect.center());
+ h_right.run_steps(1);
+ h_right.drag_at(right_splitter_rect.center());
+ h_right.run_steps(1);
+ // Moving left increases width of right-docked pane
+ h_right.hover_at(right_splitter_rect.center() - egui::vec2(30.0, 0.0));
+ h_right.run_steps(1);
+ h_right.drop_at(right_splitter_rect.center() - egui::vec2(30.0, 0.0));
+ h_right.run_steps(2);
+ let after_right_width = h_right.state().side_panels.tools_width;
+ assert!(after_right_width > initial_right_width);
+ assert!((after_right_width - (initial_right_width + 30.0)).abs() <= 5.0);
+
+ // Inside the right-docked panel (e.g. 15px inside from the splitter), cursor is not resize.
+ h_right.hover_at(right_splitter_rect.center() + egui::vec2(15.0, 0.0));
+ h_right.run_steps(1);
+ assert_ne!(h_right.output().platform_output.cursor_icon, egui::CursorIcon::ResizeHorizontal);
+}