Make Region::child_bounds private

This commit is contained in:
Emil Ernerfeldt 2020-05-05 08:15:20 +02:00
parent 2f9e70febf
commit fade508c15
4 changed files with 33 additions and 11 deletions

View file

@ -120,9 +120,11 @@ impl CollapsingHeader {
let top_left = child_region.top_left();
add_contents(child_region);
// Pretend children took up less space than they did:
child_region.child_bounds.max.y =
child_region.child_bounds.max.y.min(top_left.y + max_height);
// Pretend children took up less space:
let mut child_bounds = child_region.child_bounds();
child_bounds.max.y = child_bounds.max.y.min(top_left.y + max_height);
child_region.force_set_child_bounds(child_bounds);
});
} else if state.open {
region.indent(id, add_contents);

View file

@ -35,9 +35,7 @@ impl Frame {
},
);
// TODO: move up corsor?
region
.child_bounds
.extend_with(child_region.child_bounds.max + margin);
region.expand_to_include_child(child_region.rect().expand2(margin));
// TODO: move up cursor?
}
}

View file

@ -358,12 +358,18 @@ impl Rect {
}
}
/// Expand by this much in each direction
/// Expand by this much in each direction, keeping the center
#[must_use]
pub fn expand(self, amnt: f32) -> Self {
Rect::from_center_size(self.center(), self.size() + 2.0 * vec2(amnt, amnt))
}
/// Expand by this much in each direction, keeping the center
#[must_use]
pub fn expand2(self, amnt: Vec2) -> Self {
Rect::from_center_size(self.center(), self.size() + 2.0 * amnt)
}
#[must_use]
pub fn translate(self, amnt: Vec2) -> Self {
Rect::from_min_size(self.min + amnt, self.size())

View file

@ -30,9 +30,10 @@ pub struct Region {
/// but may overflow (which you will see in child_bounds).
desired_rect: Rect, // TODO: rename?
/// Bounding box of children.
// TODO: remove pub(crate)
pub(crate) child_bounds: Rect,
/// Bounding box of all children.
/// This is used to see how large a region actually
/// needs to be after all children has been added.
child_bounds: Rect,
/// Overide default style in this region
style: Style,
@ -188,6 +189,21 @@ impl Region {
self.child_bounds.max - self.desired_rect.min
}
/// Expand the bounding rect of this region to include a child at the given rect.
pub fn expand_to_include_child(&mut self, rect: Rect) {
self.child_bounds.extend_with(rect.min);
self.child_bounds.extend_with(rect.max);
}
/// Bounding box of all contained children
pub fn child_bounds(&self) -> Rect {
self.child_bounds
}
pub fn force_set_child_bounds(&mut self, child_bounds: Rect) {
self.child_bounds = child_bounds;
}
// ------------------------------------------------------------------------
// Layout related measures: