1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use crate::Inspectable; use crate::{egui, Context}; impl<T> Inspectable for Vec<T> where T: Inspectable + Default, T::Attributes: Clone, { type Attributes = <T as Inspectable>::Attributes; fn ui(&mut self, ui: &mut egui::Ui, options: Self::Attributes, context: &Context) { ui.vertical(|ui| { let mut to_delete = None; for (i, val) in self.iter_mut().enumerate() { ui.horizontal(|ui| { ui.label(i.to_string()); val.ui(ui, options.clone(), context); if ui.button("-").clicked { to_delete = Some(i); } }); } ui.vertical_centered_justified(|ui| { if ui.button("+").clicked { self.push(T::default()); } }); if let Some(i) = to_delete { self.remove(i); } }); } } #[cfg(feature = "nightly")] impl<T: Inspectable, const N: usize> Inspectable for [T; N] where T::Attributes: Clone, { type Attributes = <T as Inspectable>::Attributes; fn ui(&mut self, ui: &mut egui::Ui, options: Self::Attributes, context: &Context) { ui.vertical(|ui| { for (i, val) in self.iter_mut().enumerate() { ui.horizontal(|ui| { ui.label(i.to_string()); val.ui(ui, options.clone(), context); }); } }); } }