1111
1212namespace LVGLSharp . Runtime . Linux
1313{
14- public unsafe class FrameBufferView : ViewLifetimeBase , IView
14+ public unsafe class FrameBufferView : ViewLifetimeBase
1515 {
1616 static lv_display_t * g_display ;
1717 static lv_indev_t * g_indev ;
@@ -23,9 +23,9 @@ public unsafe class FrameBufferView : ViewLifetimeBase, IView
2323 public static lv_group_t * KeyInputGroupObject { get ; set ; } = null ;
2424 public static delegate * unmanaged[ Cdecl] < lv_event_t * , void > SendTextAreaFocusCallbackCore { get ; set ; } = null ;
2525
26- public lv_obj_t * Root => RootObject ;
27- public lv_group_t * KeyInputGroup => KeyInputGroupObject ;
28- public delegate * unmanaged[ Cdecl] < lv_event_t * , void > SendTextAreaFocusCallback => SendTextAreaFocusCallbackCore ;
26+ public override lv_obj_t * Root => RootObject ;
27+ public override lv_group_t * KeyInputGroup => KeyInputGroupObject ;
28+ public override delegate * unmanaged[ Cdecl] < lv_event_t * , void > SendTextAreaFocusCallback => SendTextAreaFocusCallbackCore ;
2929
3030 private lv_font_t * _fallbackFont ;
3131 private lv_style_t * _defaultFontStyle ;
@@ -48,58 +48,45 @@ public FrameBufferView(string fbdev = "/dev/fb0", string indev = "/dev/input/eve
4848 _dpi = dpi ;
4949 }
5050
51- public void Open ( )
51+ protected override void OnOpenCore ( )
5252 {
53- if ( ! TryBeginOpen ( ) )
54- {
55- return ;
56- }
57-
5853 if ( g_running )
5954 {
6055 return ;
6156 }
6257
63- try
64- {
65- LvglNativeLibraryResolver . EnsureRegistered ( ) ;
66- g_running = true ;
67- startTick = Environment . TickCount ;
68- lv_init ( ) ;
69- lv_tick_set_cb ( & my_tick ) ;
70-
71- g_display = lv_linux_fbdev_create ( ) ;
72- fixed ( byte * ptr = Encoding . ASCII . GetBytes ( $ "{ _fbdev } \0 ") )
73- lv_linux_fbdev_set_file ( g_display , ptr ) ;
74-
75- fixed ( byte * ptr = Encoding . ASCII . GetBytes ( $ "{ _indev } \0 ") )
76- g_indev = lv_evdev_create ( lv_indev_type_t . LV_INDEV_TYPE_POINTER , ptr ) ;
77-
78- RootObject = lv_scr_act ( ) ;
79-
80- _fallbackFont = lv_obj_get_style_text_font ( RootObject , LV_PART_MAIN ) ;
81-
82- var systemFontPath = LinuxSystemFontResolver . TryResolveFontPath ( ) ;
83- if ( ! string . IsNullOrWhiteSpace ( systemFontPath ) )
84- {
85- _fontManager = new SixLaborsFontManager (
86- systemFontPath ,
87- 12 ,
88- _dpi ,
89- _fallbackFont ,
90- LvglHostDefaults . CreateDefaultFontFallbackGlyphs ( ) ) ;
91-
92- _defaultFontStyle = LvglHostDefaults . ApplyDefaultFontStyle ( RootObject , _fontManager . GetLvFontPtr ( ) ) ;
93- }
94- }
95- catch
58+ LvglNativeLibraryResolver . EnsureRegistered ( ) ;
59+ g_running = true ;
60+ startTick = Environment . TickCount ;
61+ lv_init ( ) ;
62+ lv_tick_set_cb ( & my_tick ) ;
63+
64+ g_display = lv_linux_fbdev_create ( ) ;
65+ fixed ( byte * ptr = Encoding . ASCII . GetBytes ( $ "{ _fbdev } \0 ") )
66+ lv_linux_fbdev_set_file ( g_display , ptr ) ;
67+
68+ fixed ( byte * ptr = Encoding . ASCII . GetBytes ( $ "{ _indev } \0 ") )
69+ g_indev = lv_evdev_create ( lv_indev_type_t . LV_INDEV_TYPE_POINTER , ptr ) ;
70+
71+ RootObject = lv_scr_act ( ) ;
72+
73+ _fallbackFont = lv_obj_get_style_text_font ( RootObject , LV_PART_MAIN ) ;
74+
75+ var systemFontPath = LinuxSystemFontResolver . TryResolveFontPath ( ) ;
76+ if ( ! string . IsNullOrWhiteSpace ( systemFontPath ) )
9677 {
97- MarkOpenFailed ( ) ;
98- throw ;
78+ _fontManager = new SixLaborsFontManager (
79+ systemFontPath ,
80+ 12 ,
81+ _dpi ,
82+ _fallbackFont ,
83+ LvglHostDefaults . CreateDefaultFontFallbackGlyphs ( ) ) ;
84+
85+ _defaultFontStyle = LvglHostDefaults . ApplyDefaultFontStyle ( RootObject , _fontManager . GetLvFontPtr ( ) ) ;
9986 }
10087 }
10188
102- public void RegisterTextInput ( lv_obj_t * textArea )
89+ public override void RegisterTextInput ( lv_obj_t * textArea )
10390 {
10491 if ( textArea == null )
10592 {
@@ -111,41 +98,23 @@ public void RegisterTextInput(lv_obj_t* textArea)
11198 lv_keyboard_set_textarea ( keyboard , textArea ) ;
11299 }
113100
114- public void RunLoop ( Action iteration )
101+ protected override void RunLoopCore ( Action iteration )
115102 {
116- try
103+ while ( g_running )
117104 {
118- while ( g_running )
119- {
120- HandleEvents ( ) ;
121- iteration ? . Invoke ( ) ;
122- Thread . Sleep ( 5 ) ;
123- }
124- }
125- finally
126- {
127- Close ( ) ;
105+ HandleEvents ( ) ;
106+ iteration ? . Invoke ( ) ;
107+ Thread . Sleep ( 5 ) ;
128108 }
129109 }
130110
131- public void HandleEvents ( )
111+ public override void HandleEvents ( )
132112 {
133113 lv_timer_handler ( ) ;
134114 }
135115
136- public void Close ( )
116+ protected override void OnCloseCore ( )
137117 {
138- if ( ! g_running && g_display == null && g_indev == null && RootObject == null )
139- {
140- TryBeginClose ( ) ;
141- return ;
142- }
143-
144- if ( ! TryBeginClose ( ) )
145- {
146- return ;
147- }
148-
149118 g_running = false ;
150119
151120 if ( g_indev != null )
@@ -167,9 +136,6 @@ public void Close()
167136 SendTextAreaFocusCallbackCore = null ;
168137 }
169138
170- public void Dispose ( )
171- {
172- Close ( ) ;
173- }
139+ protected override bool CanSkipClose ( ) => ! g_running && g_display == null && g_indev == null && RootObject == null ;
174140 }
175141}
0 commit comments