diff --git a/Cargo.toml b/Cargo.toml index d491ae3..80c06ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" smol = "1" # or any other runtime/executor async-tftp = "0.3.6" slint = "1.12.1" +rfd = "0.15.4" [build-dependencies] -slint-build = "1.12" +slint-build = "1.12" \ No newline at end of file diff --git a/components/Window.slint b/components/Window.slint index 9e12b93..c335f8b 100644 --- a/components/Window.slint +++ b/components/Window.slint @@ -1,5 +1,74 @@ +import { Button, VerticalBox } from "std-widgets.slint"; + export component MainWindow inherits Window { height: 180px; width: 320px; title: "VoileTftpTools"; + default-font-family: "Segoe UI"; + default-font-size: 16px; + default-font-weight: 700; + //选择路径回调 + callback BrowserFolder() -> string; + property SelectFolder: ""; + //启动回调 + callback StartTftp(); + //停止回调 + callback StopTftp(); + Rectangle { + height: 35px; + width: 95px; + x: 10px; + y: 10px; + Button { + height: parent.height; + width: parent.width; + text: "选择路径"; + clicked => { + SelectFolder = BrowserFolder(); + } + } + } + + Rectangle { + height: 35px; + width: 95px; + x: 110px; + y: 10px; + Button { + height: parent.height; + width: parent.width; + text: "启动"; + clicked => { + StartTftp(); + } + } + } + + Rectangle { + height: 35px; + width: 95px; + x: 210px; + y: 10px; + Button { + height: parent.height; + width: parent.width; + text: "停止"; + clicked => { + StopTftp(); + } + } + } + + Text { + x: 13px; + y: 55px; + text: "路径:"; + } + Text { + x: 60px; + y: 55px; + width: 200px; + wrap: word-wrap; // 自动换行关键属性 + text: SelectFolder; + } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d30fafd..99c3bb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ -use async_tftp::server::TftpServerBuilder; -use async_tftp::Result; +// use async_tftp::server::TftpServerBuilder; +// use async_tftp::Result; +use rfd::FileDialog; +use slint::SharedString; slint::include_modules!(); // fn main() -> Result<()> { // smol::block_on(async { @@ -10,5 +12,33 @@ slint::include_modules!(); // } fn main() { - MainWindow::new().unwrap().run().unwrap(); + let ui = MainWindow::new().unwrap(); + //选择路径按钮的回调函数 + ui.on_BrowserFolder(move || { + let result = FileDialog::new() + .set_directory("/") + .pick_folder(); + + SharedString::from( + result.map(|p| p.to_string_lossy().into_owned()) + .unwrap_or_default() + ) + }); + //启动按钮的回调函数 + ui.on_StartTftp(move || { + println!("Start Tftp Dir:"); + }); + //停止按钮的回调函数 + ui.on_StopTftp(move || { + println!("Stop Tftp Dir:"); + }); + ui.run().unwrap(); + // // 实现 Slint 中定义的 select_path 函数 + // ui.global::().invoke_select_path(move || { + // // 使用 rfd 库打开文件选择对话框 + // if let Some(path) = FileDialog::new().pick_folder() { + // // 将选择的路径设置到 Slint 的 selected_path 属性中 + // ui.global::().set_selected_path(path.to_str().unwrap_or("")); + // } + // }); } \ No newline at end of file