diff --git a/game_data/src/lib.rs b/game_data/src/lib.rs index 7ff544a..54d9f02 100644 --- a/game_data/src/lib.rs +++ b/game_data/src/lib.rs @@ -22,7 +22,7 @@ pub struct Item { pub always_collectable: bool, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ingredient { pub item_id: u32, diff --git a/src/app.rs b/src/app.rs index 604aa0d..7ae8cab 100644 --- a/src/app.rs +++ b/src/app.rs @@ -288,12 +288,22 @@ impl eframe::App for MacroSolverApp { self.draw_list_select_widgets(ui); }) .response; + + let config_min_height = match ui.available_size_before_wrap().x { + x if x < config_width => 0.0, + _ => response.rect.height(), + }; let response = ui - .allocate_ui(egui::vec2(config_width, response.rect.height()), |ui| { + .allocate_ui(egui::vec2(config_width, config_min_height), |ui| { self.draw_config_and_results_widget(ui); }) .response; - ui.allocate_ui(egui::vec2(macro_width, response.rect.height()), |ui| { + + let macro_min_height = match ui.available_size_before_wrap().x { + x if x < macro_width => 0.0, + _ => response.rect.height(), + }; + ui.allocate_ui(egui::vec2(macro_width, macro_min_height), |ui| { self.draw_macro_output_widget(ui); }); }, diff --git a/src/widgets/food_select.rs b/src/widgets/food_select.rs index 64c284c..1c8e06d 100644 --- a/src/widgets/food_select.rs +++ b/src/widgets/food_select.rs @@ -43,7 +43,24 @@ impl<'a> Widget for FoodSelect<'a> { ui.group(|ui| { ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0); ui.vertical(|ui| { + let mut collapsed = false; + ui.horizontal(|ui| { + let mut collapse_button_text = "⏷"; + let collapsed_id = Id::new("FOOD_SEARCH_COLLAPSED"); + ui.data_mut(|data| { + collapsed = *data.get_persisted_mut_or_default(collapsed_id); + collapse_button_text = match collapsed { + false => "⏷", + true => "⏵", + } + }); + if ui.button(collapse_button_text).clicked() { + ui.data_mut(|data| { + *data.get_persisted_mut_or_default(collapsed_id) = !collapsed; + }) + } + ui.label(egui::RichText::new(t!("label.food")).strong()); match self.selected_consumable { None => { @@ -65,6 +82,11 @@ impl<'a> Widget for FoodSelect<'a> { } }); }); + + if collapsed { + return; + } + ui.separator(); let id = Id::new("FOOD_SEARCH_TEXT"); diff --git a/src/widgets/potion_select.rs b/src/widgets/potion_select.rs index f911c14..ae13949 100644 --- a/src/widgets/potion_select.rs +++ b/src/widgets/potion_select.rs @@ -43,7 +43,24 @@ impl<'a> Widget for PotionSelect<'a> { ui.group(|ui| { ui.style_mut().spacing.item_spacing = egui::vec2(8.0, 3.0); ui.vertical(|ui| { + let mut collapsed = false; + ui.horizontal(|ui| { + let mut collapse_button_text = "⏷"; + let collapsed_id = Id::new("POTION_SEARCH_COLLAPSED"); + ui.data_mut(|data| { + collapsed = *data.get_persisted_mut_or_default(collapsed_id); + collapse_button_text = match collapsed { + false => "⏷", + true => "⏵", + } + }); + if ui.button(collapse_button_text).clicked() { + ui.data_mut(|data| { + *data.get_persisted_mut_or_default(collapsed_id) = !collapsed; + }) + } + ui.label(egui::RichText::new(t!("label.potion")).strong()); match self.selected_consumable { None => { @@ -65,6 +82,11 @@ impl<'a> Widget for PotionSelect<'a> { } }); }); + + if collapsed { + return; + } + ui.separator(); let id = Id::new("POTION_SEARCH_TEXT"); diff --git a/src/widgets/recipe_select.rs b/src/widgets/recipe_select.rs index 8a67179..d112d49 100644 --- a/src/widgets/recipe_select.rs +++ b/src/widgets/recipe_select.rs @@ -110,13 +110,6 @@ impl<'a> RecipeSelect<'a> { } fn draw_custom_recipe_select(self, ui: &mut egui::Ui) { - self.recipe_config.recipe.item_id = 0; - self.recipe_config.recipe.material_quality_factor = 0; - self.recipe_config.recipe.ingredients = [Ingredient { - item_id: 0, - amount: 0, - }; 6]; - let game_settings = get_game_settings( self.recipe_config.recipe, *self.crafter_config.active_stats(), @@ -214,7 +207,24 @@ impl<'a> Widget for RecipeSelect<'a> { } }); + let mut collapsed = false; + ui.horizontal(|ui| { + let mut collapse_button_text = "⏷"; + let collapsed_id = Id::new("RECIPE_SEARCH_COLLAPSED"); + ui.data_mut(|data| { + collapsed = *data.get_persisted_mut_or_default(collapsed_id); + collapse_button_text = match collapsed { + false => "⏷", + true => "⏵", + } + }); + if ui.button(collapse_button_text).clicked() { + ui.data_mut(|data| { + *data.get_persisted_mut_or_default(collapsed_id) = !collapsed; + }) + } + ui.label(egui::RichText::new(t!("label.recipe")).strong()); ui.add(ItemNameLabel::new( self.recipe_config.recipe.item_id, @@ -226,23 +236,33 @@ impl<'a> Widget for RecipeSelect<'a> { .checkbox(&mut custom_recipe, t!("label.custom_recipe")) .changed() { - self.recipe_config.quality_source = match custom_recipe { - true => QualitySource::Value(0), - false => QualitySource::HqMaterialList([0; 6]), + if custom_recipe { + self.recipe_config.recipe.item_id = 0; + self.recipe_config.recipe.material_quality_factor = 0; + self.recipe_config.recipe.ingredients = [Ingredient::default(); 6]; + self.recipe_config.quality_source = QualitySource::Value(0); + } else { + self.recipe_config.quality_source = + QualitySource::HqMaterialList([0; 6]); } + ui.ctx().data_mut(|data| { + data.insert_persisted(Id::new("CUSTOM_RECIPE"), custom_recipe); + }); }; }); }); + + if collapsed { + return; + } + ui.separator(); + if custom_recipe { self.draw_custom_recipe_select(ui); } else { self.draw_normal_recipe_select(ui); } - - ui.ctx().data_mut(|data| { - data.insert_persisted(Id::new("CUSTOM_RECIPE"), custom_recipe); - }); }); }) .response