From 66a08a9c0501be73c8dd77064a67799f60b3d310 Mon Sep 17 00:00:00 2001 From: iorebuild Date: Wed, 6 Aug 2025 23:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=80=89=E6=8B=A9=E8=B7=AF=E5=BE=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 3 +- components/Window.slint | 69 +++++++++++++++++++++++++++++++++++++++++ src/main.rs | 36 +++++++++++++++++++-- 3 files changed, 104 insertions(+), 4 deletions(-) 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