Skip to main content

Crate cotis_layout

Crate cotis_layout 

Source
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

  1. Create a CotisLayoutManager with the viewport Dimensions.
  2. Wire it into a CotisApp with a renderer. The renderer supplies a text measurer and window dimensions via LayoutManagerCompatible.
  3. Each frame: begin_frame() returns a CotisLayoutRun.
  4. UI code opens elements through ConfigureElements (open_new_element, set_config, close_element).
  5. Text leaves use ConfigureLeafElements with TextElementConfig.
  6. end() runs layout (fit/grow/shrink, text wrap, positioning) and yields an iterator of RenderCommandOutput.
  7. A pipe such as CotisLayoutToRenderListPipeForGenerics converts 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

§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

FeatureEffect
serializationEnables serde on render output types and serialization in cotis, cotis-defaults, and cotis-utils.

Modules§

cotis_traits
Cotis trait implementations wiring CotisLayoutManager into 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.