mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-04 13:03:19 -05:00
* Fix #9001: scroll bars are a usable width and do not grow on hover The page view's scroll bars regressed to 3-pixel floating slivers that grow on hover. The root cause is the .floating_scrollbars() call on the PageView builder, which switches the page view from the 18 pt docked bar (stable width in every state, no growth) to the 2-6 pt floating bar (transparent at rest, thumb grows from 2 pt to 6 pt on hover). Removing .floating_scrollbars() restores the docked bar: 18 pt wide (comparable to a button) and stable in every state, so it no longer grows when the pointer moves onto it. Adds the_vertical_scroll_bar_is_a_usable_width, which fails without the fix (6 pt < 16 pt) and passes with it (18 pt >= 16 pt). Co-authored-by: Copilot <[email protected]> * test(ui): aim the track test at the docked bar and check the thumb is wide at rest (#9001 review) Ports the test half of361654b70from the release line: the scroll-bar track test takes the bar's rect from the access tree instead of aiming at the floating bar's outer points, and `document_scrollbar_is_wide_at_rest_and_draggable` finds the painted thumb before hovering. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * test(ui): find the painted document thumb in its viewport paint slot (#9001) Portsd24593f70from the release line, the follow-up that the wide-at-rest test needs on this tree. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: FredApps <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
4 files changed
+86
-7
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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<egui::Rect> {
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user