-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use the "files" example as a crate, and add the "files" example to wi…
…dget-gallery (#677) * add animation example to widget-gallery * add draggable example to widget-gallery * add dropped file example to widget-gallery * format * add files example to widget-gallery * keep the "files" example, and use it as a crate
- Loading branch information
Showing
7 changed files
with
180 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use floem::{ | ||
action::{open_file, save_as}, | ||
file::{FileDialogOptions, FileInfo, FileSpec}, | ||
reactive::{create_rw_signal, SignalGet, SignalUpdate}, | ||
text::Weight, | ||
views::{button, h_stack, label, v_stack, Decorators}, | ||
IntoView, | ||
}; | ||
|
||
pub fn files_view() -> impl IntoView { | ||
let files = create_rw_signal("".to_string()); | ||
let view = h_stack(( | ||
button("Select file").on_click_cont(move |_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.force_starting_directory("/") | ||
.title("Select file") | ||
.allowed_types(vec![FileSpec { | ||
name: "text", | ||
extensions: &["txt", "rs", "md"], | ||
}]), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected file: {:?}", file.path); | ||
files.set(display_files(file)); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select multiple files").on_click_cont(move |_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.multi_selection() | ||
.title("Select file") | ||
.allowed_types(vec![FileSpec { | ||
name: "text", | ||
extensions: &["txt", "rs", "md"], | ||
}]), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected file: {:?}", file.path); | ||
files.set(display_files(file)); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select folder").on_click_cont(move |_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.select_directories() | ||
.title("Select Folder"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected folder: {:?}", file.path); | ||
files.set(display_files(file)); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select multiple folder").on_click_cont(move |_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.select_directories() | ||
.multi_selection() | ||
.title("Select multiple Folder"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected folder: {:?}", file.path); | ||
files.set(display_files(file)); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Save file").on_click_cont(move |_| { | ||
save_as( | ||
FileDialogOptions::new() | ||
.default_name("floem.file") | ||
.title("Save file"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Save file to: {:?}", file.path); | ||
files.set(display_files(file)); | ||
} | ||
}, | ||
); | ||
}), | ||
)) | ||
.style(|s| s.justify_center()); | ||
|
||
v_stack(( | ||
view, | ||
h_stack(( | ||
"Path(s): ".style(|s| s.font_weight(Weight::BOLD)), | ||
label(move || files.get()), | ||
)), | ||
)) | ||
.style(|s| { | ||
s.row_gap(5) | ||
.width_full() | ||
.height_full() | ||
.items_center() | ||
.justify_center() | ||
}) | ||
} | ||
|
||
fn display_files(file: FileInfo) -> String { | ||
let paths: Vec<&str> = file | ||
.path | ||
.iter() | ||
.map(|p| p.to_str()) | ||
.filter(|p| p.is_some()) | ||
.map(|p| p.unwrap()) | ||
.collect(); | ||
paths.join("\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod files; | ||
pub use files::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,5 @@ | ||
use floem::{ | ||
action::{open_file, save_as}, | ||
file::{FileDialogOptions, FileSpec}, | ||
keyboard::{Key, NamedKey}, | ||
views::{button, h_stack, Decorators}, | ||
IntoView, View, | ||
}; | ||
|
||
fn app_view() -> impl IntoView { | ||
let view = h_stack(( | ||
button("Select file").on_click_cont(|_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.force_starting_directory("/") | ||
.title("Select file") | ||
.allowed_types(vec![FileSpec { | ||
name: "text", | ||
extensions: &["txt", "rs", "md"], | ||
}]), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected file: {:?}", file.path); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select multiple files").on_click_cont(|_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.multi_selection() | ||
.title("Select file") | ||
.allowed_types(vec![FileSpec { | ||
name: "text", | ||
extensions: &["txt", "rs", "md"], | ||
}]), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected file: {:?}", file.path); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select folder").on_click_cont(|_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.select_directories() | ||
.title("Select Folder"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected folder: {:?}", file.path); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Select multiple folder").on_click_cont(|_| { | ||
open_file( | ||
FileDialogOptions::new() | ||
.select_directories() | ||
.multi_selection() | ||
.title("Select multiple Folder"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Selected folder: {:?}", file.path); | ||
} | ||
}, | ||
); | ||
}), | ||
button("Save file").on_click_cont(|_| { | ||
save_as( | ||
FileDialogOptions::new() | ||
.default_name("floem.file") | ||
.title("Save file"), | ||
move |file_info| { | ||
if let Some(file) = file_info { | ||
println!("Save file to: {:?}", file.path); | ||
} | ||
}, | ||
); | ||
}), | ||
)) | ||
.style(|s| { | ||
s.row_gap(5) | ||
.width_full() | ||
.height_full() | ||
.items_center() | ||
.justify_center() | ||
}); | ||
|
||
let id = view.id(); | ||
view.on_key_up( | ||
Key::Named(NamedKey::F11), | ||
|m| m.is_empty(), | ||
move |_| id.inspect(), | ||
) | ||
} | ||
pub mod files; | ||
|
||
fn main() { | ||
floem::launch(app_view); | ||
floem::launch(files::files_view); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters