Fix spacing calculation in Axis::split

This commit is contained in:
Héctor Ramón Jiménez 2020-03-17 04:15:17 +01:00
parent c7583f1227
commit 21a4095a99

View file

@ -15,36 +15,33 @@ impl Axis {
) -> (Rectangle, Rectangle) { ) -> (Rectangle, Rectangle) {
match self { match self {
Axis::Horizontal => { Axis::Horizontal => {
let height_top = let height_top = (rectangle.height * ratio).round();
(rectangle.height * ratio).round() - halved_spacing; let height_bottom = rectangle.height - height_top;
let height_bottom =
rectangle.height - height_top - halved_spacing;
( (
Rectangle { Rectangle {
height: height_top, height: height_top - halved_spacing,
..*rectangle ..*rectangle
}, },
Rectangle { Rectangle {
y: rectangle.y + height_top + halved_spacing, y: rectangle.y + height_top + halved_spacing,
height: height_bottom, height: height_bottom - halved_spacing,
..*rectangle ..*rectangle
}, },
) )
} }
Axis::Vertical => { Axis::Vertical => {
let width_left = let width_left = (rectangle.width * ratio).round();
(rectangle.width * ratio).round() - halved_spacing; let width_right = rectangle.width - width_left;
let width_right = rectangle.width - width_left - halved_spacing;
( (
Rectangle { Rectangle {
width: width_left, width: width_left - halved_spacing,
..*rectangle ..*rectangle
}, },
Rectangle { Rectangle {
x: rectangle.x + width_left + halved_spacing, x: rectangle.x + width_left + halved_spacing,
width: width_right, width: width_right - halved_spacing,
..*rectangle ..*rectangle
}, },
) )