@@ -58,20 +58,28 @@ impl Rusty for LvWidget {
5858 type Parent = ( ) ;
5959
6060 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-
6661 let widget_name = format_ident ! ( "{}" , self . pascal_name( ) ) ;
6762 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>;
7068
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+ }
7583 }
7684}
7785
@@ -106,7 +114,7 @@ impl Rusty for LvFunc {
106114 let original_func_name = format_ident ! ( "{}" , self . name. as_str( ) ) ;
107115
108116 // generate constructor
109- if new_name. as_str ( ) . eq ( "create" ) {
117+ if new_name. as_str ( ) . eq ( "create" ) && parent . name != "obj" {
110118 return Ok ( quote ! {
111119
112120 pub fn create( parent: & mut impl crate :: NativeObject ) -> crate :: LvResult <Self > {
@@ -115,7 +123,7 @@ impl Rusty for LvFunc {
115123 parent. raw( ) . as_mut( ) ,
116124 ) ;
117125 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( ) ;
119127 Ok ( Self { core } )
120128 } else {
121129 Err ( crate :: LvError :: InvalidReference )
@@ -243,7 +251,11 @@ impl Rusty for LvFunc {
243251 . enumerate ( )
244252 . fold ( quote ! ( ) , |args_accumulator, ( arg_idx, arg) | {
245253 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+ }
247259 } else if arg. typ . is_mut_native_object ( ) {
248260 let var = arg. get_value_usage ( ) ;
249261 quote ! { #var. raw( ) . as_mut( ) }
@@ -275,17 +287,30 @@ impl Rusty for LvFunc {
275287 None => quote ! ( ; ) ,
276288 _ => quote ! ( ) ,
277289 } ;
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+ }
286300 }
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+ }
289314 }
290315}
291316
@@ -927,7 +952,7 @@ mod test {
927952 parent. raw( ) . as_mut( ) ,
928953 ) ;
929954 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( ) ;
931956 Ok ( Self { core } )
932957 } else {
933958 Err ( crate :: LvError :: InvalidReference )
0 commit comments