Fyrox
Fyrox copied to clipboard
Type convert bug in 'UiNode::cast()'
Maybe there is a bug:
impl UiNode {
pub fn cast<T: Control>(&self) -> Option<&T> {
self.0.as_any().downcast_ref::<T>()
}
}
To consider composition style inheritance, it should be
impl UiNode {
pub fn cast<T: Control>(&self) -> Option<&T> {
self.0
.query_component(TypeId::of::<T>())
.map(|a| a.downcast_ref::<T>())
.flatten()
}
}
Hi, query_component was added after cast and I just didn't think that cast could be improved in this way. This seems to be a very good improvement 🤔
I explained the difference of the methods in the docs - https://github.com/FyroxEngine/Fyrox/blob/master/fyrox-ui/src/node.rs#L90-L111