Expose RGB values from Color #29

Merged
rafaelcaricio merged 1 commit from expose-rgb-values into master 2020-08-27 09:40:09 +00:00

View file

@ -27,6 +27,24 @@ impl Color {
pub fn from_raw(raw: lvgl_sys::lv_color_t) -> Self {
Self { raw }
}
pub fn r(&self) -> u8 {
unsafe {
lvgl_sys::_LV_COLOR_GET_R(self.raw) as u8
}
}
pub fn g(&self) -> u8 {
unsafe {
lvgl_sys::_LV_COLOR_GET_G(self.raw) as u8
}
}
pub fn b(&self) -> u8 {
unsafe {
lvgl_sys::_LV_COLOR_GET_B(self.raw) as u8
}
}
}
impl From<Color> for Rgb888 {
@ -231,3 +249,25 @@ impl From<Animation> for lvgl_sys::lv_anim_enable_t {
}
}
}
#[cfg(test)]
mod test {
use super::*;
use lvgl_sys;
#[test]
fn color_properties_accessible() {
let color = Color::from_rgb((206, 51, 255));
if lvgl_sys::LV_COLOR_DEPTH == 32 {
assert_eq!(color.r(), 206);
assert_eq!(color.g(), 51);
assert_eq!(color.b(), 255);
} else if lvgl_sys::LV_COLOR_DEPTH == 16 {
assert_eq!(color.r(), 25);
assert_eq!(color.g(), 12);
assert_eq!(color.b(), 31);
}
}
}