mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
pages: Go To puts the view's top where the page before ends
A go_to in a continuous view subtracted the margin above the first row (16) from every page's top, while rows after the first have the page gap (12) above them, so 4 pt of the page before showed at the view's top and WordCraft's status bar named that page. Since #7149 item 7 the offset and the canvas use one rect inside the rulers, which brought the 4 pt into view. The view's top now goes where what shows of the row above ends (the document's start for the first row), which holds for gaps on and off, Hide White Space and spreads.
This commit is contained in:
1 parent
614f4d5f16
commit
c0ba9cceb2
2 files changed
+49
-3
No files matched your search
@@ -709,8 +709,6 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
|
||||
let mut mem = cx.memory::<Memory>().clone();
|
||||
let (vw, vh) = (build.viewport.width, build.viewport.height);
|
||||
let count = build.sizes.len();
|
||||
let spacing = build.spacing;
|
||||
|
||||
// The layout the canvas was given its view for: what this pass draws, whatever the pass makes of the state.
|
||||
let drawn = build.of(&state);
|
||||
let drawn_frame = Frame::of(&drawn);
|
||||
@@ -807,9 +805,20 @@ fn run_pass(ui: &mut Ui, cx: &mut BodyCx<'_>, held: &mut Held<'_, PageViewState>
|
||||
geo = build.of(&state);
|
||||
state.zoom = geo.scale / SCREEN_POINTS_PER_POINT;
|
||||
want.1 = match geo.layout.rects.get(state.current) {
|
||||
// The view's top goes where what shows of the row above ends (the document's start for the first row), so
|
||||
// the space the layout keeps above the page shows and nothing of the page before it.
|
||||
Some(r) if state.continuous => {
|
||||
let (top, bottom) = geo.layout.bands[state.current];
|
||||
r.y0 + top + fraction * (bottom - top) - spacing.margin
|
||||
let start = r.y0 + top;
|
||||
let above = geo
|
||||
.layout
|
||||
.rects
|
||||
.iter()
|
||||
.zip(&geo.layout.bands)
|
||||
.map(|(r, band)| r.y0 + band.1)
|
||||
.filter(|&end| end <= start)
|
||||
.fold(geo.doc.y0, f64::max);
|
||||
above + fraction * (bottom - top)
|
||||
}
|
||||
_ => geo.doc.y0,
|
||||
};
|
||||
|
||||
@@ -908,3 +908,40 @@ fn a_wheel_up_at_the_top_never_moves_the_page_with_rulers_on_or_off() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Go To page `page` in a continuous view of 20 pages at 100 %, `rulers` on or off: the first page the view places and
|
||||
/// the offset, with where the page before ends.
|
||||
fn gone_to(page: usize, rulers: bool) -> (Option<usize>, f64, f64) {
|
||||
let state = Rc::new(RefCell::new(state_with(|s| {
|
||||
s.fit = Fit::None;
|
||||
s.zoom = 1.0;
|
||||
s.continuous = true;
|
||||
})));
|
||||
let seen = Rc::new(RefCell::new((None, 0.0)));
|
||||
let (kept, shown) = (Rc::clone(&state), Rc::clone(&seen));
|
||||
let pages = DemoPages::new(20);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut now = kept.borrow().clone();
|
||||
let out = PageView::new("Pages", &pages, &mut now, PAPER).options(LayoutOptions::ACROBAT).rulers(rulers).show(ui, |_, _| ());
|
||||
let before = page.checked_sub(1).map_or(0.0, |before| out.layout.rects[before].y0 + out.layout.bands[before].1);
|
||||
*shown.borrow_mut() = (out.pages.first().map(|p| p.page), before);
|
||||
*kept.borrow_mut() = now;
|
||||
});
|
||||
fixture.room(vec2(1280.0, 760.0));
|
||||
fixture.settle();
|
||||
state.borrow_mut().go_to(page);
|
||||
fixture.idle(3);
|
||||
let (first, before) = *seen.borrow();
|
||||
(first, state.borrow().offset.1, before)
|
||||
}
|
||||
|
||||
/// Go To puts the view's top where the page before ends, so the gap above the page shows and nothing of the page
|
||||
/// before it, with rulers on or off.
|
||||
#[trial]
|
||||
fn go_to_shows_the_page_at_the_top_and_nothing_of_the_page_before() {
|
||||
for rulers in [false, true] {
|
||||
let (first, offset, before) = gone_to(5, rulers);
|
||||
assert_eq!(first, Some(5), "rulers {rulers}: the first page in view is the one gone to");
|
||||
assert!((offset - before).abs() < 0.01, "rulers {rulers}: the view's top {offset} is where the page before ends, {before}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user