Compare commits

..

1 commit

Author SHA1 Message Date
76d485b68a
Compile to WASM using emscripten 2020-09-21 20:01:31 +02:00
22 changed files with 436 additions and 1305 deletions

View file

@ -1,6 +1,7 @@
[workspace] [workspace]
members = [ members = [
"lvgl", "lvgl",
"lvgl-codegen",
"lvgl-sys", "lvgl-sys",
"lvgl-codegen",
"examples"
] ]

View file

@ -1,41 +1,24 @@
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md) <h1 align="center"> LittlevGL - Open-source Embedded GUI Library in Rust</h1>
<h1 align="center"> LVGL - Open-source Embedded GUI Library in Rust</h1> ![Original LittlevGL demo image](lv_demo.png)
![Original LVGL demo image](lv_demo.png)
<p align="center"> <p align="center">
LVGL provides everything you need to create a Graphical User Interface (GUI) on embedded systems with easy-to-use graphical elements, beautiful visual effects and low memory footprint. LittlevGL provides everything you need to create a Graphical User Interface (GUI) on embedded systems with easy-to-use graphical elements, beautiful visual effects and low memory footprint.
</p> </p>
<p align="center"> <p align="center">
LVGL is compatible with <samp>#![no_std]</samp> environments by default. LittlevGL is compatible with <samp>#![no_std]</samp> environments by default.
</p> </p>
<h4 align="center"> <h4 align="center">
<a href="https://github.com/rafaelcaricio/lvgl-rs-wasm">Rust to WASM demo</a> &middot; <a href="https://lvgl.io/">Official LittlevGL Website </a> &middot;
<a href="https://lvgl.io/">Official LVGL Website </a> &middot;
<a href="https://github.com/littlevgl/lvgl">C library repository</a> &middot; <a href="https://github.com/littlevgl/lvgl">C library repository</a> &middot;
<a href="https://lvgl.io/demos">Official live demos</a> <a href="https://lvgl.io/demos">Live demo</a>
</h4> </h4>
--- ---
![Rust bindings usage demo code.](demo.png) ![Rust bindings usage demo code.](demo.png)
## System Build Dependencies
In order to build the `lvgl` project you will need the following system dependencies to be installed:
```
$ sudo apt install build-essential llvm clang
```
If you want to build the examples, then you will need to install SDL2 as well.
```
$ sudo apt install libsdl2-dev
```
## Usage ## Usage
Edit your `Cargo.toml` file dependencies with: Edit your `Cargo.toml` file dependencies with:
@ -45,7 +28,7 @@ $ cargo add lvgl
The build requires the environment variable bellow to be set: The build requires the environment variable bellow to be set:
- `DEP_LV_CONFIG_PATH`: Path to the directory containing the `lv_conf.h` header file used for configuration of LVGL library. - `DEP_LV_CONFIG_PATH`: Path to the directory containing the `lv_conf.h` header file used for configuration of LittlevGL library.
We recommend the `lv_conf.h` file to be in your project's root directory. If so, the command to build your project would be: We recommend the `lv_conf.h` file to be in your project's root directory. If so, the command to build your project would be:
```shell script ```shell script
@ -61,22 +44,9 @@ for `no_std`, so we need to use a workaround to build "lvgl-rs". The mainstrem i
```shell ```shell
$ DEP_LV_CONFIG_PATH=`pwd` cargo build -Zfeatures=build_dep $ DEP_LV_CONFIG_PATH=`pwd` cargo build -Zfeatures=build_dep
``` ```
### LVGL Global Allocator
A [global allocator](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) for Rust leveraging the
[LVGL memory allocator](https://github.com/lvgl/lvgl/blob/master/src/misc/lv_mem.h) is provided, but not enabled
by default. Can be enabled by the feature `lvgl_alloc`. This will make all dynamic memory to be allocated by LVGL
internal memory manager.
## Running the demo ## Running the demo
**Hint for macOS users**: Before you run the demos you need to make sure you have [libsdl](https://www.libsdl.org)
installed on your machine. To install it, use HomeBrew:
```shell
$ brew install sdl2
```
[This project contains examples that can run in a desktop simulator.](./examples) [This project contains examples that can run in a desktop simulator.](./examples)
First, make sure to pull `lvgl-rs` submodules: First, make sure to pull `lvgl-rs` submodules:
@ -88,7 +58,7 @@ $ git submodule update
Then run the `demo` example: Then run the `demo` example:
```shell ```shell
$ DEP_LV_CONFIG_PATH=`pwd`/examples/include cargo run --example demo --features="alloc" $ DEP_LV_CONFIG_PATH=`pwd`/examples/include cargo run --example demo
``` ```
## Feature Support ## Feature Support

34
examples/Cargo.toml Normal file
View file

@ -0,0 +1,34 @@
[package]
name = "demo"
version = "0.1.0"
authors = ["Rafael Caricio <crates@caric.io>"]
edition = "2018"
publish = false
[dev-dependencies]
lvgl = { path = "../lvgl" }
lvgl-sys = { path = "../lvgl-sys" }
embedded-graphics = "0.6"
embedded-graphics-simulator = "0.2.0"
heapless = "0.5.5"
cstr_core = { version = "0.2.0", features = ["alloc"] }
[[example]]
name = "demo"
path = "demo.rs"
[[example]]
name = "bar"
path = "bar.rs"
[[example]]
name = "button_click"
path = "button_click.rs"
[[example]]
name = "gauge"
path = "gauge.rs"
[[example]]
name = "arc"
path = "arc.rs"

View file

@ -11,31 +11,7 @@ use lvgl::{LvError, Widget};
use lvgl_sys; use lvgl_sys;
use std::time::Instant; use std::time::Instant;
fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
let mut info = lvgl_sys::lv_mem_monitor_t {
total_size: 0,
free_cnt: 0,
free_size: 0,
free_biggest_size: 0,
used_cnt: 0,
max_used: 0,
used_pct: 0,
frag_pct: 0,
};
unsafe {
lvgl_sys::lv_mem_monitor(&mut info as *mut _);
}
info
}
fn main() -> Result<(), LvError> { fn main() -> Result<(), LvError> {
println!("meminfo init: {:?}", mem_info());
run_arc_demo()?;
println!("meminfo end: {:?}", mem_info());
Ok(())
}
fn run_arc_demo() -> Result<(), LvError> {
let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new( let display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(
lvgl_sys::LV_HOR_RES_MAX, lvgl_sys::LV_HOR_RES_MAX,
lvgl_sys::LV_VER_RES_MAX, lvgl_sys::LV_VER_RES_MAX,
@ -82,7 +58,6 @@ fn run_arc_demo() -> Result<(), LvError> {
if i > 270 { if i > 270 {
forward = if forward { false } else { true }; forward = if forward { false } else { true };
i = 1; i = 1;
println!("meminfo running: {:?}", mem_info());
} }
angle = if forward { angle + 1 } else { angle - 1 }; angle = if forward { angle + 1 } else { angle - 1 };
arc.set_end_angle(angle + 135)?; arc.set_end_angle(angle + 135)?;

View file

@ -1,4 +1,4 @@
use cstr_core::CString; use cstr_core::{CStr, CString};
use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{ use embedded_graphics_simulator::{
@ -52,6 +52,20 @@ fn main() -> Result<(), LvError> {
bt.set_label_align(LabelAlign::Left)?; bt.set_label_align(LabelAlign::Left)?;
bt.set_align(&mut screen, Align::InTopLeft, 0, 0)?; bt.set_align(&mut screen, Align::InTopLeft, 0, 0)?;
fn set_text<S>(text: S) -> Result<(), ()>
where
S: AsRef<cstr_core::CStr>,
{
let _v: *const i8 = text.as_ref().as_ptr();
Ok(())
}
let mut t: heapless::String<heapless::consts::U8> = heapless::String::from("test");
t.push('\0').unwrap();
set_text(CStr::from_bytes_with_nul(t.as_bytes()).unwrap()).unwrap();
set_text(cstr_core::CStr::from_bytes_with_nul("test\0".as_bytes()).unwrap()).unwrap();
set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap();
let mut power = Label::new(&mut screen)?; let mut power = Label::new(&mut screen)?;
power.set_recolor(true)?; power.set_recolor(true)?;
power.set_width(80)?; power.set_width(80)?;
@ -66,8 +80,8 @@ fn main() -> Result<(), LvError> {
if i > 59 { if i > 59 {
i = 0; i = 0;
} }
let val = CString::new(format!("21:{:02}", i)).unwrap(); let val = format!("21:{:02}", i);
time.set_text(&val)?; time.set_text(CString::new(val.as_str()).unwrap().as_c_str())?;
i = 1 + i; i = 1 + i;
ui.task_handler(); ui.task_handler();
@ -88,7 +102,7 @@ fn main() -> Result<(), LvError> {
Ok(()) Ok(())
} }
// Reference to native font for LVGL, defined in the file: "fonts_noto_sans_numeric_80.c" // Reference to native font for LittlevGL, defined in the file: "fonts_noto_sans_numeric_80.c"
// TODO: Create a macro for defining a safe wrapper for fonts. // TODO: Create a macro for defining a safe wrapper for fonts.
// Maybe sometihng like: // Maybe sometihng like:
// //

View file

@ -80,7 +80,7 @@ typedef int16_t lv_coord_t;
#define LV_MEM_CUSTOM 0 #define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/ /* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (1048576U) // 1Mb # define LV_MEM_SIZE (32U * 1024U)
/* Complier prefix for a big array declaration */ /* Complier prefix for a big array declaration */
# define LV_MEM_ATTR # define LV_MEM_ATTR

View file

@ -1,6 +1,6 @@
[package] [package]
name = "lvgl-codegen" name = "lvgl-codegen"
version = "0.5.2" version = "0.4.0"
description = "Code generation based on LVGL source code" description = "Code generation based on LVGL source code"
authors = ["Rafael Caricio <crates.lvgl@caric.io>"] authors = ["Rafael Caricio <crates.lvgl@caric.io>"]
readme = "README.md" readme = "README.md"
@ -9,10 +9,10 @@ license = "MIT"
repository = "https://github.com/rafaelcaricio/lvgl-rs" repository = "https://github.com/rafaelcaricio/lvgl-rs"
[dependencies] [dependencies]
regex = "1.4.3" regex = "1.3.9"
quote = "1.0.9" quote = "1.0.7"
lazy_static = "1.4.0" lazy_static = "1.4.0"
proc-macro2 = "1.0.27" proc-macro2 = "1.0.18"
Inflector = "0.11.4" Inflector = "0.11.4"
syn = { version = "1.0.72", features = ["full"]} syn = { version = "1.0.31", features = ["full"]}

View file

@ -1,11 +1,12 @@
use inflector::cases::pascalcase::to_pascal_case; use inflector::cases::pascalcase::to_pascal_case;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use proc_macro2::{Ident, TokenStream}; use proc_macro2::{Ident, TokenStream};
use quote::format_ident;
use quote::quote; use quote::quote;
use quote::{format_ident, ToTokens};
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;
use syn::export::ToTokens;
use syn::{FnArg, ForeignItem, ForeignItemFn, Item, ReturnType}; use syn::{FnArg, ForeignItem, ForeignItemFn, Item, ReturnType};
type CGResult<T> = Result<T, Box<dyn Error>>; type CGResult<T> = Result<T, Box<dyn Error>>;
@ -303,21 +304,21 @@ impl Rusty for LvArg {
#[derive(Clone)] #[derive(Clone)]
pub struct LvType { pub struct LvType {
literal_name: String, literal_name: String,
_r_type: Option<Box<syn::Type>>, r_type: Option<Box<syn::Type>>,
} }
impl LvType { impl LvType {
pub fn new(literal_name: String) -> Self { pub fn new(literal_name: String) -> Self {
Self { Self {
literal_name, literal_name,
_r_type: None, r_type: None,
} }
} }
pub fn from(r_type: Box<syn::Type>) -> Self { pub fn from(r_type: Box<syn::Type>) -> Self {
Self { Self {
literal_name: r_type.to_token_stream().to_string(), literal_name: r_type.to_token_stream().to_string(),
_r_type: Some(r_type), r_type: Some(r_type),
} }
} }

View file

@ -1,7 +1,7 @@
[package] [package]
name = "lvgl-sys" name = "lvgl-sys"
description = "Raw bindings to the LVGL C library." description = "Raw bindings to the LittlevGL C library."
version = "0.5.2" version = "0.4.0"
authors = ["Rafael Caricio <crates.lvgl-sys@caric.io>"] authors = ["Rafael Caricio <crates.lvgl-sys@caric.io>"]
edition = "2018" edition = "2018"
license = "MIT" license = "MIT"
@ -20,8 +20,5 @@ name = "lvgl_sys"
cty = "0.2.1" cty = "0.2.1"
[build-dependencies] [build-dependencies]
cc = "1.0.68" cc = "1.0.50"
bindgen = "0.59.2" bindgen = "0.54.0"
[features]
use-vendored-config = []

View file

@ -5,7 +5,7 @@ Rust raw bindings for LittlevGL library.
Build requires environment variables to be set: Build requires environment variables to be set:
- `DEP_LV_CONFIG_PATH`: Path to the directory containing the `lv_conf.h` header file used for configuration of LVGL library. - `DEP_LV_CONFIG_PATH`: Path to the directory containing the `lv_conf.h` header file used for configuration of LittlevGL library.
We recommend the `lv_conf.h` file to be in your project's root directory. If so, the command to build your project would be: We recommend the `lv_conf.h` file to be in your project's root directory. If so, the command to build your project would be:
```shell script ```shell script

View file

@ -4,50 +4,36 @@ use std::{env, path::Path, path::PathBuf};
static CONFIG_NAME: &str = "DEP_LV_CONFIG_PATH"; static CONFIG_NAME: &str = "DEP_LV_CONFIG_PATH";
fn main() { fn main() {
let project_dir = canonicalize(PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())); let project_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.canonicalize()
.unwrap();
let shims_dir = project_dir.join("shims"); let shims_dir = project_dir.join("shims");
let vendor = project_dir.join("vendor"); let vendor = project_dir.join("vendor");
let vendor_src = vendor.join("lvgl").join("src"); let vendor_src = vendor.join("lvgl").join("src");
let lv_config_dir = { let lv_config_dir = {
let conf_path = env::var(CONFIG_NAME) let raw_path = env::var(CONFIG_NAME).unwrap_or_else(|_| {
.map(PathBuf::from) panic!(
.unwrap_or_else(|_| { "The environment variable {} is required to be defined",
match std::env::var("DOCS_RS") { CONFIG_NAME
Ok(_) => { );
// We've detected that we are building for docs.rs });
// so let's use the vendored `lv_conf.h` file. let conf_path = PathBuf::from(raw_path);
vendor.join("include")
}
Err(_) => {
#[cfg(not(feature = "use-vendored-config"))]
panic!(
"The environment variable {} is required to be defined",
CONFIG_NAME
);
#[cfg(feature = "use-vendored-config")]
vendor.join("include")
}
}
});
if !conf_path.exists() { if !conf_path.exists() {
panic!( panic!(format!(
"Directory {} referenced by {} needs to exist", "Directory referenced by {} needs to exist",
conf_path.to_string_lossy(),
CONFIG_NAME CONFIG_NAME
); ));
} }
if !conf_path.is_dir() { if !conf_path.is_dir() {
panic!("{} needs to be a directory", CONFIG_NAME); panic!(format!("{} needs to be a directory", CONFIG_NAME));
} }
if !conf_path.join("lv_conf.h").exists() { if !conf_path.join("lv_conf.h").exists() {
panic!( panic!(format!(
"Directory {} referenced by {} needs to contain a file called lv_conf.h", "Directory referenced by {} needs to contain a file called lv_conf.h",
conf_path.to_string_lossy(),
CONFIG_NAME CONFIG_NAME
); ));
} }
println!( println!(
@ -97,27 +83,17 @@ fn main() {
if target.ends_with("emscripten") { if target.ends_with("emscripten") {
if let Ok(em_path) = env::var("EMSDK") { if let Ok(em_path) = env::var("EMSDK") {
additional_args.push("-I".to_string()); additional_args.push("-I".to_string());
additional_args.push(format!( additional_args.push(format!("{}/upstream/emscripten/system/include/libc", em_path));
"{}/upstream/emscripten/system/include/libc",
em_path
));
additional_args.push("-I".to_string()); additional_args.push("-I".to_string());
additional_args.push(format!( additional_args.push(format!("{}/upstream/emscripten/system/lib/libc/musl/arch/emscripten", em_path));
"{}/upstream/emscripten/system/lib/libc/musl/arch/emscripten",
em_path
));
additional_args.push("-I".to_string()); additional_args.push("-I".to_string());
additional_args.push(format!( additional_args.push(format!("{}/upstream/emscripten/system/include/SDL", em_path));
"{}/upstream/emscripten/system/include/SDL",
em_path
));
} }
} }
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let bindings = bindgen::Builder::default() let bindings = bindgen::Builder::default()
.header(shims_dir.join("lvgl_sys.h").to_str().unwrap()) .header(shims_dir.join("lvgl_sys.h").to_str().unwrap())
.generate_comments(false)
.layout_tests(false) .layout_tests(false)
.use_core() .use_core()
.rustfmt_bindings(true) .rustfmt_bindings(true)
@ -127,8 +103,7 @@ fn main() {
.generate() .generate()
.expect("Unable to generate bindings"); .expect("Unable to generate bindings");
bindings bindings.write_to_file(out_path.join("bindings.rs"))
.write_to_file(out_path.join("bindings.rs"))
.expect("Can't write bindings!"); .expect("Can't write bindings!");
} }
@ -143,10 +118,3 @@ fn add_c_files(build: &mut cc::Build, path: impl AsRef<Path>) {
} }
} }
} }
fn canonicalize(path: impl AsRef<Path>) -> PathBuf {
let canonicalized = path.as_ref().canonicalize().unwrap();
let canonicalized = &*canonicalized.to_string_lossy();
PathBuf::from(canonicalized.strip_prefix(r"\\?\").unwrap_or(canonicalized))
}

View file

@ -23,10 +23,10 @@ mod tests {
lv_init(); lv_init();
let horizontal_resolution = lv_disp_get_hor_res(core::ptr::null_mut()); let horizontal_resolution = lv_disp_get_hor_res(core::ptr::null_mut());
assert_eq!(horizontal_resolution, LV_HOR_RES_MAX as i16); assert_eq!(horizontal_resolution, 240);
let vertical_resolution = lv_disp_get_ver_res(core::ptr::null_mut()); let vertical_resolution = lv_disp_get_ver_res(core::ptr::null_mut());
assert_eq!(vertical_resolution, LV_VER_RES_MAX as i16); assert_eq!(vertical_resolution, 240);
} }
} }
} }

View file

@ -1,701 +0,0 @@
/**
* @file lv_conf.h
*
*/
/*
* COPY THIS FILE AS `lv_conf.h` NEXT TO the `lvgl` FOLDER
*/
#if 1 /*Set it to "1" to enable content*/
#ifndef LV_CONF_H
#define LV_CONF_H
/* clang-format off */
#include <stdint.h>
/*====================
Graphical settings
*====================*/
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (240)
#define LV_VER_RES_MAX (240)
/* Color depth:
* - 1: 1 byte per pixel
* - 8: RGB332
* - 16: RGB565
* - 32: ARGB8888
*/
#define LV_COLOR_DEPTH 16
/* Swap the 2 bytes of RGB565 color.
* Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP 0
/* 1: Enable screen transparency.
* Useful for OSD or other overlapping GUIs.
* Requires `LV_COLOR_DEPTH = 32` colors and the screen's style should be modified: `style.body.opa = ...`*/
#define LV_COLOR_SCREEN_TRANSP 0
/*Images pixels with this color will not be drawn (with chroma keying)*/
#define LV_COLOR_TRANSP LV_COLOR_LIME /*LV_COLOR_LIME: pure green*/
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
#define LV_ANTIALIAS 1
/* Default display refresh period.
* Can be changed in the display driver (`lv_disp_drv_t`).*/
#define LV_DISP_DEF_REFR_PERIOD 30 /*[ms]*/
/* Dot Per Inch: used to initialize default sizes.
* E.g. a button with width = LV_DPI / 2 -> half inch wide
* (Not so important, you can adjust it to modify default sizes and spaces)*/
#define LV_DPI 130 /*[px]*/
/* The the real width of the display changes some default values:
* default object sizes, layout of examples, etc.
* According to the width of the display (hor. res. / dpi)
* the displays fall in 4 categories.
* The 4th is extra large which has no upper limit so not listed here
* The upper limit of the categories are set below in 0.1 inch unit.
*/
#define LV_DISP_SMALL_LIMIT 30
#define LV_DISP_MEDIUM_LIMIT 50
#define LV_DISP_LARGE_LIMIT 70
/* Type of coordinates. Should be `int16_t` (or `int32_t` for extreme cases) */
typedef int16_t lv_coord_t;
/*=========================
Memory manager settings
*=========================*/
/* LittelvGL's internal memory manager's settings.
* The graphical objects and other related data are stored here. */
/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#define LV_MEM_CUSTOM 0
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U)
/* Complier prefix for a big array declaration */
# define LV_MEM_ATTR
/* Set an address for the memory pool instead of allocating it as an array.
* Can be in external SRAM too. */
# define LV_MEM_ADR 0
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
# define LV_MEM_AUTO_DEFRAG 1
#else /*LV_MEM_CUSTOM*/
# define LV_MEM_CUSTOM_INCLUDE <stdlib.h> /*Header for the dynamic memory function*/
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
#endif /*LV_MEM_CUSTOM*/
/* Garbage Collector settings
* Used if lvgl is binded to higher level language and the memory is managed by that language */
#define LV_ENABLE_GC 0
#if LV_ENABLE_GC != 0
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
#endif /* LV_ENABLE_GC */
/*=======================
Input device settings
*=======================*/
/* Input device default settings.
* Can be changed in the Input device driver (`lv_indev_drv_t`)*/
/* Input device read period in milliseconds */
#define LV_INDEV_DEF_READ_PERIOD 30
/* Drag threshold in pixels */
#define LV_INDEV_DEF_DRAG_LIMIT 10
/* Drag throw slow-down in [%]. Greater value -> faster slow-down */
#define LV_INDEV_DEF_DRAG_THROW 10
/* Long press time in milliseconds.
* Time to send `LV_EVENT_LONG_PRESSSED`) */
#define LV_INDEV_DEF_LONG_PRESS_TIME 400
/* Repeated trigger period in long press [ms]
* Time between `LV_EVENT_LONG_PRESSED_REPEAT */
#define LV_INDEV_DEF_LONG_PRESS_REP_TIME 100
/* Gesture threshold in pixels */
#define LV_INDEV_DEF_GESTURE_LIMIT 50
/* Gesture min velocity at release before swipe (pixels)*/
#define LV_INDEV_DEF_GESTURE_MIN_VELOCITY 3
/*==================
* Feature usage
*==================*/
/*1: Enable the Animations */
#define LV_USE_ANIMATION 1
#if LV_USE_ANIMATION
/*Declare the type of the user data of animations (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_anim_user_data_t;
#endif
/* 1: Enable shadow drawing*/
#define LV_USE_SHADOW 1
#if LV_USE_SHADOW
/* Allow buffering some shadow calculation
* LV_SHADOW_CACHE_SIZE is the max. shadow size to buffer,
* where shadow size is `shadow_width + radius`
* Caching has LV_SHADOW_CACHE_SIZE^2 RAM cost*/
#define LV_SHADOW_CACHE_SIZE 0
#endif
/* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/
#define LV_USE_BLEND_MODES 1
/* 1: Use the `opa_scale` style property to set the opacity of an object and its children at once*/
#define LV_USE_OPA_SCALE 1
/* 1: Use image zoom and rotation*/
#define LV_USE_IMG_TRANSFORM 1
/* 1: Enable object groups (for keyboard/encoder navigation) */
#define LV_USE_GROUP 1
#if LV_USE_GROUP
typedef void * lv_group_user_data_t;
#endif /*LV_USE_GROUP*/
/* 1: Enable GPU interface*/
#define LV_USE_GPU 1 /*Only enables `gpu_fill_cb` and `gpu_blend_cb` in the disp. drv- */
#define LV_USE_GPU_STM32_DMA2D 0
/* 1: Enable file system (might be required for images */
#define LV_USE_FILESYSTEM 1
#if LV_USE_FILESYSTEM
/*Declare the type of the user data of file system drivers (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_fs_drv_user_data_t;
#endif
/*1: Add a `user_data` to drivers and objects*/
#define LV_USE_USER_DATA 1
/*1: Show CPU usage and FPS count in the right bottom corner*/
#define LV_USE_PERF_MONITOR 0
/*1: Use the functions and types from the older API if possible */
#define LV_USE_API_EXTENSION_V6 1
/*========================
* Image decoder and cache
*========================*/
/* 1: Enable indexed (palette) images */
#define LV_IMG_CF_INDEXED 1
/* 1: Enable alpha indexed images */
#define LV_IMG_CF_ALPHA 1
/* Default image cache size. Image caching keeps the images opened.
* If only the built-in image formats are used there is no real advantage of caching.
* (I.e. no new image decoder is added)
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
* However the opened images might consume additional RAM.
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
#define LV_IMG_CACHE_DEF_SIZE 1
/*Declare the type of the user data of image decoder (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_img_decoder_user_data_t;
/*=====================
* Compiler settings
*====================*/
/* Define a custom attribute to `lv_tick_inc` function */
#define LV_ATTRIBUTE_TICK_INC
/* Define a custom attribute to `lv_task_handler` function */
#define LV_ATTRIBUTE_TASK_HANDLER
/* Define a custom attribute to `lv_disp_flush_ready` function */
#define LV_ATTRIBUTE_FLUSH_READY
/* With size optimization (-Os) the compiler might not align data to
* 4 or 8 byte boundary. This alignment will be explicitly applied where needed.
* E.g. __attribute__((aligned(4))) */
#define LV_ATTRIBUTE_MEM_ALIGN
/* Attribute to mark large constant arrays for example
* font's bitmaps */
#define LV_ATTRIBUTE_LARGE_CONST
/* Prefix performance critical functions to place them into a faster memory (e.g RAM)
* Uses 15-20 kB extra memory */
#define LV_ATTRIBUTE_FAST_MEM
/* Export integer constant to binding.
* This macro is used with constants in the form of LV_<CONST> that
* should also appear on lvgl binding API such as Micropython
*
* The default value just prevents a GCC warning.
*/
#define LV_EXPORT_CONST_INT(int_value) struct _silence_gcc_warning
/*===================
* HAL settings
*==================*/
/* 1: use a custom tick source.
* It removes the need to manually update the tick with `lv_tick_inc`) */
#define LV_TICK_CUSTOM 0
#if LV_TICK_CUSTOM == 1
#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
#endif /*LV_TICK_CUSTOM*/
typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
typedef void * lv_indev_drv_user_data_t; /*Type of user data in the input device driver*/
/*================
* Log settings
*===============*/
/*1: Enable the log module*/
#define LV_USE_LOG 0
#if LV_USE_LOG
/* How important log should be added:
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
* LV_LOG_LEVEL_INFO Log important events
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't cause a problem
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
* LV_LOG_LEVEL_NONE Do not log anything
*/
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
/* 1: Print the log with 'printf';
* 0: user need to register a callback with `lv_log_register_print_cb`*/
# define LV_LOG_PRINTF 0
#endif /*LV_USE_LOG*/
/*=================
* Debug settings
*================*/
/* If Debug is enabled LittelvGL validates the parameters of the functions.
* If an invalid parameter is found an error log message is printed and
* the MCU halts at the error. (`LV_USE_LOG` should be enabled)
* If you are debugging the MCU you can pause
* the debugger to see exactly where the issue is.
*
* The behavior of asserts can be overwritten by redefining them here.
* E.g. #define LV_ASSERT_MEM(p) <my_assert_code>
*/
#define LV_USE_DEBUG 1
#if LV_USE_DEBUG
/*Check if the parameter is NULL. (Quite fast) */
#define LV_USE_ASSERT_NULL 1
/*Checks is the memory is successfully allocated or no. (Quite fast)*/
#define LV_USE_ASSERT_MEM 1
/*Check the integrity of `lv_mem` after critical operations. (Slow)*/
#define LV_USE_ASSERT_MEM_INTEGRITY 0
/* Check the strings.
* Search for NULL, very long strings, invalid characters, and unnatural repetitions. (Slow)
* If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */
#define LV_USE_ASSERT_STR 0
/* Check NULL, the object's type and existence (e.g. not deleted). (Quite slow)
* If disabled `LV_USE_ASSERT_NULL` will be performed instead (if it's enabled) */
#define LV_USE_ASSERT_OBJ 0
/*Check if the styles are properly initialized. (Fast)*/
#define LV_USE_ASSERT_STYLE 0
#endif /*LV_USE_DEBUG*/
/*==================
* FONT USAGE
*===================*/
/* The built-in fonts contains the ASCII range and some Symbols with 4 bit-per-pixel.
* The symbols are available via `LV_SYMBOL_...` defines
* More info about fonts: https://docs.lvgl.com/#Fonts
* To create a new font go to: https://lvgl.com/ttf-font-to-c-array
*/
/* Montserrat fonts with bpp = 4
* https://fonts.google.com/specimen/Montserrat */
#define LV_FONT_MONTSERRAT_12 0
#define LV_FONT_MONTSERRAT_14 0
#define LV_FONT_MONTSERRAT_16 1
#define LV_FONT_MONTSERRAT_18 0
#define LV_FONT_MONTSERRAT_20 0
#define LV_FONT_MONTSERRAT_22 0
#define LV_FONT_MONTSERRAT_24 0
#define LV_FONT_MONTSERRAT_26 0
#define LV_FONT_MONTSERRAT_28 0
#define LV_FONT_MONTSERRAT_30 0
#define LV_FONT_MONTSERRAT_32 0
#define LV_FONT_MONTSERRAT_34 0
#define LV_FONT_MONTSERRAT_36 0
#define LV_FONT_MONTSERRAT_38 0
#define LV_FONT_MONTSERRAT_40 0
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
/* Demonstrate special features */
#define LV_FONT_MONTSERRAT_12_SUBPX 0
#define LV_FONT_MONTSERRAT_28_COMPRESSED 0 /*bpp = 3*/
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0 /*Hebrew, Arabic, PErisan letters and all their forms*/
#define LV_FONT_SIMSUN_16_CJK 0 /*1000 most common CJK radicals*/
/*Pixel perfect monospace font
* http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8 0
/* Optionally declare your custom fonts here.
* You can use these fonts as default font too
* and they will be available globally. E.g.
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
* LV_FONT_DECLARE(my_font_2)
*/
#define LV_FONT_CUSTOM_DECLARE
/* Enable it if you have fonts with a lot of characters.
* The limit depends on the font size, font face and bpp
* but with > 10,000 characters if you see issues probably you need to enable it.*/
#define LV_FONT_FMT_TXT_LARGE 0
/* Set the pixel order of the display.
* Important only if "subpx fonts" are used.
* With "normal" font it doesn't matter.
*/
#define LV_FONT_SUBPX_BGR 0
/*Declare the type of the user data of fonts (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_font_user_data_t;
/*================
* THEME USAGE
*================*/
/*Always enable at least on theme*/
/* No theme, you can apply your styles as you need
* No flags. Set LV_THEME_DEFAULT_FLAG 0 */
#define LV_USE_THEME_EMPTY 1
/*Simple to the create your theme based on it
* No flags. Set LV_THEME_DEFAULT_FLAG 0 */
#define LV_USE_THEME_TEMPLATE 1
/* A fast and impressive theme.
* Flags:
* LV_THEME_MATERIAL_FLAG_LIGHT: light theme
* LV_THEME_MATERIAL_FLAG_DARK: dark theme*/
#define LV_USE_THEME_MATERIAL 1
/* Mono-color theme for monochrome displays.
* If LV_THEME_DEFAULT_COLOR_PRIMARY is LV_COLOR_BLACK the
* texts and borders will be black and the background will be
* white. Else the colors are inverted.
* No flags. Set LV_THEME_DEFAULT_FLAG 0 */
#define LV_USE_THEME_MONO 1
#define LV_THEME_DEFAULT_INCLUDE <stdint.h> /*Include a header for the init. function*/
#define LV_THEME_DEFAULT_INIT lv_theme_material_init
#define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_RED
#define LV_THEME_DEFAULT_COLOR_SECONDARY LV_COLOR_BLUE
#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_LIGHT
#define LV_THEME_DEFAULT_FONT_SMALL &lv_font_montserrat_16
#define LV_THEME_DEFAULT_FONT_NORMAL &lv_font_montserrat_16
#define LV_THEME_DEFAULT_FONT_SUBTITLE &lv_font_montserrat_16
#define LV_THEME_DEFAULT_FONT_TITLE &lv_font_montserrat_16
/*=================
* Text settings
*=================*/
/* Select a character encoding for strings.
* Your IDE or editor should have the same character encoding
* - LV_TXT_ENC_UTF8
* - LV_TXT_ENC_ASCII
* */
#define LV_TXT_ENC LV_TXT_ENC_UTF8
/*Can break (wrap) texts on these chars*/
#define LV_TXT_BREAK_CHARS " ,.;:-_"
/* If a word is at least this long, will break wherever "prettiest"
* To disable, set to a value <= 0 */
#define LV_TXT_LINE_BREAK_LONG_LEN 0
/* Minimum number of characters in a long word to put on a line before a break.
* Depends on LV_TXT_LINE_BREAK_LONG_LEN. */
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3
/* Minimum number of characters in a long word to put on a line after a break.
* Depends on LV_TXT_LINE_BREAK_LONG_LEN. */
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 3
/* The control character to use for signalling text recoloring. */
#define LV_TXT_COLOR_CMD "#"
/* Support bidirectional texts.
* Allows mixing Left-to-Right and Right-to-Left texts.
* The direction will be processed according to the Unicode Bidirectioanl Algorithm:
* https://www.w3.org/International/articles/inline-bidi-markup/uba-basics*/
#define LV_USE_BIDI 0
#if LV_USE_BIDI
/* Set the default direction. Supported values:
* `LV_BIDI_DIR_LTR` Left-to-Right
* `LV_BIDI_DIR_RTL` Right-to-Left
* `LV_BIDI_DIR_AUTO` detect texts base direction */
#define LV_BIDI_BASE_DIR_DEF LV_BIDI_DIR_AUTO
#endif
/* Enable Arabic/Persian processing
* In these languages characters should be replaced with
* an other form based on their position in the text */
#define LV_USE_ARABIC_PERSIAN_CHARS 0
/*Change the built in (v)snprintf functions*/
#define LV_SPRINTF_CUSTOM 0
#if LV_SPRINTF_CUSTOM
# define LV_SPRINTF_INCLUDE <stdio.h>
# define lv_snprintf snprintf
# define lv_vsnprintf vsnprintf
#else /*!LV_SPRINTF_CUSTOM*/
# define LV_SPRINTF_DISABLE_FLOAT 1
#endif /*LV_SPRINTF_CUSTOM*/
/*===================
* LV_OBJ SETTINGS
*==================*/
#if LV_USE_USER_DATA
/*Declare the type of the user data of object (can be e.g. `void *`, `int`, `struct`)*/
typedef void * lv_obj_user_data_t;
/*Provide a function to free user data*/
#define LV_USE_USER_DATA_FREE 0
#if LV_USE_USER_DATA_FREE
# define LV_USER_DATA_FREE_INCLUDE "something.h" /*Header for user data free function*/
/* Function prototype : void user_data_free(lv_obj_t * obj); */
# define LV_USER_DATA_FREE (user_data_free) /*Invoking for user data free function*/
#endif
#endif
/*1: enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
#define LV_USE_OBJ_REALIGN 1
/* Enable to make the object clickable on a larger area.
* LV_EXT_CLICK_AREA_OFF or 0: Disable this feature
* LV_EXT_CLICK_AREA_TINY: The extra area can be adjusted horizontally and vertically (0..255 px)
* LV_EXT_CLICK_AREA_FULL: The extra area can be adjusted in all 4 directions (-32k..+32k px)
*/
#define LV_USE_EXT_CLICK_AREA LV_EXT_CLICK_AREA_TINY
/*==================
* LV OBJ X USAGE
*================*/
/*
* Documentation of the object types: https://docs.lvgl.com/#Object-types
*/
/*Arc (dependencies: -)*/
#define LV_USE_ARC 1
/*Bar (dependencies: -)*/
#define LV_USE_BAR 1
/*Button (dependencies: lv_cont*/
#define LV_USE_BTN 1
/*Button matrix (dependencies: -)*/
#define LV_USE_BTNMATRIX 1
/*Calendar (dependencies: -)*/
#define LV_USE_CALENDAR 1
/*Canvas (dependencies: lv_img)*/
#define LV_USE_CANVAS 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define LV_USE_CHECKBOX 1
/*Chart (dependencies: -)*/
#define LV_USE_CHART 1
#if LV_USE_CHART
# define LV_CHART_AXIS_TICK_LABEL_MAX_LEN 256
#endif
/*Container (dependencies: -*/
#define LV_USE_CONT 1
/*Color picker (dependencies: -*/
#define LV_USE_CPICKER 1
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
#define LV_USE_DROPDOWN 1
#if LV_USE_DROPDOWN != 0
/*Open and close default animation time [ms] (0: no animation)*/
# define LV_DROPDOWN_DEF_ANIM_TIME 200
#endif
/*Gauge (dependencies:lv_bar, lv_linemeter)*/
#define LV_USE_GAUGE 1
/*Image (dependencies: lv_label*/
#define LV_USE_IMG 1
/*Image Button (dependencies: lv_btn*/
#define LV_USE_IMGBTN 1
#if LV_USE_IMGBTN
/*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
# define LV_IMGBTN_TILED 0
#endif
/*Keyboard (dependencies: lv_btnm)*/
#define LV_USE_KEYBOARD 1
/*Label (dependencies: -*/
#define LV_USE_LABEL 1
#if LV_USE_LABEL != 0
/*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_ROLL/ROLL_CIRC' mode*/
# define LV_LABEL_DEF_SCROLL_SPEED 25
/* Waiting period at beginning/end of animation cycle */
# define LV_LABEL_WAIT_CHAR_COUNT 3
/*Enable selecting text of the label */
# define LV_LABEL_TEXT_SEL 0
/*Store extra some info in labels (12 bytes) to speed up drawing of very long texts*/
# define LV_LABEL_LONG_TXT_HINT 0
#endif
/*LED (dependencies: -)*/
#define LV_USE_LED 1
#if LV_USE_LED
# define LV_LED_BRIGHT_MIN 120 /*Minimal brightness*/
# define LV_LED_BRIGHT_MAX 255 /*Maximal brightness*/
#endif
/*Line (dependencies: -*/
#define LV_USE_LINE 1
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
#define LV_USE_LIST 1
#if LV_USE_LIST != 0
/*Default animation time of focusing to a list element [ms] (0: no animation) */
# define LV_LIST_DEF_ANIM_TIME 100
#endif
/*Line meter (dependencies: *;)*/
#define LV_USE_LINEMETER 1
#if LV_USE_LINEMETER
/* Draw line more precisely at cost of performance.
* Useful if there are lot of lines any minor are visible
* 0: No extra precision
* 1: Some extra precision
* 2: Best precision
*/
# define LV_LINEMETER_PRECISE 0
#endif
/*Mask (dependencies: -)*/
#define LV_USE_OBJMASK 1
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
#define LV_USE_MSGBOX 1
/*Page (dependencies: lv_cont)*/
#define LV_USE_PAGE 1
#if LV_USE_PAGE != 0
/*Focus default animation time [ms] (0: no animation)*/
# define LV_PAGE_DEF_ANIM_TIME 400
#endif
/*Preload (dependencies: lv_arc, lv_anim)*/
#define LV_USE_SPINNER 1
#if LV_USE_SPINNER != 0
# define LV_SPINNER_DEF_ARC_LENGTH 60 /*[deg]*/
# define LV_SPINNER_DEF_SPIN_TIME 1000 /*[ms]*/
# define LV_SPINNER_DEF_ANIM LV_SPINNER_TYPE_SPINNING_ARC
#endif
/*Roller (dependencies: lv_ddlist)*/
#define LV_USE_ROLLER 1
#if LV_USE_ROLLER != 0
/*Focus animation time [ms] (0: no animation)*/
# define LV_ROLLER_DEF_ANIM_TIME 200
/*Number of extra "pages" when the roller is infinite*/
# define LV_ROLLER_INF_PAGES 7
#endif
/*Slider (dependencies: lv_bar)*/
#define LV_USE_SLIDER 1
/*Spinbox (dependencies: lv_ta)*/
#define LV_USE_SPINBOX 1
/*Switch (dependencies: lv_slider)*/
#define LV_USE_SWITCH 1
/*Text area (dependencies: lv_label, lv_page)*/
#define LV_USE_TEXTAREA 1
#if LV_USE_TEXTAREA != 0
# define LV_TEXTAREA_DEF_CURSOR_BLINK_TIME 400 /*ms*/
# define LV_TEXTAREA_DEF_PWD_SHOW_TIME 1500 /*ms*/
#endif
/*Table (dependencies: lv_label)*/
#define LV_USE_TABLE 1
#if LV_USE_TABLE
# define LV_TABLE_COL_MAX 12
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#define LV_USE_TABVIEW 1
# if LV_USE_TABVIEW != 0
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TABVIEW_DEF_ANIM_TIME 300
#endif
/*Tileview (dependencies: lv_page) */
#define LV_USE_TILEVIEW 1
#if LV_USE_TILEVIEW
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TILEVIEW_DEF_ANIM_TIME 300
#endif
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define LV_USE_WIN 1
/*==================
* Non-user section
*==================*/
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /* Disable warnings for Visual Studio*/
# define _CRT_SECURE_NO_WARNINGS
#endif
/*--END OF LV_CONF_H--*/
#endif /*LV_CONF_H*/
#endif /*End of "Content enable"*/

@ -1 +1 @@
Subproject commit 524709472757405ac0eef8d6d002632526430df3 Subproject commit 1ca1934dbe8e826ef1ed1690005fb678fea3a1f3

View file

@ -1,7 +1,7 @@
[package] [package]
name = "lvgl" name = "lvgl"
description = "LVGL bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash)." description = "LittlevGL bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects (opacity, antialiasing, animations) and low memory requirements (16K RAM, 64K Flash)."
version = "0.5.2" version = "0.4.0"
authors = ["Rafael Caricio <crates.lvgl@caric.io>"] authors = ["Rafael Caricio <crates.lvgl@caric.io>"]
edition = "2018" edition = "2018"
repository = "https://github.com/rafaelcaricio/lvgl-rs" repository = "https://github.com/rafaelcaricio/lvgl-rs"
@ -12,47 +12,15 @@ keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
lvgl-sys = { version = "0.5.2", path = "../lvgl-sys" } lvgl-sys = { version = "0.4.0", path = "../lvgl-sys" }
cty = "0.2.1" cty = "0.2.1"
embedded-graphics = "0.7.1" embedded-graphics = "0.6.2"
cstr_core = "0.2.3" cstr_core = { version = "0.2.0" }
bitflags = "1.2.1" bitflags = "1.2.1"
[features]
alloc = ["cstr_core/alloc"]
lvgl_alloc = ["alloc"]
use-vendored-config = ["lvgl-sys/use-vendored-config"]
[build-dependencies] [build-dependencies]
quote = "1.0.9" quote = "1.0.7"
proc-macro2 = "1.0.24" proc-macro2 = "1.0.18"
lvgl-codegen = { version = "0.5.2", path = "../lvgl-codegen" } lvgl-codegen = { version = "0.4.0", path = "../lvgl-codegen" }
lvgl-sys = { version = "0.5.2", path = "../lvgl-sys" } lvgl-sys = { version = "0.4.0", path = "../lvgl-sys" }
[dev-dependencies]
embedded-graphics-simulator = "0.3.0"
heapless = "0.7.13"
[[example]]
name = "demo"
path = "../examples/demo.rs"
required-features = ["alloc"]
[[example]]
name = "bar"
path = "../examples/bar.rs"
required-features = ["alloc"]
[[example]]
name = "button_click"
path = "../examples/button_click.rs"
required-features = ["alloc"]
[[example]]
name = "gauge"
path = "../examples/gauge.rs"
[[example]]
name = "arc"
path = "../examples/arc.rs"
required-features = ["lvgl_alloc"]

View file

@ -1,20 +0,0 @@
use core::alloc::{GlobalAlloc, Layout};
// Register the global allocator
#[global_allocator]
static ALLOCATOR: LvglAlloc = LvglAlloc;
pub struct LvglAlloc;
unsafe impl GlobalAlloc for LvglAlloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
// Make sure LVGL is initialized!
crate::lvgl_init();
lvgl_sys::lv_mem_alloc(layout.size() as lvgl_sys::size_t) as *mut u8
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
crate::lvgl_init();
lvgl_sys::lv_mem_free(ptr as *const cty::c_void)
}
}

View file

@ -1,68 +1,15 @@
//! [![github]](https://github.com/rafaelcaricio/lvgl-rs)&ensp;[![crates-io]](https://crates.io/crates/lvgl)&ensp;[![docs-rs]](crate)
//!
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K
//!
//! <br>
//!
//! [LVGL][1] bindings for Rust. A powerful and easy-to-use embedded GUI with many widgets, advanced visual effects, and
//! low memory footprint. This crate is compatible with `#![no_std]` environments by default.
//!
//! [1]: https://docs.lvgl.io/v7/en/html/get-started/quick-overview.html
//!
#![cfg_attr(not(test), no_std)] #![cfg_attr(not(test), no_std)]
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
#[cfg(feature = "lvgl_alloc")] pub(crate) mod mem;
extern crate alloc;
// We can ONLY use `alloc::boxed::Box` if `lvgl_alloc` is enabled.
// That is because we use `Box` to send memory references to LVGL. Since the global allocator, when
// `lvgl_alloc` feature is enabled, is the LVGL memory manager then everything is in LVGL
// managed memory anyways. In that case we can use the Rust's provided Box definition.
//
#[cfg(feature = "lvgl_alloc")]
use ::alloc::boxed::Box;
#[cfg(feature = "lvgl_alloc")]
mod allocator;
mod support; mod support;
mod ui; mod ui;
#[macro_use] #[macro_use]
mod lv_core; mod lv_core;
pub mod widgets; pub mod widgets;
#[cfg(not(feature = "lvgl_alloc"))]
pub(crate) mod mem;
// When LVGL allocator is not used on the Rust code, we need a way to add objects to the LVGL
// managed memory. We implement a very simple `Box` that has the minimal features to copy memory
// safely to the LVGL managed memory.
//
#[cfg(not(feature = "lvgl_alloc"))]
use crate::mem::Box;
pub use lv_core::*; pub use lv_core::*;
pub use support::*; pub use support::*;
pub use ui::*; pub use ui::*;
use core::sync::atomic::{AtomicBool, Ordering};
// Initialize LVGL only once.
static LVGL_INITIALIZED: AtomicBool = AtomicBool::new(false);
pub(crate) fn lvgl_init() {
if LVGL_INITIALIZED
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed)
.is_ok()
{
unsafe {
lvgl_sys::lv_init();
}
}
}

View file

@ -1,9 +1,9 @@
use crate::lv_core::style::Style; use crate::lv_core::style::Style;
use crate::Box; use crate::mem::Box;
use crate::{Align, LvError, LvResult}; use crate::{Align, LvError, LvResult};
use core::ptr; use core::ptr;
/// Represents a native LVGL object /// Represents a native LittlevGL object
pub trait NativeObject { pub trait NativeObject {
/// Provide common way to access to the underlying native object pointer. /// Provide common way to access to the underlying native object pointer.
fn raw(&self) -> LvResult<ptr::NonNull<lvgl_sys::lv_obj_t>>; fn raw(&self) -> LvResult<ptr::NonNull<lvgl_sys::lv_obj_t>>;
@ -28,7 +28,7 @@ impl NativeObject for Obj {
} }
} }
/// A wrapper for all LVGL common operations on generic objects. /// A wrapper for all LittlevGL common operations on generic objects.
pub trait Widget: NativeObject { pub trait Widget: NativeObject {
type SpecialEvent; type SpecialEvent;
type Part: Into<u8>; type Part: Into<u8>;
@ -146,8 +146,8 @@ macro_rules! define_object {
unsafe { unsafe {
let mut raw = self.raw()?; let mut raw = self.raw()?;
let obj = raw.as_mut(); let obj = raw.as_mut();
let user_closure = $crate::Box::new(f); let user_closure = $crate::mem::Box::new(f)?;
obj.user_data = $crate::Box::into_raw(user_closure) as *mut cty::c_void; obj.user_data = $crate::mem::Box::into_raw(user_closure) as *mut cty::c_void;
lvgl_sys::lv_obj_set_event_cb( lvgl_sys::lv_obj_set_event_cb(
obj, obj,
lvgl_sys::lv_event_cb_t::Some($crate::support::event_callback::<Self, F>), lvgl_sys::lv_event_cb_t::Some($crate::support::event_callback::<Self, F>),
@ -179,19 +179,19 @@ macro_rules! define_object {
bitflags! { bitflags! {
pub struct State: u32 { pub struct State: u32 {
/// Normal, released /// Normal, released
const DEFAULT = lvgl_sys::LV_STATE_DEFAULT as u32; const DEFAULT = lvgl_sys::LV_STATE_DEFAULT;
/// Toggled or checked /// Toggled or checked
const CHECKED = lvgl_sys::LV_STATE_CHECKED as u32; const CHECKED = lvgl_sys::LV_STATE_CHECKED;
/// Focused via keypad or encoder or clicked via touchpad/mouse /// Focused via keypad or encoder or clicked via touchpad/mouse
const FOCUSED = lvgl_sys::LV_STATE_FOCUSED as u32; const FOCUSED = lvgl_sys::LV_STATE_FOCUSED;
/// Edit by an encoder /// Edit by an encoder
const EDITED = lvgl_sys::LV_STATE_EDITED as u32; const EDITED = lvgl_sys::LV_STATE_EDITED;
/// Hovered by mouse (not supported now) /// Hovered by mouse (not supported now)
const HOVERED = lvgl_sys::LV_STATE_HOVERED as u32; const HOVERED = lvgl_sys::LV_STATE_HOVERED;
/// Pressed /// Pressed
const PRESSED = lvgl_sys::LV_STATE_PRESSED as u32; const PRESSED = lvgl_sys::LV_STATE_PRESSED;
/// Disabled or inactive /// Disabled or inactive
const DISABLED = lvgl_sys::LV_STATE_DISABLED as u32; const DISABLED = lvgl_sys::LV_STATE_DISABLED;
} }
} }
@ -206,9 +206,9 @@ pub enum Part {
All, All,
} }
impl From<Part> for u8 { impl Into<u8> for Part {
fn from(self_: Part) -> u8 { fn into(self) -> u8 {
match self_ { match self {
Part::Main => lvgl_sys::LV_OBJ_PART_MAIN as u8, Part::Main => lvgl_sys::LV_OBJ_PART_MAIN as u8,
Part::All => lvgl_sys::LV_OBJ_PART_ALL as u8, Part::All => lvgl_sys::LV_OBJ_PART_ALL as u8,
} }

View file

@ -1,4 +1,4 @@
use crate::Box; use crate::mem::Box;
use crate::{Color, LvResult, State}; use crate::{Color, LvResult, State};
use core::mem; use core::mem;
use cstr_core::CStr; use cstr_core::CStr;
@ -7,7 +7,6 @@ pub enum Themes {
Pretty, Pretty,
} }
#[derive(Clone)]
pub struct Style { pub struct Style {
pub(crate) raw: Box<lvgl_sys::lv_style_t>, pub(crate) raw: Box<lvgl_sys::lv_style_t>,
} }
@ -18,7 +17,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_ptr( lvgl_sys::_lv_style_set_ptr(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_STR as u32 (lvgl_sys::LV_STYLE_VALUE_STR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.as_ptr() as *mut cty::c_void, value.as_ptr() as *mut cty::c_void,
); );
@ -32,7 +31,7 @@ impl Default for Style {
let raw = unsafe { let raw = unsafe {
let mut style = mem::MaybeUninit::<lvgl_sys::lv_style_t>::uninit(); let mut style = mem::MaybeUninit::<lvgl_sys::lv_style_t>::uninit();
lvgl_sys::lv_style_init(style.as_mut_ptr()); lvgl_sys::lv_style_init(style.as_mut_ptr());
Box::new(style.assume_init()) Box::new(style.assume_init()).unwrap()
}; };
Self { raw } Self { raw }
} }
@ -40,122 +39,122 @@ impl Default for Style {
bitflags! { bitflags! {
pub struct Opacity: u32 { pub struct Opacity: u32 {
const OPA_TRANSP = lvgl_sys::LV_OPA_TRANSP as u32; const OPA_TRANSP = lvgl_sys::LV_OPA_TRANSP;
const OPA_0 = lvgl_sys::LV_OPA_0 as u32; const OPA_0 = lvgl_sys::LV_OPA_0;
const OPA_10 = lvgl_sys::LV_OPA_10 as u32; const OPA_10 = lvgl_sys::LV_OPA_10;
const OPA_20 = lvgl_sys::LV_OPA_20 as u32; const OPA_20 = lvgl_sys::LV_OPA_20;
const OPA_30 = lvgl_sys::LV_OPA_30 as u32; const OPA_30 = lvgl_sys::LV_OPA_30;
const OPA_40 = lvgl_sys::LV_OPA_40 as u32; const OPA_40 = lvgl_sys::LV_OPA_40;
const OPA_50 = lvgl_sys::LV_OPA_50 as u32; const OPA_50 = lvgl_sys::LV_OPA_50;
const OPA_60 = lvgl_sys::LV_OPA_60 as u32; const OPA_60 = lvgl_sys::LV_OPA_60;
const OPA_70 = lvgl_sys::LV_OPA_70 as u32; const OPA_70 = lvgl_sys::LV_OPA_70;
const OPA_80 = lvgl_sys::LV_OPA_80 as u32; const OPA_80 = lvgl_sys::LV_OPA_80;
const OPA_90 = lvgl_sys::LV_OPA_90 as u32; const OPA_90 = lvgl_sys::LV_OPA_90;
const OPA_100 = lvgl_sys::LV_OPA_100 as u32; const OPA_100 = lvgl_sys::LV_OPA_100;
const OPA_COVER = lvgl_sys::LV_OPA_COVER as u32; const OPA_COVER = lvgl_sys::LV_OPA_COVER;
} }
} }
impl From<Opacity> for u8 { impl Into<u8> for Opacity {
fn from(self_: Opacity) -> u8 { fn into(self) -> u8 {
self_.bits as u8 self.bits as u8
} }
} }
bitflags! { bitflags! {
pub struct StyleProp: u32 { pub struct StyleProp: u32 {
const RADIUS = lvgl_sys::LV_STYLE_RADIUS as u32; const RADIUS = lvgl_sys::LV_STYLE_RADIUS;
const CLIP_CORNER = lvgl_sys::LV_STYLE_CLIP_CORNER as u32; const CLIP_CORNER = lvgl_sys::LV_STYLE_CLIP_CORNER;
const SIZE = lvgl_sys::LV_STYLE_SIZE as u32; const SIZE = lvgl_sys::LV_STYLE_SIZE;
const TRANSFORM_WIDTH = lvgl_sys::LV_STYLE_TRANSFORM_WIDTH as u32; const TRANSFORM_WIDTH = lvgl_sys::LV_STYLE_TRANSFORM_WIDTH;
const TRANSFORM_HEIGHT = lvgl_sys::LV_STYLE_TRANSFORM_HEIGHT as u32; const TRANSFORM_HEIGHT = lvgl_sys::LV_STYLE_TRANSFORM_HEIGHT;
const TRANSFORM_ANGLE = lvgl_sys::LV_STYLE_TRANSFORM_ANGLE as u32; const TRANSFORM_ANGLE = lvgl_sys::LV_STYLE_TRANSFORM_ANGLE;
const TRANSFORM_ZOOM = lvgl_sys::LV_STYLE_TRANSFORM_ZOOM as u32; const TRANSFORM_ZOOM = lvgl_sys::LV_STYLE_TRANSFORM_ZOOM;
const OPA_SCALE = lvgl_sys::LV_STYLE_OPA_SCALE as u32; const OPA_SCALE = lvgl_sys::LV_STYLE_OPA_SCALE;
const PAD_TOP = lvgl_sys::LV_STYLE_PAD_TOP as u32; const PAD_TOP = lvgl_sys::LV_STYLE_PAD_TOP;
const PAD_BOTTOM = lvgl_sys::LV_STYLE_PAD_BOTTOM as u32; const PAD_BOTTOM = lvgl_sys::LV_STYLE_PAD_BOTTOM;
const PAD_LEFT = lvgl_sys::LV_STYLE_PAD_LEFT as u32; const PAD_LEFT = lvgl_sys::LV_STYLE_PAD_LEFT;
const PAD_RIGHT = lvgl_sys::LV_STYLE_PAD_RIGHT as u32; const PAD_RIGHT = lvgl_sys::LV_STYLE_PAD_RIGHT;
const PAD_INNER = lvgl_sys::LV_STYLE_PAD_INNER as u32; const PAD_INNER = lvgl_sys::LV_STYLE_PAD_INNER;
const MARGIN_TOP = lvgl_sys::LV_STYLE_MARGIN_TOP as u32; const MARGIN_TOP = lvgl_sys::LV_STYLE_MARGIN_TOP;
const MARGIN_BOTTOM = lvgl_sys::LV_STYLE_MARGIN_BOTTOM as u32; const MARGIN_BOTTOM = lvgl_sys::LV_STYLE_MARGIN_BOTTOM;
const MARGIN_LEFT = lvgl_sys::LV_STYLE_MARGIN_LEFT as u32; const MARGIN_LEFT = lvgl_sys::LV_STYLE_MARGIN_LEFT;
const MARGIN_RIGHT = lvgl_sys::LV_STYLE_MARGIN_RIGHT as u32; const MARGIN_RIGHT = lvgl_sys::LV_STYLE_MARGIN_RIGHT;
const BG_BLEND_MODE = lvgl_sys::LV_STYLE_BG_BLEND_MODE as u32; const BG_BLEND_MODE = lvgl_sys::LV_STYLE_BG_BLEND_MODE;
const BG_MAIN_STOP = lvgl_sys::LV_STYLE_BG_MAIN_STOP as u32; const BG_MAIN_STOP = lvgl_sys::LV_STYLE_BG_MAIN_STOP;
const BG_GRAD_STOP = lvgl_sys::LV_STYLE_BG_GRAD_STOP as u32; const BG_GRAD_STOP = lvgl_sys::LV_STYLE_BG_GRAD_STOP;
const BG_GRAD_DIR = lvgl_sys::LV_STYLE_BG_GRAD_DIR as u32; const BG_GRAD_DIR = lvgl_sys::LV_STYLE_BG_GRAD_DIR;
const BG_COLOR = lvgl_sys::LV_STYLE_BG_COLOR as u32; const BG_COLOR = lvgl_sys::LV_STYLE_BG_COLOR;
const BG_GRAD_COLOR = lvgl_sys::LV_STYLE_BG_GRAD_COLOR as u32; const BG_GRAD_COLOR = lvgl_sys::LV_STYLE_BG_GRAD_COLOR;
const BG_OPA = lvgl_sys::LV_STYLE_BG_OPA as u32; const BG_OPA = lvgl_sys::LV_STYLE_BG_OPA;
const BORDER_WIDTH = lvgl_sys::LV_STYLE_BORDER_WIDTH as u32; const BORDER_WIDTH = lvgl_sys::LV_STYLE_BORDER_WIDTH;
const BORDER_SIDE = lvgl_sys::LV_STYLE_BORDER_SIDE as u32; const BORDER_SIDE = lvgl_sys::LV_STYLE_BORDER_SIDE;
const BORDER_BLEND_MODE = lvgl_sys::LV_STYLE_BORDER_BLEND_MODE as u32; const BORDER_BLEND_MODE = lvgl_sys::LV_STYLE_BORDER_BLEND_MODE;
const BORDER_POST = lvgl_sys::LV_STYLE_BORDER_POST as u32; const BORDER_POST = lvgl_sys::LV_STYLE_BORDER_POST;
const BORDER_COLOR = lvgl_sys::LV_STYLE_BORDER_COLOR as u32; const BORDER_COLOR = lvgl_sys::LV_STYLE_BORDER_COLOR;
const BORDER_OPA = lvgl_sys::LV_STYLE_BORDER_OPA as u32; const BORDER_OPA = lvgl_sys::LV_STYLE_BORDER_OPA;
const OUTLINE_WIDTH = lvgl_sys::LV_STYLE_OUTLINE_WIDTH as u32; const OUTLINE_WIDTH = lvgl_sys::LV_STYLE_OUTLINE_WIDTH;
const OUTLINE_PAD = lvgl_sys::LV_STYLE_OUTLINE_PAD as u32; const OUTLINE_PAD = lvgl_sys::LV_STYLE_OUTLINE_PAD;
const OUTLINE_BLEND_MODE = lvgl_sys::LV_STYLE_OUTLINE_BLEND_MODE as u32; const OUTLINE_BLEND_MODE = lvgl_sys::LV_STYLE_OUTLINE_BLEND_MODE;
const OUTLINE_COLOR = lvgl_sys::LV_STYLE_OUTLINE_COLOR as u32; const OUTLINE_COLOR = lvgl_sys::LV_STYLE_OUTLINE_COLOR;
const OUTLINE_OPA = lvgl_sys::LV_STYLE_OUTLINE_OPA as u32; const OUTLINE_OPA = lvgl_sys::LV_STYLE_OUTLINE_OPA;
const SHADOW_WIDTH = lvgl_sys::LV_STYLE_SHADOW_WIDTH as u32; const SHADOW_WIDTH = lvgl_sys::LV_STYLE_SHADOW_WIDTH;
const SHADOW_OFS_X = lvgl_sys::LV_STYLE_SHADOW_OFS_X as u32; const SHADOW_OFS_X = lvgl_sys::LV_STYLE_SHADOW_OFS_X;
const SHADOW_OFS_Y = lvgl_sys::LV_STYLE_SHADOW_OFS_Y as u32; const SHADOW_OFS_Y = lvgl_sys::LV_STYLE_SHADOW_OFS_Y;
const SHADOW_SPREAD = lvgl_sys::LV_STYLE_SHADOW_SPREAD as u32; const SHADOW_SPREAD = lvgl_sys::LV_STYLE_SHADOW_SPREAD;
const SHADOW_BLEND_MODE = lvgl_sys::LV_STYLE_SHADOW_BLEND_MODE as u32; const SHADOW_BLEND_MODE = lvgl_sys::LV_STYLE_SHADOW_BLEND_MODE;
const SHADOW_COLOR = lvgl_sys::LV_STYLE_SHADOW_COLOR as u32; const SHADOW_COLOR = lvgl_sys::LV_STYLE_SHADOW_COLOR;
const SHADOW_OPA = lvgl_sys::LV_STYLE_SHADOW_OPA as u32; const SHADOW_OPA = lvgl_sys::LV_STYLE_SHADOW_OPA;
const PATTERN_BLEND_MODE = lvgl_sys::LV_STYLE_PATTERN_BLEND_MODE as u32; const PATTERN_BLEND_MODE = lvgl_sys::LV_STYLE_PATTERN_BLEND_MODE;
const PATTERN_REPEAT = lvgl_sys::LV_STYLE_PATTERN_REPEAT as u32; const PATTERN_REPEAT = lvgl_sys::LV_STYLE_PATTERN_REPEAT;
const PATTERN_RECOLOR = lvgl_sys::LV_STYLE_PATTERN_RECOLOR as u32; const PATTERN_RECOLOR = lvgl_sys::LV_STYLE_PATTERN_RECOLOR;
const PATTERN_OPA = lvgl_sys::LV_STYLE_PATTERN_OPA as u32; const PATTERN_OPA = lvgl_sys::LV_STYLE_PATTERN_OPA;
const PATTERN_RECOLOR_OPA = lvgl_sys::LV_STYLE_PATTERN_RECOLOR_OPA as u32; const PATTERN_RECOLOR_OPA = lvgl_sys::LV_STYLE_PATTERN_RECOLOR_OPA;
const PATTERN_IMAGE = lvgl_sys::LV_STYLE_PATTERN_IMAGE as u32; const PATTERN_IMAGE = lvgl_sys::LV_STYLE_PATTERN_IMAGE;
const VALUE_LETTER_SPACE = lvgl_sys::LV_STYLE_VALUE_LETTER_SPACE as u32; const VALUE_LETTER_SPACE = lvgl_sys::LV_STYLE_VALUE_LETTER_SPACE;
const VALUE_LINE_SPACE = lvgl_sys::LV_STYLE_VALUE_LINE_SPACE as u32; const VALUE_LINE_SPACE = lvgl_sys::LV_STYLE_VALUE_LINE_SPACE;
const VALUE_BLEND_MODE = lvgl_sys::LV_STYLE_VALUE_BLEND_MODE as u32; const VALUE_BLEND_MODE = lvgl_sys::LV_STYLE_VALUE_BLEND_MODE;
const VALUE_OFS_X = lvgl_sys::LV_STYLE_VALUE_OFS_X as u32; const VALUE_OFS_X = lvgl_sys::LV_STYLE_VALUE_OFS_X;
const VALUE_OFS_Y = lvgl_sys::LV_STYLE_VALUE_OFS_Y as u32; const VALUE_OFS_Y = lvgl_sys::LV_STYLE_VALUE_OFS_Y;
const VALUE_ALIGN = lvgl_sys::LV_STYLE_VALUE_ALIGN as u32; const VALUE_ALIGN = lvgl_sys::LV_STYLE_VALUE_ALIGN;
const VALUE_COLOR = lvgl_sys::LV_STYLE_VALUE_COLOR as u32; const VALUE_COLOR = lvgl_sys::LV_STYLE_VALUE_COLOR;
const VALUE_OPA = lvgl_sys::LV_STYLE_VALUE_OPA as u32; const VALUE_OPA = lvgl_sys::LV_STYLE_VALUE_OPA;
const VALUE_FONT = lvgl_sys::LV_STYLE_VALUE_FONT as u32; const VALUE_FONT = lvgl_sys::LV_STYLE_VALUE_FONT;
const VALUE_STR = lvgl_sys::LV_STYLE_VALUE_STR as u32; const VALUE_STR = lvgl_sys::LV_STYLE_VALUE_STR;
const TEXT_LETTER_SPACE = lvgl_sys::LV_STYLE_TEXT_LETTER_SPACE as u32; const TEXT_LETTER_SPACE = lvgl_sys::LV_STYLE_TEXT_LETTER_SPACE;
const TEXT_LINE_SPACE = lvgl_sys::LV_STYLE_TEXT_LINE_SPACE as u32; const TEXT_LINE_SPACE = lvgl_sys::LV_STYLE_TEXT_LINE_SPACE;
const TEXT_DECOR = lvgl_sys::LV_STYLE_TEXT_DECOR as u32; const TEXT_DECOR = lvgl_sys::LV_STYLE_TEXT_DECOR;
const TEXT_BLEND_MODE = lvgl_sys::LV_STYLE_TEXT_BLEND_MODE as u32; const TEXT_BLEND_MODE = lvgl_sys::LV_STYLE_TEXT_BLEND_MODE;
const TEXT_COLOR = lvgl_sys::LV_STYLE_TEXT_COLOR as u32; const TEXT_COLOR = lvgl_sys::LV_STYLE_TEXT_COLOR;
const TEXT_SEL_COLOR = lvgl_sys::LV_STYLE_TEXT_SEL_COLOR as u32; const TEXT_SEL_COLOR = lvgl_sys::LV_STYLE_TEXT_SEL_COLOR;
const TEXT_OPA = lvgl_sys::LV_STYLE_TEXT_OPA as u32; const TEXT_OPA = lvgl_sys::LV_STYLE_TEXT_OPA;
const TEXT_FONT = lvgl_sys::LV_STYLE_TEXT_FONT as u32; const TEXT_FONT = lvgl_sys::LV_STYLE_TEXT_FONT;
const LINE_WIDTH = lvgl_sys::LV_STYLE_LINE_WIDTH as u32; const LINE_WIDTH = lvgl_sys::LV_STYLE_LINE_WIDTH;
const LINE_BLEND_MODE = lvgl_sys::LV_STYLE_LINE_BLEND_MODE as u32; const LINE_BLEND_MODE = lvgl_sys::LV_STYLE_LINE_BLEND_MODE;
const LINE_DASH_WIDTH = lvgl_sys::LV_STYLE_LINE_DASH_WIDTH as u32; const LINE_DASH_WIDTH = lvgl_sys::LV_STYLE_LINE_DASH_WIDTH;
const LINE_DASH_GAP = lvgl_sys::LV_STYLE_LINE_DASH_GAP as u32; const LINE_DASH_GAP = lvgl_sys::LV_STYLE_LINE_DASH_GAP;
const LINE_ROUNDED = lvgl_sys::LV_STYLE_LINE_ROUNDED as u32; const LINE_ROUNDED = lvgl_sys::LV_STYLE_LINE_ROUNDED;
const LINE_COLOR = lvgl_sys::LV_STYLE_LINE_COLOR as u32; const LINE_COLOR = lvgl_sys::LV_STYLE_LINE_COLOR;
const LINE_OPA = lvgl_sys::LV_STYLE_LINE_OPA as u32; const LINE_OPA = lvgl_sys::LV_STYLE_LINE_OPA;
const IMAGE_BLEND_MODE = lvgl_sys::LV_STYLE_IMAGE_BLEND_MODE as u32; const IMAGE_BLEND_MODE = lvgl_sys::LV_STYLE_IMAGE_BLEND_MODE;
const IMAGE_RECOLOR = lvgl_sys::LV_STYLE_IMAGE_RECOLOR as u32; const IMAGE_RECOLOR = lvgl_sys::LV_STYLE_IMAGE_RECOLOR;
const IMAGE_OPA = lvgl_sys::LV_STYLE_IMAGE_OPA as u32; const IMAGE_OPA = lvgl_sys::LV_STYLE_IMAGE_OPA;
const IMAGE_RECOLOR_OPA = lvgl_sys::LV_STYLE_IMAGE_RECOLOR_OPA as u32; const IMAGE_RECOLOR_OPA = lvgl_sys::LV_STYLE_IMAGE_RECOLOR_OPA;
const TRANSITION_TIME = lvgl_sys::LV_STYLE_TRANSITION_TIME as u32; const TRANSITION_TIME = lvgl_sys::LV_STYLE_TRANSITION_TIME;
const TRANSITION_DELAY = lvgl_sys::LV_STYLE_TRANSITION_DELAY as u32; const TRANSITION_DELAY = lvgl_sys::LV_STYLE_TRANSITION_DELAY;
const TRANSITION_PROP_1 = lvgl_sys::LV_STYLE_TRANSITION_PROP_1 as u32; const TRANSITION_PROP_1 = lvgl_sys::LV_STYLE_TRANSITION_PROP_1;
const TRANSITION_PROP_2 = lvgl_sys::LV_STYLE_TRANSITION_PROP_2 as u32; const TRANSITION_PROP_2 = lvgl_sys::LV_STYLE_TRANSITION_PROP_2;
const TRANSITION_PROP_3 = lvgl_sys::LV_STYLE_TRANSITION_PROP_3 as u32; const TRANSITION_PROP_3 = lvgl_sys::LV_STYLE_TRANSITION_PROP_3;
const TRANSITION_PROP_4 = lvgl_sys::LV_STYLE_TRANSITION_PROP_4 as u32; const TRANSITION_PROP_4 = lvgl_sys::LV_STYLE_TRANSITION_PROP_4;
const TRANSITION_PROP_5 = lvgl_sys::LV_STYLE_TRANSITION_PROP_5 as u32; const TRANSITION_PROP_5 = lvgl_sys::LV_STYLE_TRANSITION_PROP_5;
const TRANSITION_PROP_6 = lvgl_sys::LV_STYLE_TRANSITION_PROP_6 as u32; const TRANSITION_PROP_6 = lvgl_sys::LV_STYLE_TRANSITION_PROP_6;
const TRANSITION_PATH = lvgl_sys::LV_STYLE_TRANSITION_PATH as u32; const TRANSITION_PATH = lvgl_sys::LV_STYLE_TRANSITION_PATH;
const SCALE_WIDTH = lvgl_sys::LV_STYLE_SCALE_WIDTH as u32; const SCALE_WIDTH = lvgl_sys::LV_STYLE_SCALE_WIDTH;
const SCALE_BORDER_WIDTH = lvgl_sys::LV_STYLE_SCALE_BORDER_WIDTH as u32; const SCALE_BORDER_WIDTH = lvgl_sys::LV_STYLE_SCALE_BORDER_WIDTH;
const SCALE_END_BORDER_WIDTH = lvgl_sys::LV_STYLE_SCALE_END_BORDER_WIDTH as u32; const SCALE_END_BORDER_WIDTH = lvgl_sys::LV_STYLE_SCALE_END_BORDER_WIDTH;
const SCALE_END_LINE_WIDTH = lvgl_sys::LV_STYLE_SCALE_END_LINE_WIDTH as u32; const SCALE_END_LINE_WIDTH = lvgl_sys::LV_STYLE_SCALE_END_LINE_WIDTH;
const SCALE_GRAD_COLOR = lvgl_sys::LV_STYLE_SCALE_GRAD_COLOR as u32; const SCALE_GRAD_COLOR = lvgl_sys::LV_STYLE_SCALE_GRAD_COLOR;
const SCALE_END_COLOR = lvgl_sys::LV_STYLE_SCALE_END_COLOR as u32; const SCALE_END_COLOR = lvgl_sys::LV_STYLE_SCALE_END_COLOR;
} }
} }
@ -166,8 +165,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_RADIUS as u32 (lvgl_sys::LV_STYLE_RADIUS | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32))
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, as u16,
value, value,
); );
} }
@ -178,7 +177,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_CLIP_CORNER as u32 (lvgl_sys::LV_STYLE_CLIP_CORNER
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -190,8 +189,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SIZE as u32 (lvgl_sys::LV_STYLE_SIZE | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32))
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, as u16,
value, value,
); );
} }
@ -202,7 +201,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSFORM_WIDTH as u32 (lvgl_sys::LV_STYLE_TRANSFORM_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -214,7 +213,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSFORM_HEIGHT as u32 (lvgl_sys::LV_STYLE_TRANSFORM_HEIGHT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -226,7 +225,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSFORM_ANGLE as u32 (lvgl_sys::LV_STYLE_TRANSFORM_ANGLE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -238,7 +237,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSFORM_ZOOM as u32 (lvgl_sys::LV_STYLE_TRANSFORM_ZOOM
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -250,7 +249,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OPA_SCALE as u32 (lvgl_sys::LV_STYLE_OPA_SCALE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -262,8 +261,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PAD_TOP as u32 (lvgl_sys::LV_STYLE_PAD_TOP | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32))
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, as u16,
value, value,
); );
} }
@ -274,7 +273,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PAD_BOTTOM as u32 (lvgl_sys::LV_STYLE_PAD_BOTTOM
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -286,7 +285,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PAD_LEFT as u32 (lvgl_sys::LV_STYLE_PAD_LEFT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -298,7 +297,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PAD_RIGHT as u32 (lvgl_sys::LV_STYLE_PAD_RIGHT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -310,7 +309,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PAD_INNER as u32 (lvgl_sys::LV_STYLE_PAD_INNER
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -322,7 +321,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_MARGIN_TOP as u32 (lvgl_sys::LV_STYLE_MARGIN_TOP
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -334,7 +333,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_MARGIN_BOTTOM as u32 (lvgl_sys::LV_STYLE_MARGIN_BOTTOM
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -346,7 +345,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_MARGIN_LEFT as u32 (lvgl_sys::LV_STYLE_MARGIN_LEFT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -358,7 +357,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_MARGIN_RIGHT as u32 (lvgl_sys::LV_STYLE_MARGIN_RIGHT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -370,7 +369,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_BG_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -382,7 +381,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_MAIN_STOP as u32 (lvgl_sys::LV_STYLE_BG_MAIN_STOP
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -394,7 +393,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_GRAD_STOP as u32 (lvgl_sys::LV_STYLE_BG_GRAD_STOP
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -406,7 +405,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_GRAD_DIR as u32 (lvgl_sys::LV_STYLE_BG_GRAD_DIR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -418,7 +417,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_COLOR as u32 (lvgl_sys::LV_STYLE_BG_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -430,7 +429,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_GRAD_COLOR as u32 (lvgl_sys::LV_STYLE_BG_GRAD_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -442,8 +441,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BG_OPA as u32 (lvgl_sys::LV_STYLE_BG_OPA | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32))
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, as u16,
value.into(), value.into(),
); );
} }
@ -454,7 +453,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_WIDTH as u32 (lvgl_sys::LV_STYLE_BORDER_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -466,7 +465,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_SIDE as u32 (lvgl_sys::LV_STYLE_BORDER_SIDE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -478,7 +477,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_BORDER_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -490,7 +489,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_POST as u32 (lvgl_sys::LV_STYLE_BORDER_POST
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -502,7 +501,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_COLOR as u32 (lvgl_sys::LV_STYLE_BORDER_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -514,7 +513,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_BORDER_OPA as u32 (lvgl_sys::LV_STYLE_BORDER_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -526,7 +525,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OUTLINE_WIDTH as u32 (lvgl_sys::LV_STYLE_OUTLINE_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -538,7 +537,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OUTLINE_PAD as u32 (lvgl_sys::LV_STYLE_OUTLINE_PAD
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -550,7 +549,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OUTLINE_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_OUTLINE_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -562,7 +561,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OUTLINE_COLOR as u32 (lvgl_sys::LV_STYLE_OUTLINE_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -574,7 +573,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_OUTLINE_OPA as u32 (lvgl_sys::LV_STYLE_OUTLINE_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -586,7 +585,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_WIDTH as u32 (lvgl_sys::LV_STYLE_SHADOW_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -598,7 +597,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_OFS_X as u32 (lvgl_sys::LV_STYLE_SHADOW_OFS_X
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -610,7 +609,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_OFS_Y as u32 (lvgl_sys::LV_STYLE_SHADOW_OFS_Y
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -622,7 +621,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_SPREAD as u32 (lvgl_sys::LV_STYLE_SHADOW_SPREAD
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -634,7 +633,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_SHADOW_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -646,7 +645,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_COLOR as u32 (lvgl_sys::LV_STYLE_SHADOW_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -658,7 +657,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SHADOW_OPA as u32 (lvgl_sys::LV_STYLE_SHADOW_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -670,7 +669,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PATTERN_REPEAT as u32 (lvgl_sys::LV_STYLE_PATTERN_REPEAT
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -682,7 +681,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PATTERN_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_PATTERN_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -694,7 +693,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PATTERN_RECOLOR as u32 (lvgl_sys::LV_STYLE_PATTERN_RECOLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -706,7 +705,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PATTERN_OPA as u32 (lvgl_sys::LV_STYLE_PATTERN_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -718,7 +717,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_PATTERN_RECOLOR_OPA as u32 (lvgl_sys::LV_STYLE_PATTERN_RECOLOR_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -730,7 +729,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_LETTER_SPACE as u32 (lvgl_sys::LV_STYLE_VALUE_LETTER_SPACE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -742,7 +741,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_LINE_SPACE as u32 (lvgl_sys::LV_STYLE_VALUE_LINE_SPACE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -754,7 +753,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_VALUE_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -766,7 +765,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_OFS_X as u32 (lvgl_sys::LV_STYLE_VALUE_OFS_X
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -778,7 +777,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_OFS_Y as u32 (lvgl_sys::LV_STYLE_VALUE_OFS_Y
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -790,7 +789,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_ALIGN as u32 (lvgl_sys::LV_STYLE_VALUE_ALIGN
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -802,7 +801,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_COLOR as u32 (lvgl_sys::LV_STYLE_VALUE_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -814,7 +813,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_VALUE_OPA as u32 (lvgl_sys::LV_STYLE_VALUE_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -826,7 +825,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_LETTER_SPACE as u32 (lvgl_sys::LV_STYLE_TEXT_LETTER_SPACE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -838,7 +837,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_LINE_SPACE as u32 (lvgl_sys::LV_STYLE_TEXT_LINE_SPACE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -850,7 +849,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_DECOR as u32 (lvgl_sys::LV_STYLE_TEXT_DECOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -862,7 +861,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_TEXT_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -874,7 +873,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_COLOR as u32 (lvgl_sys::LV_STYLE_TEXT_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -886,7 +885,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_SEL_COLOR as u32 (lvgl_sys::LV_STYLE_TEXT_SEL_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -898,7 +897,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TEXT_OPA as u32 (lvgl_sys::LV_STYLE_TEXT_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -910,7 +909,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_WIDTH as u32 (lvgl_sys::LV_STYLE_LINE_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -922,7 +921,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_LINE_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -934,7 +933,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_DASH_WIDTH as u32 (lvgl_sys::LV_STYLE_LINE_DASH_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -946,7 +945,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_DASH_GAP as u32 (lvgl_sys::LV_STYLE_LINE_DASH_GAP
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -958,7 +957,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_ROUNDED as u32 (lvgl_sys::LV_STYLE_LINE_ROUNDED
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -970,7 +969,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_COLOR as u32 (lvgl_sys::LV_STYLE_LINE_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -982,7 +981,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_LINE_OPA as u32 (lvgl_sys::LV_STYLE_LINE_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -994,7 +993,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_IMAGE_BLEND_MODE as u32 (lvgl_sys::LV_STYLE_IMAGE_BLEND_MODE
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1006,7 +1005,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_IMAGE_RECOLOR as u32 (lvgl_sys::LV_STYLE_IMAGE_RECOLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
@ -1018,7 +1017,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_IMAGE_OPA as u32 (lvgl_sys::LV_STYLE_IMAGE_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -1030,7 +1029,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_opa( lvgl_sys::_lv_style_set_opa(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_IMAGE_RECOLOR_OPA as u32 (lvgl_sys::LV_STYLE_IMAGE_RECOLOR_OPA
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.into(), value.into(),
); );
@ -1042,7 +1041,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_TIME as u32 (lvgl_sys::LV_STYLE_TRANSITION_TIME
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1054,7 +1053,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_DELAY as u32 (lvgl_sys::LV_STYLE_TRANSITION_DELAY
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1066,7 +1065,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_1 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_1
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1078,7 +1077,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_2 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_2
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1090,7 +1089,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_3 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_3
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1102,7 +1101,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_4 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_4
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1114,7 +1113,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_5 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_5
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1126,7 +1125,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_TRANSITION_PROP_6 as u32 (lvgl_sys::LV_STYLE_TRANSITION_PROP_6
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1138,7 +1137,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_WIDTH as u32 (lvgl_sys::LV_STYLE_SCALE_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1150,7 +1149,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_BORDER_WIDTH as u32 (lvgl_sys::LV_STYLE_SCALE_BORDER_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1162,7 +1161,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_END_BORDER_WIDTH as u32 (lvgl_sys::LV_STYLE_SCALE_END_BORDER_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1174,7 +1173,7 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_int( lvgl_sys::_lv_style_set_int(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_END_LINE_WIDTH as u32 (lvgl_sys::LV_STYLE_SCALE_END_LINE_WIDTH
| (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value, value,
); );
@ -1186,8 +1185,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_GRAD_COLOR as u32 (lvgl_sys::LV_STYLE_SCALE_GRAD_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
} }
@ -1198,8 +1197,8 @@ impl Style {
unsafe { unsafe {
lvgl_sys::_lv_style_set_color( lvgl_sys::_lv_style_set_color(
self.raw.as_mut(), self.raw.as_mut(),
(lvgl_sys::LV_STYLE_SCALE_END_COLOR as u32 (lvgl_sys::LV_STYLE_SCALE_END_COLOR
| (native_state << lvgl_sys::LV_STYLE_STATE_POS)) as u16, | (native_state << lvgl_sys::LV_STYLE_STATE_POS as u32)) as u16,
value.raw, value.raw,
); );
} }

View file

@ -1,17 +1,13 @@
use crate::{LvError, LvResult};
use core::mem; use core::mem;
use core::ops::{Deref, DerefMut}; use core::ops::{Deref, DerefMut};
use core::ptr::NonNull; use core::ptr::NonNull;
/// Places a sized `T` into LVGL memory. /// Places `T` into LVGL memory.
///
/// This is useful for cases when we need to allocate memory on Rust side
/// and handover the management of that memory to LVGL. May also be used in cases we
/// want to use dynamic memory in the Rust side.
pub(crate) struct Box<T>(NonNull<T>); pub(crate) struct Box<T>(NonNull<T>);
impl<T> Box<T> { impl<T> Box<T> {
/// Allocate memory using LVGL memory API and place `T` in the LVGL tracked memory. pub fn new(inner: T) -> LvResult<Box<T>> {
pub fn new(value: T) -> Box<T> {
let size = mem::size_of::<T>(); let size = mem::size_of::<T>();
let inner = unsafe { let inner = unsafe {
let ptr = lvgl_sys::lv_mem_alloc(size as lvgl_sys::size_t) as *mut T; let ptr = lvgl_sys::lv_mem_alloc(size as lvgl_sys::size_t) as *mut T;
@ -23,16 +19,17 @@ impl<T> Box<T> {
"Memory address not aligned!" "Memory address not aligned!"
); );
NonNull::new(ptr) match NonNull::new(ptr) {
.map(|p| { Some(v) => {
p.as_ptr().write(value); // Move `T` to LVGL managed memory
p // It will panic if LVGL memory is not aligned
}) ptr.write(inner);
.unwrap_or_else(|| { Ok(v)
panic!("Could not allocate memory {} bytes", size); }
}) None => Err(LvError::LvOOMemory),
}
}; };
Box(inner) Ok(Box(inner?))
} }
pub fn into_raw(self) -> *mut T { pub fn into_raw(self) -> *mut T {
@ -69,30 +66,35 @@ impl<T> AsMut<T> for Box<T> {
} }
} }
impl<T: Clone> Clone for Box<T> {
fn clone(&self) -> Self {
unsafe { Self::new(self.0.as_ref().clone()) }
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use std::vec::Vec; use core::mem::MaybeUninit;
use std::sync::Once;
static INIT_LVGL: Once = Once::new();
fn init() {
INIT_LVGL.call_once(|| {
unsafe {
lvgl_sys::lv_init();
};
});
}
#[test] #[test]
fn place_value_in_lv_mem() { fn place_value_in_lv_mem() {
crate::lvgl_init(); init();
let v = Box::new(5); let v = Box::new(5).unwrap();
drop(v); drop(v);
let v = Box::new(10); let v = Box::new(10).unwrap();
drop(v); drop(v);
} }
#[test] #[test]
fn place_complex_value_in_lv_mem() { fn place_complex_value_in_lv_mem() {
crate::lvgl_init(); init();
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
@ -103,9 +105,6 @@ mod test {
disp: i32, disp: i32,
} }
let initial_mem_info = mem_info();
let mut keep = Vec::new();
for i in 0..100 { for i in 0..100 {
let p = Point { let p = Point {
x: i, x: i,
@ -115,60 +114,31 @@ mod test {
}; };
println!("{:?}", p); println!("{:?}", p);
let mut b = Box::new(p); let mut b = Box::new(p).unwrap_or_else(|_| {
print_mem_info();
panic!("OOM");
});
println!("memory address is {:p}", b.as_mut()); println!("memory address is {:p}", b.as_mut());
let point = b.as_mut(); let point = b.as_mut();
if point.x != i { if point.x != i {
print_mem_info();
println!("{:?}", point); println!("{:?}", point);
} }
assert_eq!(point.x, i); assert_eq!(point.x, i);
let info = mem_info();
println!("mem info: {:?}", &info);
keep.push(b);
} }
drop(keep);
unsafe {
lvgl_sys::lv_mem_defrag();
}
let final_info = mem_info();
println!("mem info: {:?}", &final_info);
// If this fails, we are leaking memory! BOOM! \o/
assert_eq!(initial_mem_info.free_size, final_info.free_size)
} }
#[test] fn print_mem_info() {
fn clone_object_in_lv_mem() { let mut info = MaybeUninit::uninit();
crate::lvgl_init();
let v1 = Box::new(5);
let v2 = v1.clone();
// Ensure that the two objects have identical values.
assert_eq!(*v1, *v2);
// They should have different memory addresses, however.
assert_ne!(v1.into_raw() as usize, v2.into_raw() as usize);
}
fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
let mut info = lvgl_sys::lv_mem_monitor_t {
total_size: 0,
free_cnt: 0,
free_size: 0,
free_biggest_size: 0,
used_cnt: 0,
max_used: 0,
used_pct: 0,
frag_pct: 0,
};
unsafe { unsafe {
lvgl_sys::lv_mem_monitor(&mut info as *mut _); lvgl_sys::lv_mem_monitor(info.as_mut_ptr());
}
if !info.as_ptr().is_null() {
let info = unsafe { info.assume_init() };
println!("mem info: {:?}", info);
} }
info
} }
} }

View file

@ -29,15 +29,21 @@ impl Color {
} }
pub fn r(&self) -> u8 { pub fn r(&self) -> u8 {
unsafe { lvgl_sys::_LV_COLOR_GET_R(self.raw) as u8 } unsafe {
lvgl_sys::_LV_COLOR_GET_R(self.raw) as u8
}
} }
pub fn g(&self) -> u8 { pub fn g(&self) -> u8 {
unsafe { lvgl_sys::_LV_COLOR_GET_G(self.raw) as u8 } unsafe {
lvgl_sys::_LV_COLOR_GET_G(self.raw) as u8
}
} }
pub fn b(&self) -> u8 { pub fn b(&self) -> u8 {
unsafe { lvgl_sys::_LV_COLOR_GET_B(self.raw) as u8 } unsafe {
lvgl_sys::_LV_COLOR_GET_B(self.raw) as u8
}
} }
} }
@ -65,7 +71,7 @@ impl From<Color> for Rgb565 {
} }
} }
/// Events are triggered in LVGL when something happens which might be interesting to /// Events are triggered in LittlevGL when something happens which might be interesting to
/// the user, e.g. if an object: /// the user, e.g. if an object:
/// - is clicked /// - is clicked
/// - is dragged /// - is dragged
@ -112,25 +118,23 @@ impl<S> TryFrom<lvgl_sys::lv_event_t> for Event<S> {
type Error = (); type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> { fn try_from(value: u8) -> Result<Self, Self::Error> {
const LV_EVENT_PRESSED: u32 = lvgl_sys::LV_EVENT_PRESSED as u32;
const LV_EVENT_PRESSING: u32 = lvgl_sys::LV_EVENT_PRESSING as u32;
const LV_EVENT_PRESS_LOST: u32 = lvgl_sys::LV_EVENT_PRESS_LOST as u32;
const LV_EVENT_SHORT_CLICKED: u32 = lvgl_sys::LV_EVENT_SHORT_CLICKED as u32;
const LV_EVENT_CLICKED: u32 = lvgl_sys::LV_EVENT_CLICKED as u32;
const LV_EVENT_LONG_PRESSED: u32 = lvgl_sys::LV_EVENT_LONG_PRESSED as u32;
const LV_EVENT_LONG_PRESSED_REPEAT: u32 = lvgl_sys::LV_EVENT_LONG_PRESSED_REPEAT as u32;
const LV_EVENT_RELEASED: u32 = lvgl_sys::LV_EVENT_RELEASED as u32;
match value as u32 { match value as u32 {
LV_EVENT_PRESSED => Ok(Event::Pressed), lvgl_sys::LV_EVENT_PRESSED => Ok(Event::Pressed),
LV_EVENT_PRESSING => Ok(Event::Pressing), lvgl_sys::LV_EVENT_PRESSING => Ok(Event::Pressing),
LV_EVENT_PRESS_LOST => Ok(Event::PressLost), lvgl_sys::LV_EVENT_PRESS_LOST => Ok(Event::PressLost),
LV_EVENT_SHORT_CLICKED => Ok(Event::ShortClicked), lvgl_sys::LV_EVENT_SHORT_CLICKED => Ok(Event::ShortClicked),
LV_EVENT_CLICKED => Ok(Event::Clicked), lvgl_sys::LV_EVENT_CLICKED => Ok(Event::Clicked),
LV_EVENT_LONG_PRESSED => Ok(Event::LongPressed), lvgl_sys::LV_EVENT_LONG_PRESSED => Ok(Event::LongPressed),
LV_EVENT_LONG_PRESSED_REPEAT => Ok(Event::LongPressedRepeat), lvgl_sys::LV_EVENT_LONG_PRESSED_REPEAT => Ok(Event::LongPressedRepeat),
LV_EVENT_RELEASED => Ok(Event::Released), lvgl_sys::LV_EVENT_RELEASED => Ok(Event::Released),
_ => Err(()), _ => Err(()),
// _ => {
// if let Ok(special_event_type) = S::try_from(value) {
// Ok(Event::Special(special_event_type))
// } else {
// Err(())
// }
// }
} }
} }
} }
@ -203,9 +207,9 @@ pub enum Align {
OutRightBottom, OutRightBottom,
} }
impl From<Align> for u8 { impl Into<u8> for Align {
fn from(self_: Align) -> u8 { fn into(self) -> u8 {
let native = match self_ { let native = match self {
Align::Center => lvgl_sys::LV_ALIGN_CENTER, Align::Center => lvgl_sys::LV_ALIGN_CENTER,
Align::InTopLeft => lvgl_sys::LV_ALIGN_IN_TOP_LEFT, Align::InTopLeft => lvgl_sys::LV_ALIGN_IN_TOP_LEFT,
Align::InTopMid => lvgl_sys::LV_ALIGN_IN_TOP_MID, Align::InTopMid => lvgl_sys::LV_ALIGN_IN_TOP_MID,
@ -246,9 +250,11 @@ impl From<Animation> for lvgl_sys::lv_anim_enable_t {
} }
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use lvgl_sys;
#[test] #[test]
fn color_properties_accessible() { fn color_properties_accessible() {

View file

@ -1,4 +1,4 @@
use crate::Box; use crate::mem::Box;
use crate::{Color, Event, LvError, LvResult, Obj, Widget}; use crate::{Color, Event, LvError, LvResult, Obj, Widget};
use core::marker::PhantomData; use core::marker::PhantomData;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
@ -6,11 +6,11 @@ use core::ptr;
use core::ptr::NonNull; use core::ptr::NonNull;
use core::sync::atomic::{AtomicBool, Ordering}; use core::sync::atomic::{AtomicBool, Ordering};
use core::time::Duration; use core::time::Duration;
use embedded_graphics::draw_target::DrawTarget; use embedded_graphics::pixelcolor::PixelColor;
use embedded_graphics::prelude::*; use embedded_graphics::prelude::*;
use embedded_graphics::{pixelcolor::PixelColor, Pixel}; use embedded_graphics::{drawable, DrawTarget};
// There can only be a single reference to LVGL library. // There can only be a single reference to LittlevGL library.
static LVGL_IN_USE: AtomicBool = AtomicBool::new(false); static LVGL_IN_USE: AtomicBool = AtomicBool::new(false);
// TODO: Make this an external configuration // TODO: Make this an external configuration
@ -20,34 +20,33 @@ pub(crate) const BUF_SIZE: usize = lvgl_sys::LV_HOR_RES_MAX as usize * REFRESH_B
pub struct UI<T, C> pub struct UI<T, C>
where where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
// LVGL is not thread-safe by default. // LittlevGL is not thread-safe by default.
_not_sync: PhantomData<*mut ()>, _not_sync: PhantomData<*mut ()>,
// Later we can add possibility to have multiple displays by using `heapless::Vec` // Later we can add possibility to have multiple displays by using `heapless::Vec`
display_data: Option<DisplayUserData<T, C>>, display_data: Option<DisplayUserData<T, C>>,
} }
// LVGL does not use thread locals. // LittlevGL does not use thread locals.
unsafe impl<T, C> Send for UI<T, C> unsafe impl<T, C> Send for UI<T, C>
where where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
} }
impl<T, C> UI<T, C> impl<T, C> UI<T, C>
where where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
pub fn init() -> LvResult<Self> { pub fn init() -> LvResult<Self> {
if LVGL_IN_USE if !LVGL_IN_USE.compare_and_swap(false, true, Ordering::SeqCst) {
.compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) unsafe {
.is_ok() lvgl_sys::lv_init();
{ }
crate::lvgl_init();
Ok(Self { Ok(Self {
_not_sync: PhantomData, _not_sync: PhantomData,
display_data: None, display_data: None,
@ -73,15 +72,15 @@ where
// Initialize the display buffer // Initialize the display buffer
lvgl_sys::lv_disp_buf_init( lvgl_sys::lv_disp_buf_init(
disp_buf.as_mut_ptr(), disp_buf.as_mut_ptr(),
Box::into_raw(Box::new(refresh_buffer1)) as *mut cty::c_void, Box::into_raw(Box::new(refresh_buffer1)?) as *mut cty::c_void,
Box::into_raw(Box::new(refresh_buffer2)) as *mut cty::c_void, Box::into_raw(Box::new(refresh_buffer2)?) as *mut cty::c_void,
lvgl_sys::LV_HOR_RES_MAX * REFRESH_BUFFER_LEN as u32, lvgl_sys::LV_HOR_RES_MAX * REFRESH_BUFFER_LEN as u32,
); );
// Basic initialization of the display driver // Basic initialization of the display driver
lvgl_sys::lv_disp_drv_init(disp_drv.as_mut_ptr()); lvgl_sys::lv_disp_drv_init(disp_drv.as_mut_ptr());
let mut disp_drv = Box::new(disp_drv.assume_init()); let mut disp_drv = Box::new(disp_drv.assume_init())?;
// Assign the buffer to the display // Assign the buffer to the display
disp_drv.buffer = Box::into_raw(Box::new(disp_buf.assume_init())); disp_drv.buffer = Box::into_raw(Box::new(disp_buf.assume_init())?);
// Set your driver function // Set your driver function
disp_drv.flush_cb = Some(display_callback_wrapper::<T, C>); disp_drv.flush_cb = Some(display_callback_wrapper::<T, C>);
disp_drv.user_data = &mut self.display_data as *mut _ as *mut cty::c_void; disp_drv.user_data = &mut self.display_data as *mut _ as *mut cty::c_void;
@ -135,7 +134,7 @@ where
pub(crate) struct DisplayUserData<T, C> pub(crate) struct DisplayUserData<T, C>
where where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
display: T, display: T,
@ -147,7 +146,7 @@ unsafe extern "C" fn display_callback_wrapper<T, C>(
area: *const lvgl_sys::lv_area_t, area: *const lvgl_sys::lv_area_t,
color_p: *mut lvgl_sys::lv_color_t, color_p: *mut lvgl_sys::lv_color_t,
) where ) where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
// In the `std` world we would make sure to capture panics here and make them not escape across // In the `std` world we would make sure to capture panics here and make them not escape across
@ -164,12 +163,12 @@ unsafe extern "C" fn display_callback_wrapper<T, C>(
// TODO: Can we do anything when there is a error while flushing? // TODO: Can we do anything when there is a error while flushing?
let _ = display_flush(&mut user_data.display, (x1, x2), (y1, y2), color_p); let _ = display_flush(&mut user_data.display, (x1, x2), (y1, y2), color_p);
} }
// Indicate to LVGL that we are ready with the flushing // Indicate to LittlevGL that we are ready with the flushing
lvgl_sys::lv_disp_flush_ready(disp_drv); lvgl_sys::lv_disp_flush_ready(disp_drv);
} }
// We separate this display flush function to reduce the amount of unsafe code we need to write. // We separate this display flush function to reduce the amount of unsafe code we need to write.
// This also provides a good separation of concerns, what is necessary from LVGL to work and // This also provides a good separation of concerns, what is necessary from LittlevGL to work and
// what is the lvgl-rs wrapper responsibility. // what is the lvgl-rs wrapper responsibility.
fn display_flush<T, C>( fn display_flush<T, C>(
display: &mut T, display: &mut T,
@ -178,7 +177,7 @@ fn display_flush<T, C>(
color_p: *mut lvgl_sys::lv_color_t, color_p: *mut lvgl_sys::lv_color_t,
) -> Result<(), T::Error> ) -> Result<(), T::Error>
where where
T: DrawTarget<Color = C>, T: DrawTarget<C>,
C: PixelColor + From<Color>, C: PixelColor + From<Color>,
{ {
let ys = y1..=y2; let ys = y1..=y2;
@ -187,14 +186,17 @@ where
// We use iterators here to ensure that the Rust compiler can apply all possible // We use iterators here to ensure that the Rust compiler can apply all possible
// optimizations at compile time. // optimizations at compile time.
let pixels = ys.enumerate().flat_map(|(iy, y)| { let pixels = ys
xs.clone().map(move |(ix, x)| { .enumerate()
let color_len = x_len * iy + ix; .map(|(iy, y)| {
let lv_color = unsafe { *color_p.add(color_len) }; xs.clone().map(move |(ix, x)| {
let raw_color = Color::from_raw(lv_color); let color_len = x_len * iy + ix;
Pixel(Point::new(x as i32, y as i32), raw_color.into()) let lv_color = unsafe { *color_p.add(color_len) };
let raw_color = Color::from_raw(lv_color);
drawable::Pixel(Point::new(x as i32, y as i32), raw_color.into())
})
}) })
}); .flatten();
display.draw_iter(pixels) Ok(display.draw_iter(pixels)?)
} }