Skip to content

Commit 44ffad1

Browse files
committed
feat(ie-layout): implement CSS flexbox layout #26
Flexbox layout engine (flex.rs): - flex-direction: row, column, row-reverse, column-reverse - flex-wrap: nowrap (default), wrap, wrap-reverse - justify-content: flex-start, flex-end, center, space-between, space-around, space-evenly - align-items: flex-start, flex-end, center, stretch (default) - Per-item align-self override - flex-grow: distribute free space proportionally - flex-shrink: shrink items when space is negative - flex-basis: explicit base size before grow/shrink - Flex line splitting for wrap mode - Recursive child layout within flex items - Content-based sizing fallback via text measurement Integration: - BoxType::Flex variant added - display:flex routed to layout_flex in box generation - Block layout dispatches Flex children to flex layout 6 new tests: equal grow, column direction, justify center, align items center, space-between, wrap. 24 total ie-layout tests.
1 parent a06656a commit 44ffad1

4 files changed

Lines changed: 631 additions & 5 deletions

File tree

crates/ie-layout/src/block.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ pub fn layout_block(
208208
height: metrics.height,
209209
};
210210
}
211+
BoxType::Flex => {
212+
crate::flex::layout_flex(
213+
child_idx,
214+
tree,
215+
styles,
216+
content_width,
217+
child_y,
218+
text_measure,
219+
);
220+
}
211221
BoxType::Inline | BoxType::InlineBlock => {
212222
// Simplified: treat as block for now
213223
layout_block(

crates/ie-layout/src/box_generation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fn generate_boxes(
3636
}
3737

3838
let box_type = match display {
39-
"block" | "list-item" | "table" | "flex" => BoxType::Block,
39+
"flex" => BoxType::Flex,
40+
"block" | "list-item" | "table" => BoxType::Block,
4041
"inline" => BoxType::Inline,
4142
"inline-block" => BoxType::InlineBlock,
4243
_ => BoxType::Block,
@@ -67,17 +68,17 @@ fn generate_boxes(
6768
// Insert anonymous block boxes when mixing block+inline children
6869
let has_block = child_indices
6970
.iter()
70-
.any(|&i| matches!(tree.boxes[i].box_type, BoxType::Block));
71+
.any(|&i| matches!(tree.boxes[i].box_type, BoxType::Block | BoxType::Flex));
7172
let has_inline = child_indices
7273
.iter()
73-
.any(|&i| !matches!(tree.boxes[i].box_type, BoxType::Block));
74+
.any(|&i| !matches!(tree.boxes[i].box_type, BoxType::Block | BoxType::Flex));
7475

7576
if has_block && has_inline && matches!(box_type, BoxType::Block) {
7677
let mut wrapped = Vec::new();
7778
let mut inline_run = Vec::new();
7879

7980
for &idx in &child_indices {
80-
if matches!(tree.boxes[idx].box_type, BoxType::Block) {
81+
if matches!(tree.boxes[idx].box_type, BoxType::Block | BoxType::Flex) {
8182
if !inline_run.is_empty() {
8283
let anon = LayoutBox {
8384
node_id: None,

0 commit comments

Comments
 (0)