Skip to content

Commit 52464c6

Browse files
authored
Merge pull request #52 from ejjonny/fix
fix padding constraints
2 parents c5807f7 + 794f340 commit 52464c6

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

Diff for: examples/demo-site/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/egui-case-study/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ impl eframe::App for MyApp {
169169
)
170170
.align(Align::Leading)
171171
.width_range(120.0..),
172+
space(),
172173
draw(|area, state: &mut State| {
173174
if state
174175
.ui

Diff for: src/constraints.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,28 @@ impl<State> NodeValue<State> {
4242
);
4343
match self {
4444
NodeValue::Padding { amounts, element } => {
45-
element.constraints(allocations[0], state).combine_sum(
46-
SizeConstraints {
47-
width: Constraint {
48-
lower: Some(amounts.trailing + amounts.leading),
49-
upper: None,
50-
},
51-
height: Constraint {
52-
lower: Some(amounts.bottom + amounts.top),
53-
upper: None,
54-
},
55-
aspect: None,
45+
let child = element.constraints(allocations[0], state);
46+
SizeConstraints {
47+
width: Constraint {
48+
lower: Some(
49+
amounts.leading + child.width.lower.unwrap_or(0.) + amounts.trailing,
50+
),
51+
upper: child
52+
.width
53+
.upper
54+
.map(|upper| upper + amounts.leading + amounts.trailing),
5655
},
57-
0.,
58-
)
56+
height: Constraint {
57+
lower: Some(
58+
amounts.top + child.height.lower.unwrap_or(0.) + amounts.bottom,
59+
),
60+
upper: child
61+
.height
62+
.upper
63+
.map(|upper| upper + amounts.top + amounts.bottom),
64+
},
65+
aspect: None,
66+
}
5967
}
6068
NodeValue::Column {
6169
ref mut elements,
@@ -183,13 +191,6 @@ impl SizeConstraints {
183191
aspect: self.aspect.or(other.aspect),
184192
}
185193
}
186-
pub(crate) fn combine_sum(self, other: Self, spacing: f32) -> Self {
187-
SizeConstraints {
188-
width: self.width.combine_sum(other.width, spacing),
189-
height: self.height.combine_sum(other.height, spacing),
190-
aspect: None,
191-
}
192-
}
193194
}
194195

195196
impl Constraint {

Diff for: src/tests/layout_tests.rs

+16
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,20 @@ mod tests {
571571
})
572572
.draw(Area::new(0., 0., 100., 100.), &mut ());
573573
}
574+
#[test]
575+
fn test_explicit_with_padding() {
576+
Layout::new(|()| {
577+
column(vec![
578+
draw(|a, _| {
579+
assert_eq!(a, Area::new(10., 10., 80., 20.));
580+
})
581+
.height(20.)
582+
.pad(10.),
583+
draw(|a, _| {
584+
assert_eq!(a, Area::new(0., 40., 100., 60.));
585+
}),
586+
])
587+
})
588+
.draw(Area::new(0., 0., 100., 100.), &mut ());
589+
}
574590
}

0 commit comments

Comments
 (0)