mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
red round 2 (fw-pages): fixes for fw-run-3 (runs/fw-run-3/fw-pages.md); L-198 applied in fw-lists; committed by the lead
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6187b8cea3
commit
b218c823b2
@@ -18,12 +18,8 @@ const CENTRE: Point = Point::new(300.0, 400.0);
|
||||
const DRAG_THRESHOLDS: f32 = 12.0;
|
||||
|
||||
fn drag_left_edge(fixture: &mut Fixture) {
|
||||
let Some(target) = fixture.by_label("Left Margin") else {
|
||||
eprintln!("DIAG MarginHandles<'_>::drives: no node named Left Margin");
|
||||
return;
|
||||
};
|
||||
let Some(target) = fixture.by_label("Left Margin") else { return };
|
||||
let travel = DRAG_THRESHOLDS * craft_ui::testing::input::slop(fixture.ctx());
|
||||
eprintln!("DIAG MarginHandles<'_>::drives: target centre {:?}, travel {travel}", target.center());
|
||||
fixture.drag(&target, Vec2::new(travel, 0.0));
|
||||
}
|
||||
|
||||
|
||||
+10
-21
@@ -437,11 +437,10 @@ impl<'a> PageView<'a> {
|
||||
let frame = Frame::of(&geo);
|
||||
let given = frame.view(rect, start.offset, geo.scale / SCREEN_POINTS_PER_POINT);
|
||||
let mut navigation = navigation;
|
||||
navigation.overscroll = !start.continuous;
|
||||
let mut canvas = Canvas::new(label.clone()).view(given).navigation(navigation).keys_to_body(true);
|
||||
if start.continuous {
|
||||
canvas = canvas.document(frame.document(&geo));
|
||||
}
|
||||
// The canvas keeps the view inside the shown row, as the pass does, so a wheel share that cannot pan a row at its
|
||||
// edge leaves the gesture unmoved and a page turn can follow it.
|
||||
navigation.overscroll = false;
|
||||
let canvas = Canvas::new(label.clone()).view(given).navigation(navigation).keys_to_body(true).document(frame.document(&geo));
|
||||
let mut held = Held::new(Bind::bound(state));
|
||||
let mut seen: Option<Seen> = None;
|
||||
let mut canvas_body = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
|
||||
@@ -629,18 +628,11 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
|
||||
// A scale the fit (a new viewport or pages) or the app changed keeps the document point at the centre of the
|
||||
// view where it was, unless the app moved the view or asked for a go-to in the same breath.
|
||||
let unmoved = mem.offset == Some(state.offset);
|
||||
if let Some((_, previous)) = previous.filter(|(_, p)| !scale_settled(p.scale, geo.scale)).filter(|_| unmoved && state.go_to.is_none())
|
||||
&& let Some(offset) = centred_offset(&previous, &geo, state.offset, (vw, vh))
|
||||
if let Some((key, previous)) = previous.filter(|(_, p)| !scale_settled(p.scale, geo.scale)).filter(|_| unmoved && state.go_to.is_none())
|
||||
&& let Some(offset) = centred_offset(&previous, &geo, state.offset, (key.viewport.width, key.viewport.height), (vw, vh))
|
||||
{
|
||||
state.offset = offset;
|
||||
}
|
||||
eprintln!(
|
||||
"DIAG a_changed_zoom_keeps_the_point_at_the_centre_in_place: unmoved {unmoved} scale {} offset {:?} mem {:?} go_to {}",
|
||||
geo.scale,
|
||||
state.offset,
|
||||
mem.offset,
|
||||
state.go_to.is_some()
|
||||
);
|
||||
state.zoom = geo.scale / SCREEN_POINTS_PER_POINT;
|
||||
|
||||
// The canvas folded the wheel, a pinch and the view commands into the view it settled on: a different zoom is the
|
||||
@@ -751,10 +743,6 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
|
||||
})
|
||||
.collect();
|
||||
let near = near_pages(&drawn, state.continuous, &visible, count, &build.layout_options(&state), travel);
|
||||
eprintln!(
|
||||
"DIAG prefetch_asks_for_the_rows_ahead_of_the_motion_and_none_behind: travel {travel} last {:?} want {want:?} visible {visible:?} near {near:?}",
|
||||
mem.offset
|
||||
);
|
||||
let kept = keep.iter().copied().filter(|page| *page < count && !rows.contains(page) && !near.contains(page));
|
||||
for page in near.iter().copied().chain(kept) {
|
||||
let size = drawn.layout.rects[page].size();
|
||||
@@ -1108,9 +1096,10 @@ fn offset_range(lo: f64, hi: f64, len: f64) -> (f64, f64) {
|
||||
|
||||
/// The offset that keeps the document point at the centre of a view `(vw, vh)` points where it was when the scale
|
||||
/// goes from `old`'s to `new`'s: the page under the centre keeps the same fractions of its width and height there;
|
||||
/// with the centre in a gap, the next page keeps its distance below the centre. `None` when `new` has no such page.
|
||||
fn centred_offset(old: &Placed, new: &Placed, offset: (f64, f64), (vw, vh): (f64, f64)) -> Option<(f64, f64)> {
|
||||
let centre = Point::new(offset.0 + vw / 2.0, offset.1 + vh / 2.0);
|
||||
/// with the centre in a gap, the next page keeps its distance below the centre. `offset` is of a view of `old_view`
|
||||
/// points, the result of one of `(vw, vh)` points (a new room changes both). `None` when `new` has no such page.
|
||||
fn centred_offset(old: &Placed, new: &Placed, offset: (f64, f64), old_view: (f64, f64), (vw, vh): (f64, f64)) -> Option<(f64, f64)> {
|
||||
let centre = Point::new(offset.0 + old_view.0 / 2.0, offset.1 + old_view.1 / 2.0);
|
||||
let pages = 0..old.layout.rects.len();
|
||||
let band = |page: usize| band_rect(&old.layout, page);
|
||||
let fraction = |at: f64, from: f64, len: f64| if len > 0.0 { (at - from) / len } else { 0.0 };
|
||||
|
||||
@@ -87,11 +87,8 @@ fn rig_over(source: impl PageSource + 'static, start: PageViewState, navigation:
|
||||
let mut now = kept.borrow().clone();
|
||||
let offset = now.offset;
|
||||
let keep = held.borrow().clone();
|
||||
let shown = PageView::new("Pages", &source, &mut now, PAPER)
|
||||
.options(LayoutOptions::ACROBAT)
|
||||
.navigation(navigation)
|
||||
.keep(&keep)
|
||||
.show(ui, |_, _| ());
|
||||
let shown =
|
||||
PageView::new("Pages", &source, &mut now, PAPER).options(LayoutOptions::ACROBAT).navigation(navigation).keep(&keep).show(ui, |_, _| ());
|
||||
*seen.borrow_mut() =
|
||||
Out { offset, rects: shown.layout.rects.clone(), pages: shown.pages, visible: shown.visible, view: shown.canvas.response.rect };
|
||||
*kept.borrow_mut() = now;
|
||||
@@ -126,7 +123,10 @@ fn assert_centre_kept(out: &Out, before: (usize, kurbo::Point), what: &str) {
|
||||
let (page, point) = before;
|
||||
let now = out.point(page, point);
|
||||
let centre = out.centre();
|
||||
assert!((now.x - centre.x).abs() < 1.0 && (now.y - centre.y).abs() < 1.0, "{what}: {point:?} of page {page} is at {now:?}, the centre at {centre:?}");
|
||||
assert!(
|
||||
(now.x - centre.x).abs() < 1.0 && (now.y - centre.y).abs() < 1.0,
|
||||
"{what}: {point:?} of page {page} is at {now:?}, the centre at {centre:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
@@ -174,7 +174,13 @@ fn wheel(fixture: &mut Fixture, lines: f32) {
|
||||
|
||||
/// A scroll of `dy` points over the middle of the room from `source`, in device phase `phase`.
|
||||
fn swipe(fixture: &mut Fixture, dy: f32, phase: egui::TouchPhase, source: egui::MouseWheelSource) {
|
||||
fixture.frame(vec![egui::Event::MouseWheel { unit: egui::MouseWheelUnit::Point, delta: vec2(0.0, dy), modifiers: Modifiers::NONE, phase, source }]);
|
||||
fixture.frame(vec![egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: vec2(0.0, dy),
|
||||
modifiers: Modifiers::NONE,
|
||||
phase,
|
||||
source,
|
||||
}]);
|
||||
}
|
||||
|
||||
/// Frames until the wheel service has ended the running gesture.
|
||||
@@ -455,7 +461,8 @@ fn a_fit_holds_the_page_at_the_top_still_while_pages_of_other_sizes_scroll_past(
|
||||
#[trial]
|
||||
fn prefetch_asks_for_the_rows_ahead_of_the_motion_and_none_behind() {
|
||||
// The pages outside the view the source was asked to render since the last call.
|
||||
let outside = |asked: &RefCell<Vec<usize>>, out: &Out| -> Vec<usize> { asked.borrow_mut().drain(..).filter(|page| !out.visible.contains(page)).collect() };
|
||||
let outside =
|
||||
|asked: &RefCell<Vec<usize>>, out: &Out| -> Vec<usize> { asked.borrow_mut().drain(..).filter(|page| !out.visible.contains(page)).collect() };
|
||||
for two_up in [false, true] {
|
||||
let asked: Rc<RefCell<Vec<usize>>> = Rc::default();
|
||||
let source = Recording::new(DemoPages::new(24), vec![LETTER; 24], &asked);
|
||||
@@ -475,7 +482,11 @@ fn prefetch_asks_for_the_rows_ahead_of_the_motion_and_none_behind() {
|
||||
fixture.frame(Vec::new());
|
||||
let out = out.borrow();
|
||||
let asked = outside(&asked, &out);
|
||||
assert!(asked.iter().all(|page| *page >= out.visible.end), "two-up {two_up}: forward asks ahead only: {asked:?} beside {:?}", out.visible);
|
||||
assert!(
|
||||
asked.iter().all(|page| *page >= out.visible.end),
|
||||
"two-up {two_up}: forward asks ahead only: {asked:?} beside {:?}",
|
||||
out.visible
|
||||
);
|
||||
ahead += asked.len();
|
||||
}
|
||||
assert!(ahead > 0, "two-up {two_up}: forward travel asks for the pages ahead");
|
||||
@@ -485,7 +496,9 @@ fn prefetch_asks_for_the_rows_ahead_of_the_motion_and_none_behind() {
|
||||
let still = outside(&asked, &out.borrow());
|
||||
assert!(still.is_empty(), "two-up {two_up}: a still view asks for nothing it had not asked for: {still:?}");
|
||||
|
||||
state.borrow_mut().offset.1 += 4000.0;
|
||||
// To the end of the document, far from every page the run forward and its rests asked for: a page the source
|
||||
// rendered before is cached, so only pages never asked for show what the back travel asks for.
|
||||
state.borrow_mut().offset.1 = 1.0e6;
|
||||
fixture.idle(3);
|
||||
asked.borrow_mut().clear();
|
||||
let mut behind = 0;
|
||||
@@ -679,8 +692,7 @@ fn reselecting_the_display_moves_nothing_and_a_change_keeps_the_current_page() {
|
||||
view.fixture.idle(2);
|
||||
assert_eq!(view.state.borrow().offset, offset, "writing the display it has moves nothing");
|
||||
|
||||
let changes: [(&str, fn(&mut PageViewState)); 2] =
|
||||
[("display", |s| s.display = PageDisplay::TwoUp), ("fit", |s| s.fit = Fit::Page)];
|
||||
let changes: [(&str, fn(&mut PageViewState)); 2] = [("display", |s| s.display = PageDisplay::TwoUp), ("fit", |s| s.fit = Fit::Page)];
|
||||
for (what, change) in changes {
|
||||
// Where a go-to to the current page puts the view, from the same state.
|
||||
let mut reference = rig(6, view.state.borrow().clone());
|
||||
@@ -693,7 +705,10 @@ fn reselecting_the_display_moves_nothing_and_a_change_keeps_the_current_page() {
|
||||
change(&mut view.state.borrow_mut());
|
||||
view.fixture.idle(2);
|
||||
let (got, want) = (view.state.borrow().offset, reference.state.borrow().offset);
|
||||
assert!((got.0 - want.0).abs() < 1.0 && (got.1 - want.1).abs() < 1.0, "a new {what} keeps the current page in view: {got:?} against {want:?}");
|
||||
assert!(
|
||||
(got.0 - want.0).abs() < 1.0 && (got.1 - want.1).abs() < 1.0,
|
||||
"a new {what} keeps the current page in view: {got:?} against {want:?}"
|
||||
);
|
||||
assert_eq!(view.state.borrow().current, current, "a new {what} keeps the current page");
|
||||
}
|
||||
}
|
||||
@@ -764,11 +779,8 @@ fn a_scroll_bar_drag_holds_the_sharp_renders_of_the_part_in_view_in_its_own_pass
|
||||
});
|
||||
let Rig { mut fixture, state, .. } = rig_over(source, start, NavigationOptions::default(), true);
|
||||
assert!(*parts.borrow() > 0, "precondition: a page past the texture side asks for the part in view");
|
||||
let bar = fixture
|
||||
.by_role(Role::SCROLL_BAR)
|
||||
.into_iter()
|
||||
.max_by(|a, b| a.rect.height().total_cmp(&b.rect.height()))
|
||||
.expect("the view has scroll bars");
|
||||
let bar =
|
||||
fixture.by_role(Role::SCROLL_BAR).into_iter().max_by(|a, b| a.rect.height().total_cmp(&b.rect.height())).expect("the view has scroll bars");
|
||||
let grab = pos2(bar.rect.center().x, bar.rect.min.y + 6.0);
|
||||
let (before, offset) = (*parts.borrow(), state.borrow().offset.1);
|
||||
fixture.frame(vec![craft_ui::testing::pointer::moved(grab)]);
|
||||
|
||||
@@ -262,6 +262,19 @@ impl Component for CanvasScrollbars<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The host maps a proposed centre through its own layout (a scroll offset in points) and back, so the view it
|
||||
/// writes back differs from the proposal by rounding only; that is not a change under the drag.
|
||||
fn same_value(&self, proposed: &CanvasView, host: &CanvasView) -> bool {
|
||||
let magnitude = proposed.center.x.abs().max(proposed.center.y.abs()).max(host.center.x.abs()).max(host.center.y.abs());
|
||||
let mut rounded = *proposed;
|
||||
rounded.center = host.center;
|
||||
rounded.zoom = host.zoom;
|
||||
rounded == *host
|
||||
&& craft_behavior::same_in_f32_at(proposed.center.x, host.center.x, magnitude)
|
||||
&& craft_behavior::same_in_f32_at(proposed.center.y, host.center.y, magnitude)
|
||||
&& craft_behavior::same_in_f32(proposed.zoom, host.zoom)
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let Some(view) = cx.value().copied() else { return };
|
||||
let bars = self.bars(&view, cx.rect, cx.style.look.thickness);
|
||||
|
||||
Reference in New Issue
Block a user