pub struct ElementRegistry { /* private fields */ }Expand description
A global registry of custom element types.
Games or plugins register their custom element implementations here
before layout rendering begins. The layout engine looks up elements
by their type string at render time and dispatches to the
corresponding CustomElement if found.
§Example
let mut registry = ElementRegistry::new();
registry.register(Box::new(MyMonsterSpriteElement));
if let Some(element) = registry.get("custom:monster_sprite") {
element.render(&layout_elem, &ctx, &render_ctx, &mut painter)?;
}Implementations§
Source§impl ElementRegistry
impl ElementRegistry
Sourcepub fn register(&mut self, element: Box<dyn CustomElement>)
pub fn register(&mut self, element: Box<dyn CustomElement>)
Register a custom element implementation.
The element’s element_type is used
as the lookup key. If an element with the same type is already
registered, it is replaced.
Sourcepub fn get(&self, type_name: &str) -> Option<&dyn CustomElement>
pub fn get(&self, type_name: &str) -> Option<&dyn CustomElement>
Look up a custom element by its type name.
Returns None if no element with the given type has been registered.
Sourcepub fn contains(&self, type_name: &str) -> bool
pub fn contains(&self, type_name: &str) -> bool
Check whether a custom element type has been registered.
Sourcepub fn validate_layout(
&self,
layout: &ScreenLayout,
) -> Result<(), Vec<SchemaViolation>>
pub fn validate_layout( &self, layout: &ScreenLayout, ) -> Result<(), Vec<SchemaViolation>>
Validate every custom:* element of layout against the registered
schemas. Call once when a layout is loaded — render-time dispatch does
no checking.
Checks per element (recursing into border/group children):
- the element type is registered;
- every
requiredschema prop is present; - present schema props match their declared
PropType.
Props outside the schema are NOT flagged: the DSL compiler already
rejects undeclared props at build time, and standard layout props
(align, padding, …) may legitimately accompany any element.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ElementRegistry
impl !UnwindSafe for ElementRegistry
impl Freeze for ElementRegistry
impl Send for ElementRegistry
impl Sync for ElementRegistry
impl Unpin for ElementRegistry
impl UnsafeUnpin for ElementRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.