use iced_core::{Point, Rectangle};
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Offset {
pub x: f32,
pub y: f32,
}
impl Offset {
pub const ZERO: Offset = Offset { x: 0.0, y: 0.0 };
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
#[inline]
pub fn offset_rect(&self, rect: &Rectangle) -> Rectangle {
Rectangle {
x: rect.x + self.x,
y: rect.y + self.y,
width: rect.width,
height: rect.height,
}
}
#[inline]
pub fn offset_rect_mut(&self, rect: &mut Rectangle) {
rect.x += self.x;
rect.y += self.y;
}
}
impl Default for Offset {
fn default() -> Self {
Offset::ZERO
}
}
impl From<Offset> for Point {
fn from(offset: Offset) -> Self {
Point {
x: offset.x,
y: offset.y,
}
}
}