Skip to content

Commit

Permalink
fix 'parent' size and point for sibilings
Browse files Browse the repository at this point in the history
  • Loading branch information
d0iasm committed Jun 9, 2024
1 parent 0d51b7c commit 555cf3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
45 changes: 17 additions & 28 deletions core/src/renderer/layout/layout_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,14 @@ impl LayoutObject {
let mut height = 0;
let mut child = self.first_child();
while child.is_some() {
height += child
.clone()
.expect("first child should exist")
.borrow()
.size
.height();

child = child
.expect("first child should exist")
.borrow()
.next_sibling();
let c = match child {
Some(c) => c,
None => panic!("first child should exist"),
};

height += c.borrow().size.height();

child = c.borrow().next_sibling();
}
size.set_height(height);
}
Expand All @@ -302,23 +299,15 @@ impl LayoutObject {
let mut height = 0;
let mut child = self.first_child();
while child.is_some() {
width += child
.clone()
.expect("first child should exist")
.borrow()
.size
.width();
height += child
.clone()
.expect("first child should exist")
.borrow()
.size
.height();

child = child
.expect("first child should exist")
.borrow()
.next_sibling();
let c = match child {
Some(c) => c,
None => panic!("first child should exist"),
};

width += c.borrow().size.width();
height += c.borrow().size.height();

child = c.borrow().next_sibling();
}

size.set_width(width);
Expand Down
2 changes: 1 addition & 1 deletion core/src/renderer/layout/layout_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl LayoutView {
Self::layout_node(&first_child, &n.borrow().size(), &n.borrow().point());

let next_sibling = n.borrow().next_sibling();
Self::layout_node(&next_sibling, &n.borrow().size(), &n.borrow().point());
Self::layout_node(&next_sibling, parent_size, parent_point);

// TODO: optimize this code because we call update_layout() twice.
// For inline, text elements and the height of block elements, we should layout the size after calling children.
Expand Down

0 comments on commit 555cf3d

Please sign in to comment.