Expand description
Reference layout engine for Cotis element trees.
cotis-layout implements Cotis’s LayoutManager and
LayoutFrameManager traits. It runs a flexbox-like
sizing and positioning pass over a configured element tree and produces a stream of
RenderCommandOutput values for downstream pipes
(typically cotis-pipes) and renderers.
§Frame lifecycle
- Create a
CotisLayoutManagerwith the viewportDimensions. - Wire it into a
CotisAppwith a renderer. The renderer supplies a text measurer and window dimensions viaLayoutManagerCompatible. - Each frame:
begin_frame()returns aCotisLayoutRun. - UI code opens elements through
ConfigureElements(open_new_element,set_config,close_element). - Text leaves use
ConfigureLeafElementswithTextElementConfig. end()runs layout (fit/grow/shrink, text wrap, positioning) and yields an iterator ofRenderCommandOutput.- A pipe such as
CotisLayoutToRenderListPipeForGenericsconverts those commands into renderer-specific draw lists.
§Quick start
For a runnable desktop demo, use a renderer backend such as
cotis-wgpu or
cotis-raylib. Local examples under examples/
mirror the same wiring once ecosystem crates are on crates.io. A minimal setup looks like:
use cotis::cotis_app::CotisApp;
use cotis_layout::preamble::CotisLayoutManager;
use cotis_pipes::cotis_layout_pipes::CotisLayoutToRenderListPipeForGenerics;
use cotis_utils::math::Dimensions;
let dimensions = Dimensions::new(800.0, 600.0);
let manager = CotisLayoutManager::new(dimensions);
// let app = CotisApp::new(renderer, manager, CotisLayoutToRenderListPipeForGenerics);§Modules
preamble— convenience re-exports:CotisLayoutManager,CotisLayoutRun,TextConfigurable.layout_traits—CotisLayoutCompatible, the bridge trait for custom config types.layout_struct— layout output types (RenderCommandOutput, clip markers,TextDrawPayload).cotis_traits— Cotis trait implementations for the defaultElementConfigintegration path and element-state query hooks.
§Generic config types
To use a config type other than ElementConfig, implement CotisLayoutCompatible to map
your type into the internal layout style representation, and TextConfigurable if your type
supports text leaves. Built-in wiring for ElementConfig lives in cotis_traits.
§Inspecting layout state
After a frame completes, CotisLayoutManager::get_cache_element exposes a snapshot of the
last layout tree for debugging and hit-testing. cotis_traits::secondary_traits implements
cotis_utils::element_state query traits on that cache.
§Cargo features
| Feature | Effect |
|---|---|
serialization | Enables serde on render output types and serialization in cotis, cotis-defaults, and cotis-utils. |
Modules§
- cotis_
traits - Cotis trait implementations wiring
CotisLayoutManagerinto the standard frame and element configuration API. - layout_
struct - Layout output types consumed by pipes and renderers.
- layout_
traits - Bridge trait connecting custom element config types to the layout engine.
- preamble
- Entry-point re-exports for the layout manager and frame configurator.