pub struct FileBrowser {
pub picker_mode: PickerMode,
pub dir: PathBuf,
pub exts: Vec<String>,
pub window_pose: Pose,
pub window_size: Vec2,
pub close_on_select: bool,
pub caller: StepperId,
pub dir_buttons_tint: Color128,
pub input_tint: Color128,
pub file_name_to_save: String,
/* private fields */
}
Expand description
A basic file browser to open existing file on PC and Android. Must be launched by an other stepper which has to be set in caller.
§Fields that can be changed before initialization:
picker_mode
- What the file browser is for. Default is PickerMode::Open.caller
- The id of the stepper that launched the file browser and is waiting for a FILE_BROWSER_OPEN message.dir
- The directory to show. You can’t browse outside of this directory.exts
- The file extensions to filter.window_pose
- The pose where to show the file browser window.window_size
- The size of the file browser window. Default is Vec2{x: 0.5, y: 0.0}.close_on_select
- If true, the file browser will close when a file is selected. Default is true.file_name_to_save
- The name of the file to save. Default is an empty string.dir_tint
- The tint to differenciate directories from files. Default is same as UiVisual::Separator.input_tint
- The tint of the input fields. Default is RED.to_gamma().
§Examples
use stereokit_rust::{maths::{Vec2, Vec3}, sk::SkInfo, ui::Ui, tools::os_api::get_external_path,
tools::file_browser::{FileBrowser, FILE_BROWSER_OPEN}, };
let id = "main".to_string();
const BROWSER_SUFFIX: &str = "_file_browser";
let mut file_browser = FileBrowser::default();
let sk_info = Some(sk.get_sk_info_clone());
if cfg!(target_os = "android") {
if let Some(img_dir) = get_external_path(&sk_info) {
file_browser.dir = img_dir;
}
}
if !file_browser.dir.exists() {
file_browser.dir = std::env::current_dir().unwrap_or_default().join("tests");
}
file_browser.caller = id.clone();
file_browser.window_pose = Ui::popup_pose([-0.02, 0.04, 1.40]);
file_browser.window_size = Vec2{x: 0.16, y: 0.0};
SkInfo::send_event(&sk_info, StepperAction::add(id.clone() + BROWSER_SUFFIX, file_browser));
filename_scr = "screenshots/file_browser.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
for event in token.get_event_report() {
if let StepperAction::Event(stepper_id, key, value) = event{
if stepper_id == &id && key.eq(FILE_BROWSER_OPEN) {
println!("Selected file: {}", value);
}
}
}
);

use stereokit_rust::{maths::{Vec2, Vec3}, sk::SkInfo, ui::Ui, tools::os_api::get_external_path,
tools::file_browser::{FileBrowser, FILE_BROWSER_SAVE}, util::PickerMode, };
let id = "main".to_string();
const BROWSER_SUFFIX: &str = "_file_to_save";
let mut file_browser = FileBrowser::default();
let sk_info = Some(sk.get_sk_info_clone());
if cfg!(target_os = "android") {
if let Some(img_dir) = get_external_path(&sk_info) {
file_browser.dir = img_dir;
}
}
if !file_browser.dir.exists() {
file_browser.dir = std::env::current_dir().unwrap_or_default().join("tests");
}
file_browser.picker_mode = PickerMode::Save;
file_browser.caller = id.clone();
file_browser.window_pose = Ui::popup_pose([-0.02, 0.09, 1.37]);
file_browser.window_size = Vec2{x: 0.25, y: 0.0};
file_browser.file_name_to_save = "main.rs".into();
SkInfo::send_event(&sk_info, StepperAction::add(id.clone() + BROWSER_SUFFIX, file_browser));
filename_scr = "screenshots/file_save.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
for event in token.get_event_report() {
if let StepperAction::Event(stepper_id, key, value) = event{
if stepper_id == &id && key.eq(FILE_BROWSER_SAVE) {
println!("Save file: {}", value);
}
}
}
);

Fields§
§picker_mode: PickerMode
§dir: PathBuf
§exts: Vec<String>
§window_pose: Pose
§window_size: Vec2
§close_on_select: bool
§caller: StepperId
§input_tint: Color128
§file_name_to_save: String
Trait Implementations§
Source§impl Default for FileBrowser
impl Default for FileBrowser
Source§impl IStepper for FileBrowser
impl IStepper for FileBrowser
Source§fn initialize(&mut self, id: StepperId, sk_info: Rc<RefCell<SkInfo>>) -> bool
fn initialize(&mut self, id: StepperId, sk_info: Rc<RefCell<SkInfo>>) -> bool
This is called by StereoKit at the start of the next frame, and on the main thread. This happens before
StereoKit’s main Step callback, and always after Sk.initialize.
https://stereokit.net/Pages/StereoKit.Framework/IStepper/Initialize.html
id : The id of the stepper
sk : The SkInfo of the runnin Sk instance. Read more
Source§fn step(&mut self, token: &MainThreadToken)
fn step(&mut self, token: &MainThreadToken)
This Step method will be called every frame of the application, as long as Enabled is true. This happens
immediately before the main application’s Step callback.
https://stereokit.net/Pages/StereoKit.Framework/IStepper/Step.html
Source§fn initialize_done(&mut self) -> bool
fn initialize_done(&mut self) -> bool
If initialization is to be performed in multiple steps, with or without threads and in order to avoid black or
frozen screens, write the on going initialization here Read more
Source§fn enabled(&self) -> bool
fn enabled(&self) -> bool
Is this IStepper enabled? When false, StereoKit will not call Step. This can be a good way to temporarily
disable the IStepper without removing or shutting it down.
https://stereokit.net/Pages/StereoKit.Framework/IStepper/Enabled.html
Source§fn shutdown(&mut self)
fn shutdown(&mut self)
This is called when the IStepper is removed, or the application shuts down. This is always called on the main
thread, and happens at the start of the next frame, before the main application’s Step callback.
https://stereokit.net/Pages/StereoKit.Framework/IStepper/Shutdown.html
Source§fn shutdown_done(&mut self) -> bool
fn shutdown_done(&mut self) -> bool
If shutdown is to be performed in multiple steps, with or without threads and in order to avoid black or
frozen screens, write the on going shutdown here Read more
impl Send for FileBrowser
Auto Trait Implementations§
impl Freeze for FileBrowser
impl !RefUnwindSafe for FileBrowser
impl !Sync for FileBrowser
impl Unpin for FileBrowser
impl !UnwindSafe for FileBrowser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.