From f184a40877cb1d4ecd77da3141776ea79c3047fe Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 25 Jan 2024 21:25:50 -0800 Subject: [PATCH] Minor edits --- crates/render/src/ui/util/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/render/src/ui/util/mod.rs b/crates/render/src/ui/util/mod.rs index b3d8880..1d5bcf4 100644 --- a/crates/render/src/ui/util/mod.rs +++ b/crates/render/src/ui/util/mod.rs @@ -9,6 +9,7 @@ use nalgebra::{Point2, Vector2}; use crate::{RenderInput, RenderState}; /// Represents a rectangular region inside a sprite. +#[derive(Debug, Clone, Copy)] pub(crate) struct SpriteRect { /// The position of the top-left corner of this rectangle, in fractional units. /// (0.0 is left edge of sprite, 1.0 is right edge) @@ -19,6 +20,18 @@ pub(crate) struct SpriteRect { pub dim: Vector2, } +impl SpriteRect { + /// Northeast corner of this rect + pub fn ne_corner(&self) -> Point2 { + self.pos + Vector2::new(-self.dim.x, self.dim.y) / 2.0 + } + + /// Southwest corner of this rect + pub fn sw_corner(&self) -> Point2 { + self.pos + Vector2::new(self.dim.x, -self.dim.y) / 2.0 + } +} + pub(super) trait UiElement { fn push_to_buffer_child( &self,