Skip to content

Commit

Permalink
Don't show mod tags while dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
trumank committed Aug 11, 2023
1 parent e517647 commit cc2d5f4
Showing 1 changed file with 49 additions and 37 deletions.
86 changes: 49 additions & 37 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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<egui::Color32>| {
let text_color = if color.is_some() { Color32::BLACK } else { Color32::GRAY };
Expand Down Expand Up @@ -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,
Expand All @@ -481,7 +493,7 @@ impl App {
ui.label("☰");
});

ui_item(&mut ctx, ui, item, state.index);
ui_item(&mut ctx, ui, item, state);
});
},
);
Expand Down

0 comments on commit cc2d5f4

Please sign in to comment.