Trait rerun::external::eframe::egui::epaint::emath::GuiRounding

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§

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.

fn floor_ui(self) -> Self

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

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.

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl GuiRounding for f32

§

fn round_ui(self) -> f32

§

fn floor_ui(self) -> f32

§

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

§

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

§

impl GuiRounding for f64

§

fn round_ui(self) -> f64

§

fn floor_ui(self) -> f64

§

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

§

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

Implementors§