diff --git a/examples/files/Cargo.toml b/examples/files/Cargo.toml index 9e1bb7a2..970ea3d1 100644 --- a/examples/files/Cargo.toml +++ b/examples/files/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" [dependencies] im.workspace = true -floem = { path = "../..", features = ["rfd-async-std"] } +floem = { path = "../.." , features = ["rfd-async-std"] } diff --git a/examples/widget-gallery/src/files.rs b/examples/files/src/files.rs similarity index 94% rename from examples/widget-gallery/src/files.rs rename to examples/files/src/files.rs index e2e80b2f..e10d2e32 100644 --- a/examples/widget-gallery/src/files.rs +++ b/examples/files/src/files.rs @@ -2,12 +2,11 @@ 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, }; -use crate::form::form_item; - pub fn files_view() -> impl IntoView { let files = create_rw_signal("".to_string()); let view = h_stack(( @@ -86,20 +85,22 @@ pub fn files_view() -> impl IntoView { ); }), )) + .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() - }); - - v_stack(( - view, - form_item("Files:".to_string(), 40.0, move || { - label(move || files.get()) - }), - )) + }) } fn display_files(file: FileInfo) -> String { diff --git a/examples/files/src/lib.rs b/examples/files/src/lib.rs new file mode 100644 index 00000000..dfe01acc --- /dev/null +++ b/examples/files/src/lib.rs @@ -0,0 +1,2 @@ +pub mod files; +pub use files::*; diff --git a/examples/files/src/main.rs b/examples/files/src/main.rs index 929d3287..5dc078a3 100644 --- a/examples/files/src/main.rs +++ b/examples/files/src/main.rs @@ -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); } diff --git a/examples/widget-gallery/Cargo.toml b/examples/widget-gallery/Cargo.toml index 4637109b..57435081 100644 --- a/examples/widget-gallery/Cargo.toml +++ b/examples/widget-gallery/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" im.workspace = true floem = { path = "../.." , features = ["rfd-async-std"] } strum = { version = "0.25.0", features = ["derive"] } +files = { path = "../files/" } diff --git a/examples/widget-gallery/src/main.rs b/examples/widget-gallery/src/main.rs index 5b46718c..cb497cd8 100644 --- a/examples/widget-gallery/src/main.rs +++ b/examples/widget-gallery/src/main.rs @@ -6,7 +6,6 @@ pub mod context_menu; pub mod draggable; pub mod dropdown; pub mod dropped_file; -pub mod files; pub mod form; pub mod images; pub mod inputs; @@ -16,6 +15,7 @@ pub mod radio_buttons; pub mod rich_text; pub mod slider; +use files; use floem::{ event::{Event, EventListener, EventPropagation}, keyboard::{Key, NamedKey},