Skip to content

Commit

Permalink
keep the "files" example, and use it as a crate
Browse files Browse the repository at this point in the history
  • Loading branch information
tk103331 committed Nov 8, 2024
1 parent 5f955bc commit 5cc7199
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 108 deletions.
2 changes: 1 addition & 1 deletion examples/files/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ edition = "2021"

[dependencies]
im.workspace = true
floem = { path = "../..", features = ["rfd-async-std"] }
floem = { path = "../.." , features = ["rfd-async-std"] }
Original file line number Diff line number Diff line change
Expand Up @@ -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((
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/files/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod files;
pub use files::*;
98 changes: 2 additions & 96 deletions examples/files/src/main.rs
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);
}
1 change: 1 addition & 0 deletions examples/widget-gallery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/" }
2 changes: 1 addition & 1 deletion examples/widget-gallery/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand Down

0 comments on commit 5cc7199

Please sign in to comment.