Skip to main content

Module scale

Module scale 

Source
Expand description

Scale, per window. Three scales multiply into egui’s pixels_per_point (ppp) for the window being drawn:

  • the native scale, the system’s for the window’s screen (winit’s scale factor), which differs between windows on screens of different densities;
  • the interface zoom, the user’s “make everything bigger”, one value for every window (egui’s zoom_factor), moved in fixed ZOOM_STEPS so that each step’s glyphs are rasterised once;
  • text size, which egui-pop’s theme applies to fonts only.

Layout is in points and does not move when the scale changes; only rasterisation does. Read the scale where you paint (ui.ctx().pixels_per_point() is the current window’s), never from a value kept by an application-wide object. Caches sized in physical pixels (thumbnails, textures) listen to changed, once per change.

Lines: a 1 point stroke is 1.25 pixels at 1.25, feathered over two pixel columns into a grey line. stroke snaps a width as CSS snaps border widths: to whole pixels, at least one.

use egui_pop_core::scale;

assert_eq!(scale::snap(1.0, 1.25), 0.8); // one pixel
assert_eq!(scale::snap(1.0, 2.0), 1.0); // two pixels
assert_eq!(scale::snap(0.25, 1.0), 1.0); // never under one pixel
assert_eq!(scale::zoom_step(1.0, 1), 1.1);
assert_eq!(scale::zoom_step(2.0, 1), 2.0);

Structs§

Scale
The scales of the window being drawn.

Constants§

ZOOM_STEPS
The interface zoom’s steps.

Functions§

changed
The current window’s scale change this pass: (old, new) pixels per point, or None. Asked any number of times in one pass, it answers the same; the first pass of a window reports no change.
disable_keyboard_zoom
Turns off egui’s own zoom keys (Ctrl and +, -, 0), which would fire together with an application’s content zoom; egui-pop’s interface zoom commands replace them.
hairline
One physical pixel, in points, in the current window.
snap
A width of w points snapped at ppp: a whole number of physical pixels, at least one, back in points. A width of zero (or less) stays zero: a stroke set to nothing is not drawn as a hairline.
snap_size
A side of s points rounded to whole physical pixels (an icon’s box).
stroke
A stroke width of w points that stays crisp in the current window.
zoom_step
The zoom step by steps from current (the nearest step first), clamped to the ends.