Add #[inline(always)] here and there

This commit is contained in:
Emil Ernerfeldt 2021-04-19 23:11:42 +02:00
parent 0f1df90d90
commit 1681769329
4 changed files with 24 additions and 0 deletions

View file

@ -455,6 +455,7 @@ impl Context {
} }
/// The number of physical pixels for each logical point. /// The number of physical pixels for each logical point.
#[inline(always)]
pub fn pixels_per_point(&self) -> f32 { pub fn pixels_per_point(&self) -> f32 {
self.input.pixels_per_point() self.input.pixels_per_point()
} }

View file

@ -110,6 +110,7 @@ impl InputState {
} }
} }
#[inline(always)]
pub fn screen_rect(&self) -> Rect { pub fn screen_rect(&self) -> Rect {
self.screen_rect self.screen_rect
} }
@ -160,17 +161,20 @@ impl InputState {
} }
/// Also known as device pixel ratio, > 1 for high resolution screens. /// Also known as device pixel ratio, > 1 for high resolution screens.
#[inline(always)]
pub fn pixels_per_point(&self) -> f32 { pub fn pixels_per_point(&self) -> f32 {
self.pixels_per_point self.pixels_per_point
} }
/// Size of a physical pixel in logical gui coordinates (points). /// Size of a physical pixel in logical gui coordinates (points).
#[inline(always)]
pub fn physical_pixel_size(&self) -> f32 { pub fn physical_pixel_size(&self) -> f32 {
1.0 / self.pixels_per_point() 1.0 / self.pixels_per_point()
} }
/// How imprecise do we expect the mouse/touch input to be? /// How imprecise do we expect the mouse/touch input to be?
/// Returns imprecision in points. /// Returns imprecision in points.
#[inline(always)]
pub fn aim_radius(&self) -> f32 { pub fn aim_radius(&self) -> f32 {
// TODO: multiply by ~3 for touch inputs because fingers are fat // TODO: multiply by ~3 for touch inputs because fingers are fat
self.physical_pixel_size() self.physical_pixel_size()
@ -488,10 +492,12 @@ impl PointerState {
// } // }
/// Is this button currently down? /// Is this button currently down?
#[inline(always)]
pub fn button_down(&self, button: PointerButton) -> bool { pub fn button_down(&self, button: PointerButton) -> bool {
self.down[button as usize] self.down[button as usize]
} }
#[inline(always)]
pub(crate) fn could_any_button_be_click(&self) -> bool { pub(crate) fn could_any_button_be_click(&self) -> bool {
self.could_be_click self.could_be_click
} }

View file

@ -83,43 +83,51 @@ impl Painter {
/// ## Accessors etc /// ## Accessors etc
impl Painter { impl Painter {
#[inline(always)]
pub(crate) fn ctx(&self) -> &CtxRef { pub(crate) fn ctx(&self) -> &CtxRef {
&self.ctx &self.ctx
} }
/// Available fonts /// Available fonts
#[inline(always)]
pub(crate) fn fonts(&self) -> &Fonts { pub(crate) fn fonts(&self) -> &Fonts {
self.ctx.fonts() self.ctx.fonts()
} }
/// Where we paint /// Where we paint
#[inline(always)]
pub fn layer_id(&self) -> LayerId { pub fn layer_id(&self) -> LayerId {
self.layer_id self.layer_id
} }
/// Everything painted in this `Painter` will be clipped against this. /// Everything painted in this `Painter` will be clipped against this.
/// This means nothing outside of this rectangle will be visible on screen. /// This means nothing outside of this rectangle will be visible on screen.
#[inline(always)]
pub fn clip_rect(&self) -> Rect { pub fn clip_rect(&self) -> Rect {
self.clip_rect self.clip_rect
} }
/// Everything painted in this `Painter` will be clipped against this. /// Everything painted in this `Painter` will be clipped against this.
/// This means nothing outside of this rectangle will be visible on screen. /// This means nothing outside of this rectangle will be visible on screen.
#[inline(always)]
pub fn set_clip_rect(&mut self, clip_rect: Rect) { pub fn set_clip_rect(&mut self, clip_rect: Rect) {
self.clip_rect = clip_rect; self.clip_rect = clip_rect;
} }
/// Useful for pixel-perfect rendering /// Useful for pixel-perfect rendering
#[inline(always)]
pub fn round_to_pixel(&self, point: f32) -> f32 { pub fn round_to_pixel(&self, point: f32) -> f32 {
self.ctx().round_to_pixel(point) self.ctx().round_to_pixel(point)
} }
/// Useful for pixel-perfect rendering /// Useful for pixel-perfect rendering
#[inline(always)]
pub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2 { pub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2 {
self.ctx().round_vec_to_pixels(vec) self.ctx().round_vec_to_pixels(vec)
} }
/// Useful for pixel-perfect rendering /// Useful for pixel-perfect rendering
#[inline(always)]
pub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2 { pub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2 {
self.ctx().round_pos_to_pixels(pos) self.ctx().round_pos_to_pixels(pos)
} }

View file

@ -99,11 +99,13 @@ impl Ui {
// ------------------------------------------------- // -------------------------------------------------
/// A unique identity of this `Ui`. /// A unique identity of this `Ui`.
#[inline(always)]
pub fn id(&self) -> Id { pub fn id(&self) -> Id {
self.id self.id
} }
/// Style options for this `Ui` and its children. /// Style options for this `Ui` and its children.
#[inline(always)]
pub fn style(&self) -> &std::sync::Arc<Style> { pub fn style(&self) -> &std::sync::Arc<Style> {
&self.style &self.style
} }
@ -131,6 +133,7 @@ impl Ui {
/// The current spacing options for this `Ui`. /// The current spacing options for this `Ui`.
/// Short for `ui.style().spacing`. /// Short for `ui.style().spacing`.
#[inline(always)]
pub fn spacing(&self) -> &crate::style::Spacing { pub fn spacing(&self) -> &crate::style::Spacing {
&self.style.spacing &self.style.spacing
} }
@ -149,6 +152,7 @@ impl Ui {
/// The current visuals settings of this `Ui`. /// The current visuals settings of this `Ui`.
/// Short for `ui.style().visuals`. /// Short for `ui.style().visuals`.
#[inline(always)]
pub fn visuals(&self) -> &crate::Visuals { pub fn visuals(&self) -> &crate::Visuals {
&self.style.visuals &self.style.visuals
} }
@ -168,17 +172,20 @@ impl Ui {
} }
/// Get a reference to the parent [`CtxRef`]. /// Get a reference to the parent [`CtxRef`].
#[inline(always)]
pub fn ctx(&self) -> &CtxRef { pub fn ctx(&self) -> &CtxRef {
self.painter.ctx() self.painter.ctx()
} }
/// Use this to paint stuff within this `Ui`. /// Use this to paint stuff within this `Ui`.
#[inline(always)]
pub fn painter(&self) -> &Painter { pub fn painter(&self) -> &Painter {
&self.painter &self.painter
} }
/// If `false`, the `Ui` does not allow any interaction and /// If `false`, the `Ui` does not allow any interaction and
/// the widgets in it will draw with a gray look. /// the widgets in it will draw with a gray look.
#[inline(always)]
pub fn enabled(&self) -> bool { pub fn enabled(&self) -> bool {
self.enabled self.enabled
} }
@ -210,6 +217,7 @@ impl Ui {
} }
} }
#[inline(always)]
pub fn layout(&self) -> &Layout { pub fn layout(&self) -> &Layout {
self.placer.layout() self.placer.layout()
} }
@ -242,6 +250,7 @@ impl Ui {
/// The `Input` of the `Context` associated with the `Ui`. /// The `Input` of the `Context` associated with the `Ui`.
/// Equivalent to `.ctx().input()`. /// Equivalent to `.ctx().input()`.
#[inline(always)]
pub fn input(&self) -> &InputState { pub fn input(&self) -> &InputState {
self.ctx().input() self.ctx().input()
} }