graphics/
rectangled.rs

1use crate::{
2    math::{margin_rectangle, relative_rectangle, Scalar},
3    types::Rectangle,
4};
5
6/// Should be implemented by contexts that have rectangle information.
7pub trait Rectangled: Sized {
8    /// Shrinks the current rectangle equally by all sides.
9    fn margin(self, m: Scalar) -> Self;
10
11    /// Expands the current rectangle equally by all sides.
12    #[inline(always)]
13    fn expand(self, m: Scalar) -> Self {
14        self.margin(-m)
15    }
16
17    /// Moves to a relative rectangle using the current rectangle as tile.
18    fn rel(self, x: Scalar, y: Scalar) -> Self;
19}
20
21impl Rectangled for Rectangle {
22    #[inline(always)]
23    fn margin(self, m: Scalar) -> Self {
24        margin_rectangle(self, m)
25    }
26
27    #[inline(always)]
28    fn rel(self, x: Scalar, y: Scalar) -> Self {
29        relative_rectangle(self, [x, y])
30    }
31}