Fix types
This commit is contained in:
parent
ceabc135cc
commit
ad5a3deea4
4 changed files with 29 additions and 28 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lvgl-codegen"
|
name = "lvgl-codegen"
|
||||||
version = "0.1.0"
|
version = "0.3.0"
|
||||||
description = "Code generation based on LVGL source code"
|
description = "Code generation based on LVGL source code"
|
||||||
authors = ["Rafael Caricio <rafael@caricio.com>"]
|
authors = ["Rafael Caricio <rafael@caricio.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
|
@ -15,12 +15,11 @@ const LIB_PREFIX: &str = "lv_";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TYPE_MAPPINGS: HashMap<&'static str, &'static str> = [
|
static ref TYPE_MAPPINGS: HashMap<&'static str, &'static str> = [
|
||||||
("uint16_t", "u16"),
|
("u16", "u16"),
|
||||||
("int32_t", "i32"),
|
("i32", "i32"),
|
||||||
("uint8_t", "u8"),
|
("u8", "u8"),
|
||||||
("bool", "bool"),
|
("bool", "bool"),
|
||||||
("_Bool", "bool"),
|
("* const cty :: c_char", "&str"),
|
||||||
("const char *", "&str"),
|
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
@ -329,7 +328,7 @@ impl LvType {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_str(&self) -> bool {
|
pub fn is_str(&self) -> bool {
|
||||||
self.literal_name.ends_with("char *")
|
self.literal_name.ends_with("* const cty :: c_char")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,12 +526,12 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_method_wrapper() {
|
fn generate_method_wrapper() {
|
||||||
// void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end);
|
// pub fn lv_arc_set_bg_end_angle(arc: *mut lv_obj_t, end: u16);
|
||||||
let arc_set_bg_end_angle = LvFunc::new(
|
let arc_set_bg_end_angle = LvFunc::new(
|
||||||
"lv_arc_set_bg_end_angle".to_string(),
|
"lv_arc_set_bg_end_angle".to_string(),
|
||||||
vec![
|
vec![
|
||||||
LvArg::new("arc".to_string(), LvType::new("lv_obj_t *".to_string())),
|
LvArg::new("arc".to_string(), LvType::new("*mut lv_obj_t".to_string())),
|
||||||
LvArg::new("end".to_string(), LvType::new("uint16_t".to_string())),
|
LvArg::new("end".to_string(), LvType::new("u16".to_string())),
|
||||||
],
|
],
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -556,15 +555,17 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_method_wrapper_for_str_types_as_argument() {
|
fn generate_method_wrapper_for_str_types_as_argument() {
|
||||||
// void lv_label_set_text(lv_obj_t * label, const char * text)
|
let bindgen_code = quote! {
|
||||||
let label_set_text = LvFunc::new(
|
extern "C" {
|
||||||
"lv_label_set_text".to_string(),
|
#[doc = " Set a new text for a label. Memory will be allocated to store the text by the label."]
|
||||||
vec![
|
#[doc = " @param label pointer to a label object"]
|
||||||
LvArg::new("label".to_string(), LvType::new("lv_obj_t *".to_string())),
|
#[doc = " @param text '\\0' terminated character string. NULL to refresh with the current text."]
|
||||||
LvArg::new("text".to_string(), LvType::new("const char *".to_string())),
|
pub fn lv_label_set_text(label: *mut lv_obj_t, text: *const cty::c_char);
|
||||||
],
|
}
|
||||||
None,
|
};
|
||||||
);
|
let cg = CodeGen::load_func_defs(bindgen_code.to_string().as_str()).unwrap();
|
||||||
|
|
||||||
|
let label_set_text = cg.get(0).unwrap().clone();
|
||||||
let parent_widget = LvWidget {
|
let parent_widget = LvWidget {
|
||||||
name: "label".to_string(),
|
name: "label".to_string(),
|
||||||
methods: vec![],
|
methods: vec![],
|
||||||
|
@ -608,17 +609,17 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_widget_with_constructor_code() {
|
fn generate_widget_with_constructor_code() {
|
||||||
// lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy);
|
// pub fn lv_arc_create(par: *mut lv_obj_t, copy: *const lv_obj_t) -> *mut lv_obj_t;
|
||||||
let arc_create = LvFunc::new(
|
let arc_create = LvFunc::new(
|
||||||
"lv_arc_create".to_string(),
|
"lv_arc_create".to_string(),
|
||||||
vec![
|
vec![
|
||||||
LvArg::new("par".to_string(), LvType::new("lv_obj_t *".to_string())),
|
LvArg::new("par".to_string(), LvType::new("*mut lv_obj_t".to_string())),
|
||||||
LvArg::new(
|
LvArg::new(
|
||||||
"copy".to_string(),
|
"copy".to_string(),
|
||||||
LvType::new("const lv_obj_t *".to_string()),
|
LvType::new("*const lv_obj_t".to_string()),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
Some(LvType::new("lv_obj_t *".to_string())),
|
Some(LvType::new("*mut lv_obj_t".to_string())),
|
||||||
);
|
);
|
||||||
|
|
||||||
let arc_widget = LvWidget {
|
let arc_widget = LvWidget {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lvgl-sys"
|
name = "lvgl-sys"
|
||||||
description = "Raw bindings to the LittlevGL C library."
|
description = "Raw bindings to the LittlevGL C library."
|
||||||
version = "0.2.0"
|
version = "0.3.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"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "lvgl"
|
name = "lvgl"
|
||||||
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)."
|
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.2.1"
|
version = "0.3.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,7 +12,7 @@ keywords = ["littlevgl", "lvgl", "graphical_interfaces"]
|
||||||
include = ["Cargo.toml", "src/**/*", "src/widgets/generated.rs"]
|
include = ["Cargo.toml", "src/**/*", "src/widgets/generated.rs"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" }
|
lvgl-sys = { version = "0.3.0", path = "../lvgl-sys" }
|
||||||
cty = "0.2.1"
|
cty = "0.2.1"
|
||||||
embedded-graphics = "0.6.2"
|
embedded-graphics = "0.6.2"
|
||||||
cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"] }
|
cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"] }
|
||||||
|
@ -21,6 +21,6 @@ bitflags = "1.2.1"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
quote = "1.0.7"
|
quote = "1.0.7"
|
||||||
proc-macro2 = "1.0.18"
|
proc-macro2 = "1.0.18"
|
||||||
lvgl-codegen = { version = "0.1.0", path = "../lvgl-codegen" }
|
lvgl-codegen = { version = "0.3.0", path = "../lvgl-codegen" }
|
||||||
lvgl-sys = { path = "../lvgl-sys", version = "0.2.0" }
|
lvgl-sys = { version = "0.3.0", path = "../lvgl-sys" }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue