# layout-cat
Box-model layout engine: cascade CSS rules over a DOM tree and compute a `LayoutBox` tree with positions and dimensions.
`layout-cat` is the fourth sub-crate of a `comp-cat-rs` Servo-replacement webview runtime targeting Tauri integration. It consumes a [`dom-cat`](https://crates.io/crates/dom-cat) document and a [`css-cat`](https://crates.io/crates/css-cat) stylesheet, applies a simple cascade, and lays out block-level boxes. Same framework constraints: no `mut`, no `Rc`/`Arc`, no interior mutability, no panics.
## Example
```rust
use layout_cat::{layout, Error, Viewport};
fn main() -> Result<(), Error> {
let html_doc = html_cat::parse("<html><body><p>hi</p></body></html>")?;
let dom = dom_cat::Document::from_html_doc(&html_doc);
let sheet = css_cat::parse("p { width: 100px; padding: 8px; }")?;
let tree = layout(&dom, &sheet, Viewport::new(800, 600));
assert!(tree.root_box().is_some());
Ok(())
}
```
## v0 scope
- Cascade: match `css-cat` rules to `dom-cat` elements (via dom-cat's matcher) and resolve declarations to a `ComputedStyle`.
- Length resolution: px, em (multiplier on `font-size`), percentage (against containing-block width).
- Box model: margin / border / padding / content per element.
- Block layout: vertical stacking with width/height/margin/padding arithmetic.
- `LayoutTree` of `LayoutBox` with positions, dimensions, and a back-reference to the originating `dom_cat::NodeId`.
## Deferred to v0.2+
- Inline layout, text shaping.
- Flex / grid / floats / positioning (other than `static`).
- Real font metrics; v0 uses `16px` as the default font size.
- Tables, transforms, logical properties.
## License
MIT OR Apache-2.0