emath::gui_rounding

Trait GuiRounding

Source
pub trait GuiRounding {
    // Required methods
    fn round_ui(self) -> Self;
    fn floor_ui(self) -> Self;
    fn round_to_pixels(self, pixels_per_point: f32) -> Self;
    fn round_to_pixel_center(self, pixels_per_point: f32) -> Self;
}
Expand description

Trait for rounding coordinates and sizes to align with either .

See GuiRounding::round_ui for more information.

Required Methods§

Source

fn round_ui(self) -> Self

Rounds floating point numbers to an even multiple of the GUI rounding factor, crate::GUI_ROUNDING.

Use this for widget coordinates and sizes.

Rounding sizes and positions prevent rounding errors when doing sizing calculations. We don’t round to integers, because that would be too coarse (causing visible juddering when scrolling, for instance). Instead we round to an even multiple of GUI_ROUNDING.

Source

fn floor_ui(self) -> Self

Like Self::round_ui, but always rounds towards negative infinity.

Source

fn round_to_pixels(self, pixels_per_point: f32) -> Self

Round a size or position to an even multiple of the physical pixel size.

This can be useful for crisp rendering.

The self should be in coordinates of logical UI points. The argument pixels_per_point is the number of physical pixels per logical UI point. For instance, on a high-DPI screen, pixels_per_point could be 2.0.

Source

fn round_to_pixel_center(self, pixels_per_point: f32) -> Self

Will round the position to be in the center of a pixel.

The pixel size is 1.0 / pixels_per_point.

So if pixels_per_point = 2 (i.e. pixel size = 0.5), then the position will be rounded to the closest of …, 0.25, 0.75, 1.25, ….

This is useful, for instance, when picking the center of a line that is one pixel wide.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl GuiRounding for f32

Source§

fn round_ui(self) -> Self

Source§

fn floor_ui(self) -> Self

Source§

fn round_to_pixels(self, pixels_per_point: f32) -> Self

Source§

fn round_to_pixel_center(self, pixels_per_point: f32) -> Self

Source§

impl GuiRounding for f64

Source§

fn round_ui(self) -> Self

Source§

fn floor_ui(self) -> Self

Source§

fn round_to_pixels(self, pixels_per_point: f32) -> Self

Source§

fn round_to_pixel_center(self, pixels_per_point: f32) -> Self

Implementors§