@@ -64,6 +64,10 @@ pub trait Component: Any + AnyComponent {
6464 fn type_name(&self) -> &'static str {
6565 std::any::type_name::<Self>()
6666 }
67+
68+ fn id(&self) -> Option<&'static str> {
69+ None
70+ }
6771}
6872
6973use anyhow::Error;
@@ -184,6 +188,14 @@ impl Compositor {
184188 .find(|component| component.type_name() == type_name)
185189 .and_then(|component| component.as_any_mut().downcast_mut())
186190 }
191+
192+ pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
193+ let type_name = std::any::type_name::<T>();
194+ self.layers
195+ .iter_mut()
196+ .find(|component| component.type_name() == type_name && component.id() == Some(id))
197+ .and_then(|component| component.as_any_mut().downcast_mut())
198+ }
187199}
188200
189201// View casting, taken straight from Cursive