Skip to main content

Module view

Module view 

Source
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::zoom counts physical screen pixels per image pixel, so 100 % is exactly 1.0 and means one image pixel on one pixel of the window’s surface, whatever the window’s scale. Each window converts with its own pixels_per_point, so the same view shown in two windows is 1:1 in both.
  • Whole-pixel offsets: Mapping snaps 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_in and zoom_out walk ZOOM_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_in and zoom_out, in physical pixels per image pixel: whole ratios first (100 % is 1.0).

Functions§

fit_zoom
The zoom that shows a whole image in a view of rect_px physical 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 (or MAX_ZOOM’s step).
zoom_out
The next ladder step below zoom (or the smallest step).