Skip to content

Commit

Permalink
fixing broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed Sep 23, 2024
1 parent c1ad6b6 commit 7867d6f
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Widget for Align {
};

ctx.pos += child_offset;
child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Break(())
});
}
Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl Widget for Border {
ctx.pos.x += self.edges[BORDER_EDGE_LEFT].width() as i32;
}

child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);

ControlFlow::Break(())
});
Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Widget for Container {
ctx: PositionCtx,
) {
children.for_each(|child, children| {
child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Break(())
});
}
Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Widget for Expand {
ctx: PositionCtx,
) {
children.for_each(|node, children| {
node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Break(())
});
}
Expand Down
4 changes: 2 additions & 2 deletions anathema-default-widgets/src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Widget for Overflow {
children.for_each(|node, children| {
match direction {
Direction::Forward => {
node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
match axis {
Axis::Horizontal => ctx.pos.x += node.size().width as i32,
Axis::Vertical => ctx.pos.y += node.size().height as i32,
Expand All @@ -190,7 +190,7 @@ impl Widget for Overflow {
Axis::Horizontal => ctx.pos.x -= node.size().width as i32,
Axis::Vertical => ctx.pos.y -= node.size().height as i32,
}
node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
}
}

Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Widget for Padding {
ctx.pos.y += self.0.top as i32;
ctx.pos.x += self.0.left as i32;

child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Break(())
});
}
Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Widget for Position {
ctx.pos.y = offset;
}
}
child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Break(())
});
}
Expand Down
6 changes: 3 additions & 3 deletions anathema-default-widgets/src/stacks/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl Widget for Column {
let child_width = size.width as i32;
let x = x_offset - child_width / 2;

ctx.pos.x += x;

child.position(children, ctx, attribute_storage, ctx.viewport);
let mut pos = ctx.pos;
pos.x += x;
child.position(children, ctx, pos, attribute_storage, ctx.viewport);
ctx.pos.y += size.height as i32;
ControlFlow::Continue(())
});
Expand Down
19 changes: 10 additions & 9 deletions anathema-default-widgets/src/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,36 @@ impl Stack {
mut children: PositionChildren<'_, '_, 'bp>,
id: WidgetId,
attribute_storage: &AttributeStorage<'bp>,
mut ctx: PositionCtx,
ctx: PositionCtx,
) {
let attributes = attribute_storage.get(id);
let direction = attributes.get(DIRECTION).unwrap_or_default();
let mut pos = ctx.pos;

if let Direction::Backward = direction {
match self.0 {
Axis::Horizontal => ctx.pos.x += ctx.inner_size.width as i32,
Axis::Vertical => ctx.pos.y += ctx.inner_size.height as i32,
Axis::Horizontal => pos.x += ctx.inner_size.width as i32,
Axis::Vertical => pos.y += ctx.inner_size.height as i32,
}
}

children.for_each(|node, children| {
match direction {
Direction::Forward => {
node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, pos, attribute_storage, ctx.viewport);

match self.0 {
Axis::Horizontal => ctx.pos.x += node.size().width as i32,
Axis::Vertical => ctx.pos.y += node.size().height as i32,
Axis::Horizontal => pos.x += node.size().width as i32,
Axis::Vertical => pos.y += node.size().height as i32,
}
}
Direction::Backward => {
match self.0 {
Axis::Horizontal => ctx.pos.x += node.size().width as i32,
Axis::Vertical => ctx.pos.y -= node.size().height as i32,
Axis::Horizontal => pos.x += node.size().width as i32,
Axis::Vertical => pos.y -= node.size().height as i32,
}

node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, pos, attribute_storage, ctx.viewport);
}
}

Expand Down
5 changes: 3 additions & 2 deletions anathema-default-widgets/src/stacks/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ impl Widget for Row {
let child_height = size.height as i32;
let y = y_offset - child_height / 2;

ctx.pos.y += y;
child.position(children, ctx, attribute_storage, ctx.viewport);
let mut pos = ctx.pos;
pos.y += y;
child.position(children, ctx, pos, attribute_storage, ctx.viewport);
ctx.pos.x += size.width as i32;
ControlFlow::Continue(())
});
Expand Down
2 changes: 1 addition & 1 deletion anathema-default-widgets/src/stacks/zstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Widget for ZStack {
ctx: PositionCtx,
) {
children.for_each(|child, children| {
child.position(children, ctx, attribute_storage, ctx.viewport);
child.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ControlFlow::Continue(())
});
}
Expand Down
15 changes: 10 additions & 5 deletions anathema-widgets/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ impl Container {
pub fn position<'bp>(
&mut self,
children: PositionChildren<'_, '_, 'bp>,
mut ctx: PositionCtx,
ctx: PositionCtx,
pos: Pos,
attribute_storage: &AttributeStorage<'bp>,
_viewport: Viewport,
viewport: Viewport,
) {
if !matches!(self.needs, WidgetNeeds::Position) {
return;
}
self.needs = WidgetNeeds::Paint;

self.pos = ctx.pos;

ctx.set_clip_region(Region::from((ctx.pos, self.size)));
self.pos = pos;
let ctx = PositionCtx {
inner_size: self.size,
pos,
viewport,
clip: Region::from((ctx.pos, self.size)),
};

self.inner.any_position(children, self.id, attribute_storage, ctx);
self.inner_bounds = self.inner.any_inner_bounds(self.pos, self.size);
Expand Down
2 changes: 1 addition & 1 deletion anathema-widgets/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn position_widget<'bp>(
viewport,
clip: Region::from((pos, viewport.size)),
};
element.position(children, ctx, attribute_storage, viewport);
element.position(children, ctx, pos, attribute_storage, viewport);
}

#[derive(Debug, Copy, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion anathema-widgets/src/nodes/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ impl<'bp> Element<'bp> {
&mut self,
children: PositionChildren<'_, '_, 'bp>,
ctx: PositionCtx,
pos: Pos,
attribute_storage: &AttributeStorage<'bp>,
viewport: Viewport,
) {
self.container.position(children, ctx, attribute_storage, viewport);
self.container.position(children, ctx, pos, attribute_storage, viewport);
let region = Region::from((self.get_pos(), self.size()));
if ctx.clip.intersects(&region) {
self.visible = true;
Expand Down
2 changes: 1 addition & 1 deletion anathema-widgets/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl Widget for TestWidget {
) {
ctx.pos = Pos::ZERO;
children.for_each(|node, children| {
node.position(children, ctx, attribute_storage, ctx.viewport);
node.position(children, ctx, ctx.pos, attribute_storage, ctx.viewport);
ctx.pos.y += node.size().height as i32;

ControlFlow::Continue(())
Expand Down

0 comments on commit 7867d6f

Please sign in to comment.