Expand description
The view model: what part of the image is shown, at what zoom, and the one mapping between image and screen that drawing, hit testing and the pixel readout all use.
Experimental: may change in any release
(docs/stability.md).
- Zoom is physical:
View::zoomcounts physical screen pixels per image pixel, so 100 % is exactly1.0and means one image pixel on one pixel of the window’s surface, whatever the window’s scale. Each window converts with its ownpixels_per_point, so the same view shown in two windows is 1:1 in both. - Whole-pixel offsets:
Mappingsnaps the image’s origin to a whole physical pixel, so at 100 %, at whole zooms (200 %, 300 %) and at their inverses no column is repeated or skipped. - The ladder:
zoom_inandzoom_outwalkZOOM_LADDER; the wheel (wheel_zoom) is continuous but stops at 100 % when it crosses it, so exact pixels are always one notch away.
use egui_pop_viewport::view::{Mapping, View};
let rect = egui::Rect::from_min_size(egui::pos2(10.0, 10.0), egui::vec2(400.0, 300.0));
// 100 % on a window at 150 %: one image pixel per physical pixel.
let view = View::actual([500.0, 400.0]);
let m = Mapping::new(&view, [1000.0, 800.0], rect, 1.5);
assert_eq!(m.zoom, 1.0);
let p = m.image_to_screen([500.0, 400.0]);
assert_eq!(m.pixel_at(p), Some([500, 400]));The model lives in egui_pop_core::pointer::view, shared with every
zoomable image view (the library’s comparison), so a gesture changes
the same View in each.
Structs§
- Mapping
- The mapping between image pixels, physical pixels and points for one
frame of one viewport in one window. Build it with
Mapping::new; every conversion of the viewport (drawing, tiles, hit tests, the readout) goes through it. - View
- What is shown: a zoom and the image point at the centre of the view. The application owns it (a window, a document); the viewport changes it through gestures and says so with signals.
Enums§
- Zoom
- How the zoom is chosen.
Constants§
- MAX_
ZOOM - The largest zoom.
- MIN_
ZOOM - The smallest zoom (a very large image fitted in a small view).
- WHEEL_
RATE - How fast the wheel zooms: the factor per point of scroll is
exp(points × WHEEL_RATE)(wheel_factor). - ZOOM_
LADDER - The zoom steps of
zoom_inandzoom_out, in physical pixels per image pixel: whole ratios first (100 % is1.0).
Functions§
- fit_
zoom - The zoom that shows a whole image in a view of
rect_pxphysical pixels. - wheel_
zoom - The zoom after a wheel motion of
points(positive zooms in): a continuous factor that stops at exactly 100 % when it crosses it. - zoom_in
- The next ladder step above
zoom(orMAX_ZOOM’s step). - zoom_
out - The next ladder step below
zoom(or the smallest step).