use alloc::rc::Rc;
use core::ptr::null_mut;
use oxivgl_sys::*;
use super::obj::Obj;
impl<'p> Obj<'p> {
pub fn bg_color(&self, color: u32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_color(self.handle(), lv_color_hex(color), 0) };
self
}
pub fn bg_opa(&self, opa: u8) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_opa(self.handle(), opa as lv_opa_t, 0) };
self
}
pub fn bg_opa_selector(&self, opa: u8, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_opa(self.handle(), opa as lv_opa_t, selector) };
self
}
pub fn border_width(&self, w: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_border_width(self.handle(), w, 0) };
self
}
pub fn pad(&self, p: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_all(self.handle(), p, 0) };
self
}
pub fn pad_top(&self, p: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_top(self.handle(), p, 0) };
self
}
pub fn pad_bottom(&self, p: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_bottom(self.handle(), p, 0) };
self
}
pub fn pad_left(&self, p: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_left(self.handle(), p, 0) };
self
}
pub fn pad_right(&self, p: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_right(self.handle(), p, 0) };
self
}
pub fn style_pad_hor(&self, p: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_hor(self.handle(), p, selector) };
self
}
pub fn add_style(&self, style: &crate::style::Style, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
self._styles.borrow_mut().push(style.clone());
unsafe { lv_obj_add_style(self.handle(), style.lv_ptr(), selector) };
self
}
pub fn remove_style_all(&self) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_remove_style_all(self.handle()) };
self._styles.borrow_mut().clear();
self
}
pub fn remove_style(
&self,
style: Option<&crate::style::Style>,
selector: impl Into<crate::style::Selector>,
) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
let style_ptr = match style {
Some(s) => s.lv_ptr() as *mut lv_style_t,
None => null_mut() as *mut lv_style_t,
};
unsafe { lv_obj_remove_style(self.handle(), style_ptr, selector) };
if let Some(s) = style {
let target = Rc::as_ptr(&s.inner);
let mut styles = self._styles.borrow_mut();
if let Some(pos) = styles.iter().position(|e| Rc::as_ptr(&e.inner) == target) {
styles.remove(pos);
}
}
self
}
pub fn style_clip_corner(&self, clip: bool, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_clip_corner(self.handle(), clip, selector) };
self
}
pub fn style_translate_x(&self, x: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_translate_x(self.handle(), x, selector) };
self
}
pub fn text_color(&self, color: u32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_text_color(self.handle(), lv_color_hex(color), 0) };
self
}
pub fn text_font(&self, font: crate::fonts::Font) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
assert_ne!(font.as_ptr(), null_mut(), "Font pointer cannot be null");
unsafe { lv_obj_set_style_text_font(self.handle(), font.as_ptr(), 0) };
self
}
pub fn font(&self, font: crate::fonts::Font) -> &Self {
self.text_font(font)
}
pub fn text_align(&self, align: super::obj::TextAlign) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_text_align(self.handle(), align as lv_text_align_t, 0) };
self
}
pub fn opa(&self, opa: u8) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_opa(self.handle(), opa as lv_opa_t, 0) };
self
}
pub fn style_opa(&self, opa: u8, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_opa(self.handle(), opa as lv_opa_t, selector) };
self
}
pub fn style_pad_all(&self, p: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_all(self.handle(), p, selector) };
self
}
pub fn radius(&self, r: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_radius(self.handle(), r, selector) };
self
}
pub fn style_bg_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_color(self.handle(), color, selector) };
self
}
pub fn style_bg_grad_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_grad_color(self.handle(), color, selector) };
self
}
pub fn style_bg_grad_dir(&self, dir: crate::style::GradDir, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_grad_dir(self.handle(), dir as lv_grad_dir_t, selector) };
self
}
pub fn style_transform_rotation(&self, angle: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_transform_rotation(self.handle(), angle, selector) };
self
}
pub fn style_transform_scale(&self, scale: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe {
lv_obj_set_style_transform_scale_x(self.handle(), scale, selector);
lv_obj_set_style_transform_scale_y(self.handle(), scale, selector);
};
self
}
pub fn style_transform_pivot_x(&self, x: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_transform_pivot_x(self.handle(), x, selector) };
self
}
pub fn style_transform_pivot_y(&self, y: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_transform_pivot_y(self.handle(), y, selector) };
self
}
pub fn style_base_dir(&self, dir: super::obj::BaseDir, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_base_dir(self.handle(), dir as lv_base_dir_t, selector) };
self
}
pub fn line_width(&self, part: super::obj::Part, width: i32) -> &Self {
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_line_width(self.handle(), width, part as u32) };
self
}
pub fn style_image_recolor(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_image_recolor(self.handle(), color, selector) };
self
}
pub fn style_radial_offset(&self, offset: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_radial_offset(self.handle(), offset, selector) };
self
}
pub fn style_line_opa(&self, opa: u8, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_line_opa(self.handle(), opa as lv_opa_t, selector) };
self
}
pub fn style_text_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_text_color(self.handle(), color, selector) };
self
}
pub fn style_text_font(&self, font: crate::fonts::Font, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
assert_ne!(font.as_ptr(), null_mut(), "Font pointer cannot be null");
unsafe { lv_obj_set_style_text_font(self.handle(), font.as_ptr(), selector) };
self
}
pub fn style_arc_width(&self, width: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_arc_width(self.handle(), width, selector) };
self
}
pub fn style_arc_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_arc_color(self.handle(), color, selector) };
self
}
pub fn style_arc_rounded(&self, rounded: bool, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_arc_rounded(self.handle(), rounded, selector) };
self
}
pub fn style_line_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_line_color(self.handle(), color, selector) };
self
}
pub fn style_length(&self, length: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_length(self.handle(), length, selector) };
self
}
pub fn style_line_width(&self, width: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_line_width(self.handle(), width, selector) };
self
}
pub fn style_width(&self, width: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_width(self.handle(), width, selector) };
self
}
pub fn style_image_recolor_opa(&self, opa: u8, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_image_recolor_opa(self.handle(), opa as lv_opa_t, selector) };
self
}
pub fn style_pad_column(&self, gap: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_column(self.handle(), gap, selector) };
self
}
pub fn style_pad_row(&self, gap: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_pad_row(self.handle(), gap, selector) };
self
}
pub fn style_size(&self, w: i32, h: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_size(self.handle(), w, h, selector) };
self
}
pub fn style_bg_image_src_symbol(
&self,
symbol: &crate::symbols::Symbol,
selector: impl Into<crate::style::Selector>,
) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_bg_image_src(self.handle(), symbol.as_ptr() as *const core::ffi::c_void, selector) };
self
}
pub fn style_shadow_width(&self, w: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_width(self.handle(), w, selector) };
self
}
pub fn style_shadow_color(&self, color: lv_color_t, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_color(self.handle(), color, selector) };
self
}
pub fn style_shadow_offset_x(&self, x: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_offset_x(self.handle(), x, selector) };
self
}
pub fn style_shadow_offset_y(&self, y: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_offset_y(self.handle(), y, selector) };
self
}
pub fn style_shadow_spread(&self, s: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_spread(self.handle(), s, selector) };
self
}
pub fn style_shadow_opa(&self, opa: u8, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_shadow_opa(self.handle(), opa as lv_opa_t, selector) };
self
}
pub fn style_transform_scale_x(&self, scale: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_transform_scale_x(self.handle(), scale, selector) };
self
}
pub fn style_transform_scale_y(&self, scale: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_transform_scale_y(self.handle(), scale, selector) };
self
}
pub fn style_text_letter_space(&self, space: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_text_letter_space(self.handle(), space, selector) };
self
}
pub fn style_blur_radius(&self, r: i32, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_blur_radius(self.handle(), r, selector) };
self
}
pub fn style_blur_backdrop(&self, en: bool, selector: impl Into<crate::style::Selector>) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe { lv_obj_set_style_blur_backdrop(self.handle(), en, selector) };
self
}
pub unsafe fn style_bitmap_mask_src(
&self,
mask: &crate::draw_buf::DrawBuf,
selector: impl Into<crate::style::Selector>,
) -> &Self {
let selector = selector.into().raw();
assert_ne!(self.handle(), null_mut(), "Obj handle cannot be null");
unsafe {
lv_obj_set_style_bitmap_mask_src(
self.handle(),
mask.as_ptr() as *const core::ffi::c_void,
selector,
)
};
self
}
}