From 93f70ada9a31cb4d4867c64d90e46773c4156d59 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Thu, 10 Jun 2021 18:17:37 +0100 Subject: [PATCH] Moved card searching to `LoadedGame`. --- dcb-tools/dcb-card-editor/src/loaded_game.rs | 16 ++++++++++++-- dcb-tools/dcb-card-editor/src/main.rs | 22 +++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dcb-tools/dcb-card-editor/src/loaded_game.rs b/dcb-tools/dcb-card-editor/src/loaded_game.rs index 4e182b4..5959722 100644 --- a/dcb-tools/dcb-card-editor/src/loaded_game.rs +++ b/dcb-tools/dcb-card-editor/src/loaded_game.rs @@ -26,6 +26,9 @@ pub struct LoadedGame { /// Hash of `card_table` within disk file_card_table_hash: Cell, + + /// Card search + card_search: String, } impl LoadedGame { @@ -47,6 +50,7 @@ impl LoadedGame { card_table, file, file_card_table_hash: Cell::new(file_card_table_hash), + card_search: String::new(), }) } @@ -93,9 +97,17 @@ impl LoadedGame { /// Displays the card selection menu pub fn display_card_selection( - &mut self, card_search: &str, ui: &mut egui::Ui, open_edit_screens: &mut Vec, - tex_allocator: &mut dyn TextureAllocator, + &mut self, ui: &mut egui::Ui, open_edit_screens: &mut Vec, tex_allocator: &mut dyn TextureAllocator, ) { + ui.heading("Card list"); + + ui.vertical(|ui| { + ui.label("Search"); + ui.text_edit_singleline(&mut self.card_search); + }); + ui.separator(); + + let card_search = &self.card_search; let names = self .card_table .cards diff --git a/dcb-tools/dcb-card-editor/src/main.rs b/dcb-tools/dcb-card-editor/src/main.rs index f9c81fb..3b354cd 100644 --- a/dcb-tools/dcb-card-editor/src/main.rs +++ b/dcb-tools/dcb-card-editor/src/main.rs @@ -62,9 +62,6 @@ pub struct CardEditor { /// Loaded game loaded_game: Option, - /// Card search - card_search: String, - /// All selected edit screens open_edit_screens: Vec, @@ -79,7 +76,6 @@ impl Default for CardEditor { fn default() -> Self { Self { loaded_game: None, - card_search: String::new(), open_edit_screens: vec![], swap_screen: None, overview_screen: None, @@ -91,7 +87,6 @@ impl epi::App for CardEditor { fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) { let Self { loaded_game, - card_search, open_edit_screens, swap_screen, overview_screen, @@ -173,19 +168,12 @@ impl epi::App for CardEditor { } } - egui::SidePanel::left("side_panel").show(ctx, |ui| { - ui.heading("Card list"); - - ui.vertical(|ui| { - ui.label("Search"); - ui.text_edit_singleline(card_search); + // If we have a loaded game, display all cards + if let Some(loaded_game) = loaded_game { + egui::SidePanel::left("card-selection").show(ctx, |ui| { + loaded_game.display_card_selection(ui, open_edit_screens, frame.tex_allocator()); }); - - // If we have a loaded game, display all cards - if let Some(loaded_game) = loaded_game { - loaded_game.display_card_selection(card_search, ui, open_edit_screens, frame.tex_allocator()); - } - }); + } // Display all screens if let Some(loaded_game) = loaded_game {