if ui.button("选择单个文件").clicked(){ifletSome(path)=FileDialog::new().add_filter("文本文件",&["txt","md"]).add_filter("图像文件",&["png","jpg","jpeg"]).add_filter("所有文件",&["*"]).pick_file(){self.last_file_path =Some(path.display().to_string());}}ifletSome(path)=&self.last_file_path {// 如果路径有值ui.label(format!("已选文件: {}", path));}
五、选择多个文件框.pick_files()
if ui.button("选择多个文件").clicked(){ifletSome(paths)=FileDialog::new().pick_files(){self.last_files_path = paths.iter().map(|p| p.display().to_string()).collect();// 将路径列表转换为路径字符串列表}}if!self.last_files_path.is_empty(){// 如果列表不为空ui.label("已选文件:");for f inself.last_files_path.iter(){// 遍历显示所有路径ui.label(f);}}
六、保存文件框.save_file()
if ui.button("保存文件").clicked(){ifletSome(path)=rfd::FileDialog::new().add_filter("text",&["txt","rs"])// 文件类型过滤.save_file(){self.save_file_path =Some(path.display().to_string());}}ifletSome(path)=&self.save_file_path {ui.label(format!("保存的文件路径:{}", path));}