egui_probe/
collections.rs

1use crate::{EguiProbe, Style};
2
3/// Modifier to add a delete button to an item probe UI.
4pub struct DeleteMe<'a, T> {
5    pub value: &'a mut T,
6    pub delete: bool,
7}
8
9impl<T> EguiProbe for DeleteMe<'_, T>
10where
11    T: EguiProbe,
12{
13    fn probe(&mut self, ui: &mut egui::Ui, style: &Style) -> egui::Response {
14        let mut r = ui
15            .horizontal(|ui| {
16                self.value.probe(ui, style);
17                ui.add_space(ui.spacing().item_spacing.x);
18                if ui.small_button(style.remove_button_text()).clicked() {
19                    self.delete = true;
20                }
21            })
22            .response;
23
24        if self.delete {
25            r.mark_changed();
26        }
27
28        r
29    }
30
31    fn iterate_inner(
32        &mut self,
33        ui: &mut egui::Ui,
34        f: &mut dyn FnMut(&str, &mut egui::Ui, &mut dyn EguiProbe),
35    ) {
36        self.value.iterate_inner(ui, f);
37    }
38}
39
40/// Modifier to disable adding/removing items from collections.
41pub struct EguiProbeFrozen<'a, T> {
42    pub value: &'a mut T,
43}