Pane Grid spacing applied prior to rounding
On low-DPI screens, the rounding order of operations made it impossible to produce an odd-pixel spacing. Specifying 1, for instance, produced zero space between panes. This approach subtracts half the spacing from the first pane prior to rounding and uses the whole spacing for the second pane size and coordinate.
This commit is contained in:
parent
5324eb1024
commit
334dd09817
@ -14,37 +14,39 @@ impl Axis {
|
||||
&self,
|
||||
rectangle: &Rectangle,
|
||||
ratio: f32,
|
||||
halved_spacing: f32,
|
||||
spacing: f32,
|
||||
) -> (Rectangle, Rectangle) {
|
||||
match self {
|
||||
Axis::Horizontal => {
|
||||
let height_top = (rectangle.height * ratio).round();
|
||||
let height_bottom = rectangle.height - height_top;
|
||||
let height_top =
|
||||
(rectangle.height * ratio - spacing / 2.0).round();
|
||||
let height_bottom = rectangle.height - height_top - spacing;
|
||||
|
||||
(
|
||||
Rectangle {
|
||||
height: height_top - halved_spacing,
|
||||
height: height_top,
|
||||
..*rectangle
|
||||
},
|
||||
Rectangle {
|
||||
y: rectangle.y + height_top + halved_spacing,
|
||||
height: height_bottom - halved_spacing,
|
||||
y: rectangle.y + height_top + spacing,
|
||||
height: height_bottom,
|
||||
..*rectangle
|
||||
},
|
||||
)
|
||||
}
|
||||
Axis::Vertical => {
|
||||
let width_left = (rectangle.width * ratio).round();
|
||||
let width_right = rectangle.width - width_left;
|
||||
let width_left =
|
||||
(rectangle.width * ratio - spacing / 2.0).round();
|
||||
let width_right = rectangle.width - width_left - spacing;
|
||||
|
||||
(
|
||||
Rectangle {
|
||||
width: width_left - halved_spacing,
|
||||
width: width_left,
|
||||
..*rectangle
|
||||
},
|
||||
Rectangle {
|
||||
x: rectangle.x + width_left + halved_spacing,
|
||||
width: width_right - halved_spacing,
|
||||
x: rectangle.x + width_left + spacing,
|
||||
width: width_right,
|
||||
..*rectangle
|
||||
},
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ impl Node {
|
||||
let mut regions = HashMap::new();
|
||||
|
||||
self.compute_regions(
|
||||
spacing / 2.0,
|
||||
spacing,
|
||||
&Rectangle {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
@ -83,7 +83,7 @@ impl Node {
|
||||
let mut splits = HashMap::new();
|
||||
|
||||
self.compute_splits(
|
||||
spacing / 2.0,
|
||||
spacing,
|
||||
&Rectangle {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
@ -185,7 +185,7 @@ impl Node {
|
||||
|
||||
fn compute_regions(
|
||||
&self,
|
||||
halved_spacing: f32,
|
||||
spacing: f32,
|
||||
current: &Rectangle,
|
||||
regions: &mut HashMap<Pane, Rectangle>,
|
||||
) {
|
||||
@ -193,11 +193,10 @@ impl Node {
|
||||
Node::Split {
|
||||
axis, ratio, a, b, ..
|
||||
} => {
|
||||
let (region_a, region_b) =
|
||||
axis.split(current, *ratio, halved_spacing);
|
||||
let (region_a, region_b) = axis.split(current, *ratio, spacing);
|
||||
|
||||
a.compute_regions(halved_spacing, ®ion_a, regions);
|
||||
b.compute_regions(halved_spacing, ®ion_b, regions);
|
||||
a.compute_regions(spacing, ®ion_a, regions);
|
||||
b.compute_regions(spacing, ®ion_b, regions);
|
||||
}
|
||||
Node::Pane(pane) => {
|
||||
let _ = regions.insert(*pane, *current);
|
||||
@ -207,7 +206,7 @@ impl Node {
|
||||
|
||||
fn compute_splits(
|
||||
&self,
|
||||
halved_spacing: f32,
|
||||
spacing: f32,
|
||||
current: &Rectangle,
|
||||
splits: &mut HashMap<Split, (Axis, Rectangle, f32)>,
|
||||
) {
|
||||
@ -219,13 +218,12 @@ impl Node {
|
||||
b,
|
||||
id,
|
||||
} => {
|
||||
let (region_a, region_b) =
|
||||
axis.split(current, *ratio, halved_spacing);
|
||||
let (region_a, region_b) = axis.split(current, *ratio, spacing);
|
||||
|
||||
let _ = splits.insert(*id, (*axis, *current, *ratio));
|
||||
|
||||
a.compute_splits(halved_spacing, ®ion_a, splits);
|
||||
b.compute_splits(halved_spacing, ®ion_b, splits);
|
||||
a.compute_splits(spacing, ®ion_a, splits);
|
||||
b.compute_splits(spacing, ®ion_b, splits);
|
||||
}
|
||||
Node::Pane(_) => {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user