use oxivgl_sys::*;
pub struct DrawRectDsc {
pub(crate) inner: lv_draw_rect_dsc_t,
}
impl DrawRectDsc {
pub fn new() -> Self {
let mut inner = unsafe { core::mem::zeroed() };
unsafe { lv_draw_rect_dsc_init(&mut inner) };
Self { inner }
}
pub fn bg_color(&mut self, color: lv_color_t) -> &mut Self {
self.inner.bg_color = color;
self
}
pub fn radius(&mut self, r: i32) -> &mut Self {
self.inner.radius = r;
self
}
pub fn border_color(&mut self, color: lv_color_t) -> &mut Self {
self.inner.border_color = color;
self
}
pub fn border_width(&mut self, w: i32) -> &mut Self {
self.inner.border_width = w;
self
}
pub fn outline_color(&mut self, color: lv_color_t) -> &mut Self {
self.inner.outline_color = color;
self
}
pub fn outline_width(&mut self, w: i32) -> &mut Self {
self.inner.outline_width = w;
self
}
pub fn outline_pad(&mut self, pad: i32) -> &mut Self {
self.inner.outline_pad = pad;
self
}
pub fn bg_grad_dir(&mut self, dir: crate::style::GradDir) -> &mut Self {
self.inner.bg_grad.set_dir(dir as lv_grad_dir_t);
self
}
pub fn bg_grad_stop(&mut self, idx: usize, color: lv_color_t, frac: u8, opa: u8) -> &mut Self {
assert!(idx < 2, "gradient stop index must be 0 or 1");
self.inner.bg_grad.stops[idx].color = color;
self.inner.bg_grad.stops[idx].frac = frac;
self.inner.bg_grad.stops[idx].opa = opa;
self
}
pub fn bg_opa(&mut self, opa: u8) -> &mut Self {
self.inner.bg_opa = opa;
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_rect_dsc_t {
&self.inner
}
}
impl Default for DrawRectDsc {
fn default() -> Self {
Self::new()
}
}
pub struct DrawLabelDscOwned {
pub(crate) inner: lv_draw_label_dsc_t,
}
impl DrawLabelDscOwned {
pub fn default_font() -> Self {
let mut inner = unsafe { core::mem::zeroed() };
unsafe { lv_draw_label_dsc_init(&mut inner) };
inner.font = unsafe { lv_font_get_default() };
Self { inner }
}
pub fn set_color(&mut self, color: lv_color_t) -> &mut Self {
self.inner.color = color;
self
}
pub fn set_font(&mut self, font: crate::fonts::Font) -> &mut Self {
self.inner.font = font.as_ptr();
self
}
pub fn set_align(&mut self, align: crate::widgets::TextAlign) -> &mut Self {
self.inner.align = align as lv_text_align_t;
self
}
pub fn text_size(&self, text: &str) -> (i32, i32) {
let mut buf = [0u8; 64];
let len = text.len().min(buf.len() - 1);
buf[..len].copy_from_slice(&text.as_bytes()[..len]);
buf[len] = 0;
let mut size: lv_point_t = unsafe { core::mem::zeroed() };
unsafe {
lv_text_get_size(
&mut size,
buf.as_ptr() as *const core::ffi::c_char,
self.inner.font,
self.inner.letter_space,
self.inner.line_space,
0x7FFF,
lv_text_flag_t_LV_TEXT_FLAG_NONE,
);
}
(size.x, size.y)
}
}
pub struct DrawArcDsc {
inner: lv_draw_arc_dsc_t,
}
impl DrawArcDsc {
pub fn new() -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_arc_dsc_t>() };
unsafe { lv_draw_arc_dsc_init(&mut inner) };
Self { inner }
}
pub fn center(&mut self, x: i32, y: i32) -> &mut Self {
self.inner.center.x = x;
self.inner.center.y = y;
self
}
pub fn radius(&mut self, r: u16) -> &mut Self {
self.inner.radius = r;
self
}
pub fn angles(&mut self, start: f32, end: f32) -> &mut Self {
self.inner.start_angle = start;
self.inner.end_angle = end;
self
}
pub fn width(&mut self, w: i32) -> &mut Self {
self.inner.width = w;
self
}
pub fn color(&mut self, c: lv_color_t) -> &mut Self {
self.inner.color = c;
self
}
pub fn opa(&mut self, o: u8) -> &mut Self {
self.inner.opa = o;
self
}
pub fn rounded(&mut self, r: bool) -> &mut Self {
self.inner.set_rounded(r as u8);
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_arc_dsc_t {
&self.inner
}
}
impl Default for DrawArcDsc {
fn default() -> Self {
Self::new()
}
}
pub struct DrawLineDsc {
inner: lv_draw_line_dsc_t,
}
impl DrawLineDsc {
pub fn new() -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_line_dsc_t>() };
unsafe { lv_draw_line_dsc_init(&mut inner) };
Self { inner }
}
pub fn p1(&mut self, x: f32, y: f32) -> &mut Self {
self.inner.p1.x = x;
self.inner.p1.y = y;
self
}
pub fn p2(&mut self, x: f32, y: f32) -> &mut Self {
self.inner.p2.x = x;
self.inner.p2.y = y;
self
}
pub fn width(&mut self, w: i32) -> &mut Self {
self.inner.width = w;
self
}
pub fn color(&mut self, c: lv_color_t) -> &mut Self {
self.inner.color = c;
self
}
pub fn opa(&mut self, o: u8) -> &mut Self {
self.inner.opa = o;
self
}
pub fn round_start(&mut self, r: bool) -> &mut Self {
self.inner.set_round_start(r as u8);
self
}
pub fn round_end(&mut self, r: bool) -> &mut Self {
self.inner.set_round_end(r as u8);
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_line_dsc_t {
&self.inner
}
}
impl Default for DrawLineDsc {
fn default() -> Self {
Self::new()
}
}
pub struct DrawTriangleDsc {
inner: lv_draw_triangle_dsc_t,
}
impl DrawTriangleDsc {
pub fn new() -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_triangle_dsc_t>() };
unsafe { lv_draw_triangle_dsc_init(&mut inner) };
Self { inner }
}
pub fn points(&mut self, pts: [(f32, f32); 3]) -> &mut Self {
for (i, (x, y)) in pts.iter().enumerate() {
self.inner.p[i].x = *x;
self.inner.p[i].y = *y;
}
self
}
pub fn opa(&mut self, o: u8) -> &mut Self {
self.inner.opa = o;
self
}
pub fn color(&mut self, c: lv_color_t) -> &mut Self {
self.inner.color = c;
self
}
pub fn grad_stops_count(&mut self, n: u8) -> &mut Self {
self.inner.grad.stops_count = n;
self
}
pub fn grad_dir(&mut self, dir: crate::style::GradDir) -> &mut Self {
self.inner.grad.set_dir(dir as lv_grad_dir_t);
self
}
pub fn grad_stop(&mut self, idx: usize, color: lv_color_t, frac: u8, opa: u8) -> &mut Self {
assert!(idx < 2, "gradient stop index must be 0 or 1");
self.inner.grad.stops[idx].color = color;
self.inner.grad.stops[idx].frac = frac;
self.inner.grad.stops[idx].opa = opa;
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_triangle_dsc_t {
&self.inner
}
}
impl Default for DrawTriangleDsc {
fn default() -> Self {
Self::new()
}
}
pub struct DrawImageDsc<'i> {
inner: lv_draw_image_dsc_t,
_img_lifetime: core::marker::PhantomData<&'i ()>,
}
impl<'i> DrawImageDsc<'i> {
pub fn from_image_dsc(img: &'i crate::draw_buf::ImageDsc<'_>) -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_image_dsc_t>() };
unsafe { lv_draw_image_dsc_init(&mut inner) };
inner.src = &img.inner as *const lv_image_dsc_t as *const core::ffi::c_void;
Self { inner, _img_lifetime: core::marker::PhantomData }
}
pub fn from_static_dsc(img: &'i lv_image_dsc_t) -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_image_dsc_t>() };
unsafe { lv_draw_image_dsc_init(&mut inner) };
inner.src = img as *const lv_image_dsc_t as *const core::ffi::c_void;
Self { inner, _img_lifetime: core::marker::PhantomData }
}
pub fn rotation(&mut self, r: i32) -> &mut Self {
self.inner.rotation = r;
self
}
pub fn pivot(&mut self, x: i32, y: i32) -> &mut Self {
self.inner.pivot.x = x;
self.inner.pivot.y = y;
self
}
pub fn opa(&mut self, o: u8) -> &mut Self {
self.inner.opa = o;
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_image_dsc_t {
&self.inner
}
}
pub struct DrawLetterDsc {
inner: lv_draw_letter_dsc_t,
}
impl DrawLetterDsc {
pub fn new() -> Self {
let mut inner = unsafe { core::mem::zeroed::<lv_draw_letter_dsc_t>() };
unsafe { lv_draw_letter_dsc_init(&mut inner) };
Self { inner }
}
pub fn unicode(&mut self, cp: u32) -> &mut Self {
self.inner.unicode = cp;
self
}
pub fn color(&mut self, c: lv_color_t) -> &mut Self {
self.inner.color = c;
self
}
pub fn font(&mut self, f: crate::fonts::Font) -> &mut Self {
self.inner.font = f.as_ptr();
self
}
pub fn rotation(&mut self, r: i32) -> &mut Self {
self.inner.rotation = r;
self
}
pub fn opa(&mut self, o: u8) -> &mut Self {
self.inner.opa = o;
self
}
pub(crate) fn as_ptr(&self) -> *const lv_draw_letter_dsc_t {
&self.inner
}
}
impl Default for DrawLetterDsc {
fn default() -> Self {
Self::new()
}
}