incular_core/widget.rs
1//! Renderer-neutral widget contracts.
2
3use crate::{BuildContext, Key};
4use std::rc::Rc;
5
6/// Base contract shared by stateless and stateful widget descriptions.
7///
8/// Core deliberately does not prescribe how a widget is mounted, laid out, or
9/// painted. Higher-level crates can add those concerns while still accepting
10/// any type implementing this identity contract. The default key is absent,
11/// which gives a widget positional identity in a local reconciliation pass.
12pub trait Widget: 'static {
13 /// Returns the optional local identity used by reconciliation.
14 fn key(&self) -> Option<&dyn Key> {
15 None
16 }
17}
18
19/// A type-erased widget description suitable for child collections.
20pub type WidgetRef = Rc<dyn Widget>;
21
22/// Optional build contract for widget crates that want to construct a child
23/// description from a context. It is separate from [`Widget`] so core does
24/// not force every renderer-specific widget to choose a child representation.
25pub trait BuildableWidget: Widget {
26 fn build(&self, context: &BuildContext) -> WidgetRef;
27}