Repository navigation
feat(layout): declarative layout engine with nested rows/cols (#3) - #24
Conversation
The third axis of the 3-axis model. Takes a Layout tree + a widget-id to Payload map, walks the tree, and hands each leaf rect to render_payload. Config system (#2) will drive this declaratively from TOML later; for now main.rs constructs the tree programmatically. Layout primitives: - Layout::rows / Layout::cols — nested stacks - Layout::widget(id) — leaf referencing a widget by id - Layout::empty — explicit blank cell Child sizing: - Child::fill(weight) — Ratatui Constraint::Fill (proportional) - Child::length(n) — Ratatui Constraint::Length (exact) - Child::min(n) — Ratatui Constraint::Min (flex with minimum) main.rs demo now drives the render path through layout::draw with an explicit demo_layout tree + demo_widgets map, replacing the hardcoded Layout::vertical calls. Refs #3 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughA new composable layout system has been introduced via Changes
Sequence DiagramsequenceDiagram
participant App as Application
participant Layout as Layout System
participant Panel as Panel
participant Widget as Widget Renderer
participant Payload as Payload Map
participant Frame as Ratatui Frame
App->>Layout: draw(frame, area, &layout, &widgets)
alt Layout is Stack
Layout->>Layout: Split area by Direction & Sizes
loop For each Child
Layout->>Layout: Compute child rectangle
Layout->>Layout: Recursively draw child
end
end
alt Layout is Widget
Layout->>Panel: Check if Panel exists
alt Panel Present
Panel->>Frame: Build Block with border/title
Panel->>Frame: Get inner rectangle
end
Layout->>Payload: Lookup WidgetId
alt Widget Found
Payload->>Widget: Render Payload.body
Widget->>Frame: Draw to rectangle
end
end
alt Layout is Empty
Layout->>Frame: Render nothing
end
Frame->>App: Return rendered frame
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Completes the mapping to Ratatui's Constraint repertoire so layouts can express caps (Max) and explicit percentages. Fill / Length / Min cover the common case; Max / Percentage round out the long tail. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Fixes a category mistake that made group-style borders impossible
without double-drawing:
- Payload.title and the auto-Block in render_payload tangled decoration
with data. Result: a single widget got a border automatically, but
wrapping several widgets in a shared outer frame would double-line
every leaf.
- Title and borders are layout concerns, not data concerns. The plugin
protocol and widget fetchers should produce raw data; config decides
how to dress it.
Redesign:
- Payload: dropped the `title` field. Plugins now emit pure data.
- render::render_payload: no longer wraps in a Block. Each renderer
draws into the area it is given, bare.
- layout::Layout gained an optional `Panel { title, border }` on both
Stack and Widget variants. Panel draws a Block (title + BorderStyle:
Plain / Rounded / Thick / Double) around any subtree.
- Ergonomics: `Layout::widget("git").titled("Git").bordered(Rounded)`
chains decoration; `Layout::rows(...).titled("System")` makes a
bordered group around multiple widgets.
- main.rs demo updated to decorate each leaf explicitly via .titled(...).
Double borders are now structurally impossible: no Block is drawn
unless a Panel is present on that specific Layout node.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Third axis of the 3-axis model.
layout::drawwalks a declarativeLayouttree and hands each leaf rect torender_payload. Config (#2) will later drive the tree from TOML; for nowmain.rsconstructs it programmatically.Layout primitives
```rust
Layout::rows(vec![...]) // vertical stack
Layout::cols(vec![...]) // horizontal stack
Layout::widget(id) // leaf referencing a widget by id
Layout::empty // explicit blank cell
```
Size constraints (full mapping to Ratatui `Constraint`):
`Child::fill(w) / length(n) / min(n) / max(n) / percentage(p)`.
Panels (titles + borders)
Both `Widget` and `Stack` nodes can carry an optional `Panel` that draws a `Block` with a title and border:
```rust
Layout::widget("git").titled("Git").bordered(BorderStyle::Rounded)
Layout::cols(vec![
Child::fill(1, Layout::widget("cpu")),
Child::fill(1, Layout::widget("mem")),
Child::fill(1, Layout::widget("disk")),
]).titled("System")
```
BorderStyle covers Plain / Rounded / Thick / Double.
Important redesign: `Payload.title` was removed and `render_payload` no longer auto-wraps widgets in a `Block`. Decoration is now purely a layout concern — plugins and fetchers produce raw data, config decides how to dress it. This makes the Group pattern (shared outer border around multiple widgets) structurally possible without double-lining individual leaves.
Design
Fill) instead of wtfutil's absolute grid — reflows cleanly on resize.Test plan
cargo build(zero warnings)cargo test(33 passed: 12 payload + 12 render + 9 layout)cargo clippy --all-targets -- -D warningscargo fmt --checkCloses #3.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor