pub trait CustomElement:
Debug
+ Send
+ Sync {
// Required methods
fn element_type(&self) -> &'static str;
fn render(
&self,
element: &LayoutElement,
ctx: &DataContext,
render_ctx: &RenderContext<'_>,
painter: &mut dyn Painter,
) -> Result<(), RenderError>;
// Provided method
fn schema(&self) -> ComponentSchema { ... }
}Expand description
A custom layout element that can be registered from any game or plugin.
Implement this trait to provide rendering logic for a new element type
(e.g. custom:monster_sprite, custom:hp_bar). Once registered via
ElementRegistry::register, the layout engine will dispatch elements
of that type to the implementation’s render
method.
Required Methods§
Sourcefn element_type(&self) -> &'static str
fn element_type(&self) -> &'static str
Returns the unique element type identifier.
This string is matched against the type field in a
LayoutElement at dispatch time. Convention: use a colon-prefixed
namespace, e.g. "custom:monster_sprite" or "custom:hp_bar".
Sourcefn render(
&self,
element: &LayoutElement,
ctx: &DataContext,
render_ctx: &RenderContext<'_>,
painter: &mut dyn Painter,
) -> Result<(), RenderError>
fn render( &self, element: &LayoutElement, ctx: &DataContext, render_ctx: &RenderContext<'_>, painter: &mut dyn Painter, ) -> Result<(), RenderError>
Render this custom element into the framebuffer.
§Arguments
element— The layout element definition (contains id, rect, element-specific params, etc.).ctx— Per-frame mutable data context for template variables.render_ctx— Shared immutable rendering state (screen, theme, fonts, tilesets).painter— The painter used to draw into the framebuffer.
Provided Methods§
Sourcefn schema(&self) -> ComponentSchema
fn schema(&self) -> ComponentSchema
The prop schema this element expects.
Used by ElementRegistry::validate_layout to check layouts at load
time. The default (empty) schema accepts any props — override it to
get required-prop and type checking. Keep it in sync with the
component declaration in the game’s .gui prelude; a unit test
deserialising a schema-shaped params object through the element’s own
param struct is the cheapest drift guard.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".