cotis_layout/layout_traits.rs
1//! Bridge trait connecting custom element config types to the layout engine.
2//!
3//! Any config type `T` used with [`CotisLayoutManager`](crate::preamble::CotisLayoutManager) as
4//! `LayoutManager<T, RenderCommandOutput<T>>` must implement [`CotisLayoutCompatible`]. The
5//! built-in implementation for [`ElementConfig`](cotis_defaults::element_configs::ElementConfig)
6//! lives in [`crate::cotis_traits`].
7
8use crate::layout_struct::layout_states::LayoutElementConfig;
9use cotis::utils::ElementId;
10use cotis::utils::OwnedOrRef;
11
12/// Maps a user-facing element config into layout-engine data.
13///
14/// Called when [`ConfigureElements::set_config`](cotis::element_configuring::ConfigureElements::set_config)
15/// is invoked on a [`CotisLayoutRun`](crate::preamble::CotisLayoutRun). The layout style is
16/// extracted and stored on the internal tree node; the original config is retained for render
17/// command emission.
18///
19/// Custom config authors typically implement this alongside [`TextConfigurable`](crate::preamble::TextConfigurable)
20/// when text leaves are needed.
21///
22/// # Examples
23///
24/// ```
25/// use cotis::utils::ElementIdConfig;
26/// use cotis_layout::layout_traits::CotisLayoutCompatible;
27/// use cotis_defaults::element_configs::premade_configs::GenericElementConfig;
28///
29/// type MyConfig = GenericElementConfig<'static, (), ()>;
30///
31/// let config = MyConfig {
32/// id_config: ElementIdConfig::new_empty(),
33/// style: Default::default(),
34/// image: None,
35/// custom: None,
36/// extra_data: None,
37/// };
38///
39/// let _id = CotisLayoutCompatible::get_id(&config);
40/// let _name = CotisLayoutCompatible::try_get_name(&config);
41/// ```
42pub trait CotisLayoutCompatible<'name> {
43 /// Layout style derived from this config (padding, sizing, clip, float, etc.).
44 fn get_style(&self) -> LayoutElementConfig;
45
46 /// Stable element identifier used for tree nodes and render commands.
47 fn get_id(&self) -> ElementId;
48
49 /// Optional debug name appended to the internal layout node.
50 fn try_get_name(&self) -> Option<OwnedOrRef<'name, str>>;
51}