diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index eab3f48d9b..e814002175 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -1888,7 +1888,6 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu let out = ui .push_id(view_key, |ui| { PageView::new(tl!("Pages"), &source, state, DataColor::new(paper)) - .floating_scrollbars() .navigation(navigation) .border(border) .pasteboard(surround) diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index 84d0bf0a6d..8c9088afb6 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -88,6 +88,7 @@ mod redact; mod reload; mod scan_clean; mod script_noop; +mod scrollbars; mod search_position; mod show_boxes; mod side_panels; diff --git a/crates/ui-egui/tests/it/scrollbars.rs b/crates/ui-egui/tests/it/scrollbars.rs new file mode 100644 index 0000000000..96b7640098 --- /dev/null +++ b/crates/ui-egui/tests/it/scrollbars.rs @@ -0,0 +1,42 @@ +//! The page view's scroll bar: a usable width, not a sliver the user must preempt (#9001). +//! +//! A 3-pixel floating sliver is a target the user must preempt; a scroll bar is interacted with +//! more than a button and should be a comparable, reachable size. The docked bar (18 pt) is +//! stable in every state — it does not grow when the pointer moves onto it — whereas the +//! floating bar's thumb grows from 2 pt to 6 pt on hover. + +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use pdfcraft_ui_egui::PdfCraftApp; + +/// The app over six 300×200 pt pages, shown continuously at 300 %: 3600 pt of content in a 900 pt +/// window, so the vertical scroll bar is always on screen (and 900 < 1400 keeps the horizontal one off). +fn harness() -> Harness<'static, PdfCraftApp> { + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|cc| { + crate::support::install_runtime(&cc.egui_ctx); + { + let mut app = crate::control::new_app(); + app.set_option(&egui::Context::default(), "language", "en").unwrap(); + app.open_bytes(&egui::Context::default(), "pages.pdf", None, crate::support::fixtures::pdf_pages(6)).unwrap(); + app.set_option(&egui::Context::default(), "continuous", "on").unwrap(); + app.set_option(&egui::Context::default(), "zoom", "300").unwrap(); + app + } + }); + crate::support::settle(&mut h); + h.run_steps(5); + h +} + +/// The vertical scroll bar's track, from the access tree: the bar's clickable rect, whose width is +/// the bar's drawn width. +fn vertical_bar(h: &Harness<'static, PdfCraftApp>) -> egui::Rect { + h.get_by_role_and_label(egui::accesskit::Role::ScrollBar, "Vertical scroll bar").rect() +} + +#[test] +fn the_vertical_scroll_bar_is_a_usable_width() { + let h = harness(); + let track = vertical_bar(&h); + assert!(track.width() >= 16.0, "the scroll bar is a usable width ({:.1} pt), not a sliver the user must preempt", track.width()); +} diff --git a/crates/ui-egui/tests/it/viewer.rs b/crates/ui-egui/tests/it/viewer.rs index c817b803ea..56d4cb6ab6 100644 --- a/crates/ui-egui/tests/it/viewer.rs +++ b/crates/ui-egui/tests/it/viewer.rs @@ -414,6 +414,45 @@ fn a_search_flash_preserves_following_while_an_unrelated_drag_is_held() { ); } +/// #9001: the document thumb is visibly wide at rest and can be dragged from that width. +#[test] +fn document_scrollbar_is_wide_at_rest_and_draggable() { + fn painted_thumb(shape: &egui::Shape, bar: egui::Rect) -> Option { + match shape { + egui::Shape::Vec(children) => children.iter().find_map(|child| painted_thumb(child, bar)), + egui::Shape::Rect(paint) + if paint.fill.a() > 0 + && bar.expand(1.0).contains_rect(paint.rect) + && paint.rect.width() >= bar.width() - 1.0 + && paint.rect.height() > paint.rect.width() + && paint.rect.height() < bar.height() - 1.0 => + { + Some(paint.rect) + } + _ => None, + } + } + + let mut h = harness(); + h.state_mut().active = Some(0); + h.run_steps(5); + let bar = h.get_by_role_and_label(egui::accesskit::Role::ScrollBar, "Vertical scroll bar").rect(); + assert!(bar.width() >= 14.0, "the document target is comfortably wide: {bar:?}"); + let thumb = h.output().shapes.iter().find_map(|shape| painted_thumb(&shape.shape, bar)).expect("a full-width thumb is painted before hovering"); + let start = egui::pos2(thumb.left() + 2.0, thumb.center().y); + let before = h.state().views[0].page_screen_rect(0).expect("first page visible").top(); + h.hover_at(start); + h.run_steps(2); + h.drag_at(start); + h.run_steps(2); + h.hover_at(start + egui::vec2(0.0, bar.height() * 0.3)); + h.run_steps(3); + h.drop_at(start + egui::vec2(0.0, bar.height() * 0.3)); + h.run_steps(3); + let after = h.state().views[0].page_screen_rect(0).map(|r| r.top()); + assert!(after.is_none_or(|top| top < before - 10.0), "dragging the visible thumb moves the document: {before} -> {after:?}"); +} + /// The document scroll bar is its own scroll surface: a track click moves the offset with no /// pointer motion, and dragging from that press keeps moving it. Both are the reader scrolling, /// so automatic following ends. A global "any drag is scrolling" check would miss the click. @@ -422,11 +461,9 @@ fn scroll_bar_track_click_and_drag_end_automatic_search_following() { let mut h = harness(); let view = find_one_match_per_page(&mut h); h.run_steps(4); - let vp = h.state().views[view].viewport_rect(); - // Floating bars sit in the outer few points of the document area (see theme). Aim 75% down - // the vertical track: below the handle at this scroll position, and clear of the corner - // where the horizontal bar's track overlaps. - let track = egui::pos2(vp.right() - 4.0, vp.top() + vp.height() * 0.75); + // Aim below the handle, clear of the horizontal bar and independent of the bar width. + let bar = h.get_by_role_and_label(egui::accesskit::Role::ScrollBar, "Vertical scroll bar").rect(); + let track = egui::pos2(bar.center().x, bar.top() + bar.height() * 0.75); let before = h.state().views[view].page_screen_rect(0).expect("page 1 is on screen").top(); h.event(egui::Event::PointerMoved(track)); h.run_steps(2); @@ -440,7 +477,7 @@ fn scroll_bar_track_click_and_drag_end_automatic_search_following() { } // Keep dragging from the press: the scroll bar follows the pointer, still reader scrolling. - let dragged = egui::pos2(vp.right() - 4.0, vp.top() + vp.height() * 0.4); + let dragged = egui::pos2(bar.center().x, bar.top() + bar.height() * 0.4); h.event(egui::Event::PointerMoved(dragged)); h.run_steps(2); assert!(late_match_leaves_current(&mut h, view), "the track drag is the reader scrolling");