MCPcopy Create free account
hub / github.com/algoscienceacademy/RustUI / recalculate_layout

Method recalculate_layout

src/components/stack.rs:47–75  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

45 }
46
47 fn recalculate_layout(&mut self) {
48 let mut width: f32 = 0.0;
49 let mut height: f32 = 0.0;
50 self.child_positions.clear();
51
52 let mut current_x: f32 = self.bounds.origin.x;
53 let mut current_y: f32 = self.bounds.origin.y;
54
55 for child in self.children.iter() {
56 let child_bounds = child.bounds();
57
58 match self.direction {
59 Direction::Horizontal => {
60 self.child_positions.push(Point::new(current_x, current_y));
61 current_x += child_bounds.size.width + self.spacing;
62 width = current_x - self.spacing;
63 height = height.max(child_bounds.size.height);
64 }
65 Direction::Vertical => {
66 self.child_positions.push(Point::new(current_x, current_y));
67 current_y += child_bounds.size.height + self.spacing;
68 height = current_y - self.spacing;
69 width = width.max(child_bounds.size.width);
70 }
71 }
72 }
73
74 self.bounds.size = Size { width, height };
75 }
76}
77
78impl Component for Stack {

Callers 2

spacingMethod · 0.80
childMethod · 0.80

Calls 3

pushMethod · 0.80
clearMethod · 0.45
boundsMethod · 0.45

Tested by

no test coverage detected