Inset container contents to account for container border

This commit is contained in:
Nathan Sobo 2021-03-31 22:58:12 -06:00
parent e487aa5cbd
commit 995acefce5
2 changed files with 19 additions and 1 deletions

View file

@ -168,7 +168,9 @@ impl Element for Container {
corner_radius: self.corner_radius,
});
let child_origin = quad_bounds.origin() + vec2f(self.padding.left, self.padding.top);
let child_origin = quad_bounds.origin()
+ vec2f(self.padding.left, self.padding.top)
+ vec2f(self.border.left_width(), self.border.top_width());
self.child.paint(child_origin, ctx);
}

View file

@ -222,4 +222,20 @@ impl Border {
fn all_sides(&self) -> bool {
self.top && self.left && self.bottom && self.right
}
pub fn top_width(&self) -> f32 {
if self.top {
self.width
} else {
0.0
}
}
pub fn left_width(&self) -> f32 {
if self.left {
self.width
} else {
0.0
}
}
}