1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#[derive(Debug, Clone, Copy, PartialEq)] pub struct Rect { pub x: u16, pub y: u16, pub width: u16, pub height: u16, } impl Rect { pub fn new(x: u16, y: u16, width: u16, height: u16) -> Self { Self { x, y, width, height, } } pub fn default() -> Self { Self { x: 0, y: 0, width: 0, height: 0, } } pub fn x(&self, x: u16) -> Self { Self::new(x, self.y, self.width, self.height) } pub fn y(&self, y: u16) -> Self { Self::new(self.x, y, self.width, self.height) } pub fn w(&self, w: u16) -> Self { Self::new(self.x, self.y, w, self.height) } pub fn h(&self, h: u16) -> Self { Self::new(self.x, self.y, self.width, h) } }