use oxivgl_sys::*;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Area {
pub x1: i32,
pub y1: i32,
pub x2: i32,
pub y2: i32,
}
impl Area {
pub fn width(&self) -> i32 {
self.x2 - self.x1 + 1
}
pub fn height(&self) -> i32 {
self.y2 - self.y1 + 1
}
pub fn set_width_centered(&mut self, new_w: i32) {
let old_w = self.width();
let delta = new_w - old_w;
self.x1 -= delta / 2;
self.x2 += (delta + 1) / 2;
}
pub fn align_to_area(&mut self, base: Area, align: crate::widgets::Align, ofs_x: i32, ofs_y: i32) {
let base_lv: lv_area_t = base.into();
let mut self_lv: lv_area_t = (*self).into();
unsafe { lv_area_align(&base_lv, &mut self_lv, align as lv_align_t, ofs_x, ofs_y) };
*self = self_lv.into();
}
pub fn set_width(&mut self, new_w: i32) {
self.x2 = self.x1 + new_w - 1;
}
}
impl From<lv_area_t> for Area {
fn from(a: lv_area_t) -> Self {
Self { x1: a.x1, y1: a.y1, x2: a.x2, y2: a.y2 }
}
}
impl From<Area> for lv_area_t {
fn from(a: Area) -> Self {
Self { x1: a.x1, y1: a.y1, x2: a.x2, y2: a.y2 }
}
}
pub const RADIUS_CIRCLE: i32 = 0x7FFF;