make property definition container use interrior mutability
@@ -20,7 +20,12 @@ use crate::{
BuildContext, UiNode, UserInterface,
};
use fxhash::FxHashMap;
-use std::{any::TypeId, fmt::Debug, rc::Rc};
+use std::{
+ any::TypeId,
+ cell::{Ref, RefCell},
+ fmt::Debug,
+ rc::Rc,
+};
pub mod array;
pub mod bool;
@@ -93,12 +98,12 @@ pub trait PropertyEditorDefinition: Debug {
#[derive(Clone, Default)]
pub struct PropertyEditorDefinitionContainer {
- definitions: FxHashMap<TypeId, Rc<dyn PropertyEditorDefinition>>,
+ definitions: RefCell<FxHashMap<TypeId, Rc<dyn PropertyEditorDefinition>>>,
}
impl PropertyEditorDefinitionContainer {
pub fn new() -> Self {
- let mut container = Self::default();
+ let container = Self::default();
container.insert(BoolPropertyEditorDefinition);
@@ -189,14 +194,15 @@ impl PropertyEditorDefinitionContainer {
}
pub fn insert<T: PropertyEditorDefinition + 'static>(
- &mut self,
+ &self,
definition: T,
) -> Option<Rc<dyn PropertyEditorDefinition>> {
self.definitions
+ .borrow_mut()
.insert(definition.value_type_id(), Rc::new(definition))
}
- pub fn definitions(&self) -> &FxHashMap<TypeId, Rc<dyn PropertyEditorDefinition>> {
- &self.definitions
+ pub fn definitions(&self) -> Ref<FxHashMap<TypeId, Rc<dyn PropertyEditorDefinition>>> {
+ self.definitions.borrow()
}
}
