diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 370ffde2..86c2c0ba 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -167,7 +167,7 @@ impl App { let mut ui_mod = |ctx: &mut Ctx, ui: &mut Ui, _group: Option<&str>, - index: usize, + state: egui_dnd::ItemState, mc: &mut ModConfig| { if ui .add(egui::Checkbox::without_text(&mut mc.enabled)) @@ -209,7 +209,7 @@ impl App { } if let Some(info) = &info { - egui::ComboBox::from_id_source(index) + egui::ComboBox::from_id_source(state.index) .selected_text( self.state .store @@ -245,9 +245,9 @@ impl App { ui.output_mut(|o| o.copied_text = mc.spec.url.to_owned()); } - let is_duplicate = enabled_specs - .iter() - .any(|(i, spec)| Some(index) != *i && info.spec.satisfies_dependency(spec)); + let is_duplicate = enabled_specs.iter().any(|(i, spec)| { + Some(state.index) != *i && info.spec.satisfies_dependency(spec) + }); if is_duplicate && ui .button( @@ -256,7 +256,7 @@ impl App { .on_hover_text_at_pointer("remove duplicate") .clicked() { - ctx.btn_remove = Some(index); + ctx.btn_remove = Some(state.index); } let missing_deps = info @@ -343,7 +343,7 @@ impl App { required_status, approval_status, .. // version ignored - }) = &info.modio_tags + }) = (!state.dragged).then_some(info.modio_tags.as_ref()).flatten() { let mut mk_searchable_modio_tag = |tag_str: &str, ui: &mut Ui, color: Option| { let text_color = if color.is_some() { Color32::BLACK } else { Color32::GRAY }; @@ -438,40 +438,52 @@ impl App { } }; - let mut ui_item = |ctx: &mut Ctx, ui: &mut Ui, mc: &mut ModOrGroup, index: usize| { - if ui.button(" ➖ ").clicked() { - ctx.btn_remove = Some(index); - } - - match mc { - ModOrGroup::Individual(mc) => { - ui_mod(ctx, ui, None, index, mc); + let mut ui_item = + |ctx: &mut Ctx, ui: &mut Ui, mc: &mut ModOrGroup, state: egui_dnd::ItemState| { + if ui.button(" ➖ ").clicked() { + ctx.btn_remove = Some(state.index); } - ModOrGroup::Group { - ref group_name, - enabled, - } => { - if ui - .add(egui::Checkbox::without_text(enabled)) - .on_hover_text_at_pointer("enabled?") - .changed() - { - ctx.needs_save = true; + + match mc { + ModOrGroup::Individual(mc) => { + ui_mod(ctx, ui, None, state, mc); } - ui.collapsing(group_name, |ui| { - for (i, m) in groups - .get_mut(group_name) - .unwrap() - .mods - .iter_mut() - .enumerate() + ModOrGroup::Group { + ref group_name, + enabled, + } => { + if ui + .add(egui::Checkbox::without_text(enabled)) + .on_hover_text_at_pointer("enabled?") + .changed() { - ui.horizontal(|ui| ui_mod(ctx, ui, Some(group_name), i, m)); + ctx.needs_save = true; } - }); + ui.collapsing(group_name, |ui| { + for (index, m) in groups + .get_mut(group_name) + .unwrap() + .mods + .iter_mut() + .enumerate() + { + ui.horizontal(|ui| { + ui_mod( + ctx, + ui, + Some(group_name), + egui_dnd::ItemState { + index, + dragged: false, + }, + m, + ) + }); + } + }); + } } - } - }; + }; let res = egui_dnd::dnd(ui, ui.id().with("dnd")).show_vec( &mut profile.mods, @@ -481,7 +493,7 @@ impl App { ui.label("☰"); }); - ui_item(&mut ctx, ui, item, state.index); + ui_item(&mut ctx, ui, item, state); }); }, );