mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-18 02:32:33 +00:00
28 lines
1.1 KiB
Rust
28 lines
1.1 KiB
Rust
//! `CanvasScrollbars`: the clamp of the view and the bars' drag and page press.
|
|
|
|
use craft_behavior::CanvasView;
|
|
use craft_behavior::kurbo::{Point, Rect as DocRect};
|
|
use craft_ui::canvas::CanvasScrollbars;
|
|
use craft_ui::testing::trial;
|
|
use egui::{Pos2, Rect};
|
|
|
|
/// The view's rect in the fixture, in points.
|
|
const VIEW: Rect = Rect::from_min_max(Pos2::new(0.0, 0.0), Pos2::new(400.0, 300.0));
|
|
|
|
/// The slack of a rect comparison after f32 maths, in points.
|
|
const TOLERANCE: f32 = 0.01;
|
|
|
|
fn view_at(center: Point, zoom: f64) -> CanvasView {
|
|
CanvasView::new(VIEW, center, zoom)
|
|
}
|
|
|
|
#[trial]
|
|
fn a_rotated_view_is_clamped_by_the_document_as_it_is_shown() {
|
|
let doc = DocRect::new(0.0, 0.0, 1000.0, 800.0);
|
|
let mut view = view_at(Point::new(-50.0, 100.0), 1.0).rotation(90.0);
|
|
assert!(CanvasScrollbars::clamp(&mut view, doc));
|
|
let quad = view.quad(doc);
|
|
let shown = quad.iter().skip(1).fold(Rect::from_min_max(quad[0], quad[0]), |rect, &corner| rect.union(Rect::from_min_max(corner, corner)));
|
|
assert!(shown.expand(TOLERANCE).contains_rect(VIEW), "the turned document covers the view: {shown:?}");
|
|
}
|