@@ -58,20 +58,28 @@ impl Rusty for LvWidget {
58
58
type Parent = ( ) ;
59
59
60
60
fn code ( & self , _parent : & Self :: Parent ) -> WrapperResult < TokenStream > {
61
- // We don't generate for the generic Obj
62
- if self . name . as_str ( ) . eq ( "obj" ) {
63
- return Err ( WrapperError :: Skip ) ;
64
- }
65
-
66
61
let widget_name = format_ident ! ( "{}" , self . pascal_name( ) ) ;
67
62
let methods: Vec < TokenStream > = self . methods . iter ( ) . flat_map ( |m| m. code ( self ) ) . collect ( ) ;
68
- Ok ( quote ! {
69
- define_object!( #widget_name) ;
63
+ if self . name . as_str ( ) . eq ( "obj" ) {
64
+ Ok ( quote ! {
65
+ pub trait Widget <' a>: NativeObject + Sized + ' a {
66
+ type SpecialEvent ;
67
+ type Part : Into <lvgl_sys:: lv_part_t>;
70
68
71
- impl <' a> #widget_name<' a> {
72
- #( #methods) *
73
- }
74
- } )
69
+ unsafe fn from_raw( raw_pointer: core:: ptr:: NonNull <lvgl_sys:: lv_obj_t>) -> Option <Self >;
70
+
71
+ #( #methods) *
72
+ }
73
+ } )
74
+ } else {
75
+ Ok ( quote ! {
76
+ define_object!( #widget_name) ;
77
+
78
+ impl <' a> #widget_name<' a> {
79
+ #( #methods) *
80
+ }
81
+ } )
82
+ }
75
83
}
76
84
}
77
85
@@ -106,7 +114,7 @@ impl Rusty for LvFunc {
106
114
let original_func_name = format_ident ! ( "{}" , self . name. as_str( ) ) ;
107
115
108
116
// generate constructor
109
- if new_name. as_str ( ) . eq ( "create" ) {
117
+ if new_name. as_str ( ) . eq ( "create" ) && parent . name != "obj" {
110
118
return Ok ( quote ! {
111
119
112
120
pub fn create( parent: & mut impl crate :: NativeObject ) -> crate :: LvResult <Self > {
@@ -115,7 +123,7 @@ impl Rusty for LvFunc {
115
123
parent. raw( ) . as_mut( ) ,
116
124
) ;
117
125
if let Some ( raw) = core:: ptr:: NonNull :: new( ptr) {
118
- let core = <crate :: Obj as crate :: Widget >:: from_raw( raw) . unwrap( ) ;
126
+ let core = <crate :: Obj as Widget >:: from_raw( raw) . unwrap( ) ;
119
127
Ok ( Self { core } )
120
128
} else {
121
129
Err ( crate :: LvError :: InvalidReference )
@@ -243,7 +251,11 @@ impl Rusty for LvFunc {
243
251
. enumerate ( )
244
252
. fold ( quote ! ( ) , |args_accumulator, ( arg_idx, arg) | {
245
253
let next_arg = if arg_idx == 0 {
246
- quote ! ( self . core. raw( ) . as_mut( ) )
254
+ if parent. name == "obj" {
255
+ quote ! ( self . raw( ) . as_mut( ) )
256
+ } else {
257
+ quote ! ( self . core. raw( ) . as_mut( ) )
258
+ }
247
259
} else if arg. typ . is_mut_native_object ( ) {
248
260
let var = arg. get_value_usage ( ) ;
249
261
quote ! { #var. raw( ) . as_mut( ) }
@@ -275,17 +287,30 @@ impl Rusty for LvFunc {
275
287
None => quote ! ( ; ) ,
276
288
_ => quote ! ( ) ,
277
289
} ;
278
-
279
- Ok ( quote ! {
280
- pub fn #func_name( #args_decl) -> #return_type {
281
- unsafe {
282
- #args_preprocessing
283
- lvgl_sys:: #original_func_name( #ffi_args) #optional_semicolon
284
- #args_postprocessing
285
- #explicit_ok
290
+ if parent. name == "obj" {
291
+ // pub keyword cannot be used in traits
292
+ Ok ( quote ! {
293
+ fn #func_name( #args_decl) -> #return_type {
294
+ unsafe {
295
+ #args_preprocessing
296
+ lvgl_sys:: #original_func_name( #ffi_args) #optional_semicolon
297
+ #args_postprocessing
298
+ #explicit_ok
299
+ }
286
300
}
287
- }
288
- } )
301
+ } )
302
+ } else {
303
+ Ok ( quote ! {
304
+ pub fn #func_name( #args_decl) -> #return_type {
305
+ unsafe {
306
+ #args_preprocessing
307
+ lvgl_sys:: #original_func_name( #ffi_args) #optional_semicolon
308
+ #args_postprocessing
309
+ #explicit_ok
310
+ }
311
+ }
312
+ } )
313
+ }
289
314
}
290
315
}
291
316
@@ -927,7 +952,7 @@ mod test {
927
952
parent. raw( ) . as_mut( ) ,
928
953
) ;
929
954
if let Some ( raw) = core:: ptr:: NonNull :: new( ptr) {
930
- let core = <crate :: Obj as crate :: Widget >:: from_raw( raw) . unwrap( ) ;
955
+ let core = <crate :: Obj as Widget >:: from_raw( raw) . unwrap( ) ;
931
956
Ok ( Self { core } )
932
957
} else {
933
958
Err ( crate :: LvError :: InvalidReference )
0 commit comments