egui_probe/
vec.rs

1use crate::{
2    EguiProbe,
3    collections::{DeleteMe, EguiProbeFrozen},
4    option::option_probe_with,
5};
6
7impl<T> EguiProbe for Vec<T>
8where
9    T: EguiProbe + Default,
10{
11    fn probe(&mut self, ui: &mut egui::Ui, style: &crate::Style) -> egui::Response {
12        ui.horizontal(|ui| {
13            ui.weak(format!("[{}]", self.len()));
14            let r = ui.small_button(style.add_button_text());
15            if r.clicked() {
16                self.push(T::default());
17            }
18        })
19        .response
20    }
21
22    fn iterate_inner(
23        &mut self,
24        ui: &mut egui::Ui,
25        f: &mut dyn FnMut(&str, &mut egui::Ui, &mut dyn EguiProbe),
26    ) {
27        let mut idx = 0;
28        self.retain_mut(|value| {
29            let mut item = DeleteMe {
30                value,
31                delete: false,
32            };
33            f(&format!("[{idx}]"), ui, &mut item);
34            idx += 1;
35            !item.delete
36        });
37    }
38}
39
40impl<T> EguiProbe for EguiProbeFrozen<'_, Vec<T>>
41where
42    T: EguiProbe,
43{
44    fn probe(&mut self, ui: &mut egui::Ui, _style: &crate::Style) -> egui::Response {
45        ui.weak(format!("[{}]", self.value.len()))
46    }
47
48    fn iterate_inner(
49        &mut self,
50        ui: &mut egui::Ui,
51        f: &mut dyn FnMut(&str, &mut egui::Ui, &mut dyn EguiProbe),
52    ) {
53        for (i, value) in self.value.iter_mut().enumerate() {
54            f(&format!("[{i}]"), ui, value);
55        }
56    }
57}
58
59impl<T> EguiProbe for EguiProbeFrozen<'_, Option<Vec<T>>>
60where
61    T: EguiProbe,
62{
63    fn probe(&mut self, ui: &mut egui::Ui, style: &crate::Style) -> egui::Response {
64        option_probe_with(self.value, ui, style, Vec::new, |value, ui, _style| {
65            ui.weak(format!("[{}]", value.len()))
66        })
67    }
68
69    fn iterate_inner(
70        &mut self,
71        ui: &mut egui::Ui,
72        f: &mut dyn FnMut(&str, &mut egui::Ui, &mut dyn EguiProbe),
73    ) {
74        if let Some(vec) = self.value {
75            for (i, value) in vec.iter_mut().enumerate() {
76                f(&format!("[{i}]"), ui, value);
77            }
78        }
79    }
80}