Write a closure!

Not sure this is actually something useful or not...
This commit is contained in:
2023-06-03 00:34:22 +01:00
parent c744229066
commit 105c6073fb

View File

@@ -102,6 +102,7 @@ impl eframe::App for RustDoomLauncher {
}); });
ui.separator(); ui.separator();
ui.vertical(|ui| { ui.vertical(|ui| {
// TODO add default name as the path or something
ui.label("Add WADs etc"); ui.label("Add WADs etc");
ui.set_max_width(180.0); ui.set_max_width(180.0);
ui.horizontal(|ui| { ui.horizontal(|ui| {
@@ -109,10 +110,21 @@ impl eframe::App for RustDoomLauncher {
ui.text_edit_singleline(&mut self.name) ui.text_edit_singleline(&mut self.name)
.labelled_by(name_label.id); .labelled_by(name_label.id);
}); });
let get_name = |path: &PathBuf, name: &String| {
if self.name.is_empty() {
// Check this perhaps? Unsure whether the FileDialog can actually
// return something that isn't a file
path.file_name().unwrap().to_str().unwrap().to_string()
} else {
name.clone()
}
};
if ui.button("Add Launcher").clicked() { if ui.button("Add Launcher").clicked() {
if let Some(path) = rfd::FileDialog::new().pick_file() { if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_launchers.push(LauncherInfo { self.all_launchers.push(LauncherInfo {
name: self.name.clone(), name: get_name(&path, &self.name),
path: path path: path
}); });
} }
@@ -120,7 +132,7 @@ impl eframe::App for RustDoomLauncher {
if ui.button("Add IWAD").clicked() { if ui.button("Add IWAD").clicked() {
if let Some(path) = rfd::FileDialog::new().pick_file() { if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_iwads.push(WadInfo { self.all_iwads.push(WadInfo {
name: self.name.clone(), name: get_name(&path, &self.name),
path: path, path: path,
}); });
} }
@@ -128,8 +140,8 @@ impl eframe::App for RustDoomLauncher {
if ui.button("Add PWAD or Mod").clicked() { if ui.button("Add PWAD or Mod").clicked() {
if let Some(path) = rfd::FileDialog::new().pick_file() { if let Some(path) = rfd::FileDialog::new().pick_file() {
self.all_pwads.push(WadInfo { self.all_pwads.push(WadInfo {
name: get_name(&path, &self.name),
path: path.clone(), path: path.clone(),
name: self.name.clone(),
}); });
} }
} }
@@ -139,8 +151,8 @@ impl eframe::App for RustDoomLauncher {
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
// I don't actually think using SelectableLabel is correct here - // I don't actually think using SelectableLabel is correct here -
// but it'll at least do the highlighting when hovered nicely // but it'll at least do the highlighting when hovered nicely
if let Some(l) = &self.selected_launcher { if let Some(l) = self.selected_launcher {
if let Some(iwad) = &self.all_launchers.get(*l) { if let Some(iwad) = self.all_launchers.get(l) {
if ui.add(egui::SelectableLabel::new(false, &iwad.name)).clicked() { if ui.add(egui::SelectableLabel::new(false, &iwad.name)).clicked() {
self.selected_launcher = None; self.selected_launcher = None;
} }
@@ -150,8 +162,8 @@ impl eframe::App for RustDoomLauncher {
} else { } else {
ui.label("Select a launcher plz"); ui.label("Select a launcher plz");
} }
if let Some(i) = &self.selected_iwad { if let Some(i) = self.selected_iwad {
if let Some(iwad) = &self.all_iwads.get(*i) { if let Some(iwad) = self.all_iwads.get(i) {
if ui if ui
.add(egui::SelectableLabel::new(false, &iwad.name)) .add(egui::SelectableLabel::new(false, &iwad.name))
.clicked() .clicked()