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(); let top_left = child_region.top_left();
add_contents(child_region); add_contents(child_region);
// Pretend children took up less space than they did:
child_region.child_bounds.max.y = // Pretend children took up less space:
child_region.child_bounds.max.y.min(top_left.y + max_height); 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 { } else if state.open {
region.indent(id, add_contents); region.indent(id, add_contents);

View file

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

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] #[must_use]
pub fn expand(self, amnt: f32) -> Self { pub fn expand(self, amnt: f32) -> Self {
Rect::from_center_size(self.center(), self.size() + 2.0 * vec2(amnt, amnt)) 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] #[must_use]
pub fn translate(self, amnt: Vec2) -> Self { pub fn translate(self, amnt: Vec2) -> Self {
Rect::from_min_size(self.min + amnt, self.size()) 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). /// but may overflow (which you will see in child_bounds).
desired_rect: Rect, // TODO: rename? desired_rect: Rect, // TODO: rename?
/// Bounding box of children. /// Bounding box of all children.
// TODO: remove pub(crate) /// This is used to see how large a region actually
pub(crate) child_bounds: Rect, /// needs to be after all children has been added.
child_bounds: Rect,
/// Overide default style in this region /// Overide default style in this region
style: Style, style: Style,
@ -188,6 +189,21 @@ impl Region {
self.child_bounds.max - self.desired_rect.min 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: // Layout related measures: