@@ -5,10 +5,10 @@ use alloc::ffi::CString;
5
5
6
6
use core:: ffi:: { c_char, c_void, CStr } ;
7
7
use core:: marker:: PhantomData ;
8
+ use core:: mem:: MaybeUninit ;
8
9
use core:: ptr:: { self , NonNull } ;
9
-
10
10
use flipperzero_sys as sys;
11
- use sys:: { c_string , furi:: UnsafeRecord } ;
11
+ use sys:: furi:: UnsafeRecord ;
12
12
13
13
use crate :: furi:: string:: FuriString ;
14
14
use crate :: gui:: canvas:: Align ;
@@ -25,6 +25,7 @@ pub struct DialogMessage<'a> {
25
25
}
26
26
27
27
/// A dialog file browser options.
28
+ #[ repr( transparent) ]
28
29
pub struct DialogFileBrowserOptions < ' a > {
29
30
data : sys:: DialogsFileBrowserOptions ,
30
31
_phantom : PhantomData < & ' a ( ) > ,
@@ -202,19 +203,22 @@ impl DialogMessageButton {
202
203
203
204
impl < ' a > DialogFileBrowserOptions < ' a > {
204
205
/// Creates a new dialog file browser options and initializes to default values.
205
- pub fn new ( ) -> Self {
206
+ pub fn new < ' e : ' a > ( extension : & ' e CStr ) -> Self {
207
+ let mut options = MaybeUninit :: < sys:: DialogsFileBrowserOptions > :: uninit ( ) ;
208
+ let uninit_options = options. as_mut_ptr ( ) ;
209
+ let extension = extension. as_ptr ( ) ;
210
+ // TODO: as for now, we stick to default (NULL) icon,
211
+ // although we may want to make it customizable via this function's parameter
212
+ // once there are safe Icon-related APIs
213
+ let icon = ptr:: null ( ) ;
214
+ // SAFETY: all pointers are valid (`icon` is allowed to be NULL)
215
+ // and options is intentionally uninitialized
216
+ // since it is the called function's job to do it
217
+ unsafe { sys:: dialog_file_browser_set_basic_options ( uninit_options, extension, icon) } ;
206
218
Self {
207
- // default values from sys::dialog_file_browser_set_basic_options()
208
- data : sys:: DialogsFileBrowserOptions {
209
- extension : c_string ! ( "*" ) ,
210
- base_path : ptr:: null ( ) ,
211
- skip_assets : true ,
212
- hide_dot_files : false ,
213
- icon : ptr:: null ( ) ,
214
- hide_ext : true ,
215
- item_loader_callback : None ,
216
- item_loader_context : ptr:: null_mut ( ) ,
217
- } ,
219
+ // SAFETY: data has just been initialized fully
220
+ // as guaranteed by the previously called function's contract
221
+ data : unsafe { options. assume_init ( ) } ,
218
222
_phantom : PhantomData ,
219
223
}
220
224
}
0 commit comments