@@ -64,6 +64,10 @@ pub trait Component: Any + AnyComponent {
64 fn type_name(&self) -> &'static str {
64 fn type_name(&self) -> &'static str {
65 std::any::type_name::<Self>()
65 std::any::type_name::<Self>()
68+ fn id(&self) -> Option<&'static str> {
69use anyhow::Error;
73use anyhow::Error;
@@ -184,6 +188,14 @@ impl Compositor {
184 .find(|component| component.type_name() == type_name)
188 .find(|component| component.type_name() == type_name)
185 .and_then(|component| component.as_any_mut().downcast_mut())
189 .and_then(|component| component.as_any_mut().downcast_mut())
192+ pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
193+ let type_name = std::any::type_name::<T>();
196+ .find(|component| component.type_name() == type_name && component.id() == Some(id))
197+ .and_then(|component| component.as_any_mut().downcast_mut())
189// View casting, taken straight from Cursive
201// View casting, taken straight from Cursive