Enforce minimum pane size by counting splits in each axis
This commit is contained in:
parent
2a43921c56
commit
1445e068e0
2 changed files with 141 additions and 31 deletions
|
|
@ -17,17 +17,18 @@ impl Axis {
|
|||
rectangle: &Rectangle,
|
||||
ratio: f32,
|
||||
spacing: f32,
|
||||
min_size: f32,
|
||||
min_size_a: f32,
|
||||
min_size_b: f32,
|
||||
) -> (Rectangle, Rectangle, f32) {
|
||||
match self {
|
||||
Axis::Horizontal => {
|
||||
let height_top = (rectangle.height * ratio - spacing / 2.0)
|
||||
.round()
|
||||
.max(min_size)
|
||||
.min(rectangle.height - min_size);
|
||||
.max(min_size_a)
|
||||
.min(rectangle.height - min_size_b - spacing);
|
||||
|
||||
let height_bottom =
|
||||
(rectangle.height - height_top - spacing).max(min_size);
|
||||
(rectangle.height - height_top - spacing).max(min_size_b);
|
||||
|
||||
let ratio = (height_top + spacing / 2.0) / rectangle.height;
|
||||
|
||||
|
|
@ -47,11 +48,11 @@ impl Axis {
|
|||
Axis::Vertical => {
|
||||
let width_left = (rectangle.width * ratio - spacing / 2.0)
|
||||
.round()
|
||||
.max(min_size)
|
||||
.min(rectangle.width - min_size);
|
||||
.max(min_size_a)
|
||||
.min(rectangle.width - min_size_b - spacing);
|
||||
|
||||
let width_right =
|
||||
(rectangle.width - width_left - spacing).max(min_size);
|
||||
(rectangle.width - width_left - spacing).max(min_size_b);
|
||||
|
||||
let ratio = (width_left + spacing / 2.0) / rectangle.width;
|
||||
|
||||
|
|
@ -202,7 +203,8 @@ mod tests {
|
|||
width: 10.0,
|
||||
height: overall_height,
|
||||
};
|
||||
let (top, bottom, _ratio) = a.split(&r, 0.5, spacing, 0.0);
|
||||
let (top, bottom, _ratio) =
|
||||
a.split(&r, 0.5, spacing, 0.0, 0.0);
|
||||
assert_eq!(
|
||||
top,
|
||||
Rectangle {
|
||||
|
|
@ -233,7 +235,8 @@ mod tests {
|
|||
width: overall_width,
|
||||
height: 10.0,
|
||||
};
|
||||
let (left, right, _ratio) = a.split(&r, 0.5, spacing, 0.0);
|
||||
let (left, right, _ratio) =
|
||||
a.split(&r, 0.5, spacing, 0.0, 0.0);
|
||||
assert_eq!(
|
||||
left,
|
||||
Rectangle {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue