Add option to reset all images (#220)

This commit is contained in:
Philip Kristoffersen
2022-09-01 21:17:33 +02:00
committed by GitHub
parent 57a687c3a8
commit b38281719f
+24 -7
View File
@@ -128,6 +128,7 @@ enum UserAction {
SetGamesMode(GameMode), SetGamesMode(GameMode),
BackButton, BackButton,
NoAction, NoAction,
ClearImages,
} }
impl MyEguiApp { impl MyEguiApp {
@@ -147,7 +148,7 @@ impl MyEguiApp {
ui.heading(shortcut.name()); ui.heading(shortcut.name());
if let Some(possible_names) = state.possible_names.as_ref() { if let Some(possible_names) = state.possible_names.as_ref() {
if let Some(value) = render_possible_names(possible_names, ui) { if let Some(value) = render_possible_names(possible_names, ui,state) {
return value; return value;
} }
} else if let Some(image_type) = state.image_type_selected.as_ref() { } else if let Some(image_type) = state.image_type_selected.as_ref() {
@@ -399,6 +400,12 @@ impl MyEguiApp {
.set_image_banned(&image_type, app_id, should_ban); .set_image_banned(&image_type, app_id, should_ban);
self.handle_image_type_clear(image_type); self.handle_image_type_clear(image_type);
} }
UserAction::ClearImages =>{
for image_type in ImageType::all(){
self.handle_image_type_clear(*image_type);
}
self.handle_back_button_action();
},
}; };
} }
@@ -638,12 +645,27 @@ impl MyEguiApp {
fn render_possible_names( fn render_possible_names(
possible_names: &Vec<steamgriddb_api::search::SearchResult>, possible_names: &Vec<steamgriddb_api::search::SearchResult>,
ui: &mut egui::Ui, ui: &mut egui::Ui,
state: &ImageSelectState
) -> Option<UserAction> { ) -> Option<UserAction> {
let mut grid_id_text = state.grid_id.map(|id| id.to_string()).unwrap_or_default();
ui.label("SteamGridDB ID").on_hover_text("You can change this id to one you have found at the steamgriddb webpage");
if ui.text_edit_singleline(&mut grid_id_text)
.changed() {
if let Ok(grid_id) = grid_id_text.parse::<usize>() {
return Some(UserAction::GridIdChanged(grid_id));
}
};
for possible in possible_names { for possible in possible_names {
if ui.button(&possible.name).clicked() { if ui.button(&possible.name).clicked() {
return Some(UserAction::GridIdChanged(possible.id)); return Some(UserAction::GridIdChanged(possible.id));
} }
} }
ui.separator();
if ui.button("Clear all images").on_hover_text("Clicking this deletes all images for this shortcut").clicked(){
return Some(UserAction::ClearImages);
}
None None
} }
@@ -661,12 +683,7 @@ fn render_steam_game_select(ui: &mut egui::Ui, state: &ImageSelectState) -> Opti
} }
fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option<UserAction> { fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option<UserAction> {
let mut grid_id_text = state.grid_id.map(|id| id.to_string()).unwrap_or_default();
if ui.text_edit_singleline(&mut grid_id_text).changed() {
if let Ok(grid_id) = grid_id_text.parse::<usize>() {
return Some(UserAction::GridIdChanged(grid_id));
}
};
if ui if ui
.button("Click here if the images are for a wrong game") .button("Click here if the images are for a wrong game")
.clicked() .clicked()