2019-11-10 01:55:32 +01:00
|
|
|
use crate::Rectangle;
|
2019-07-20 19:12:31 +02:00
|
|
|
|
2019-11-10 01:55:32 +01:00
|
|
|
mod limits;
|
|
|
|
|
|
|
|
|
|
pub use limits::Limits;
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// The computed bounds of a [`Node`] and its children.
|
|
|
|
|
///
|
|
|
|
|
/// This type is provided by the GUI runtime to [`Widget::on_event`] and
|
2019-08-29 00:58:42 +02:00
|
|
|
/// [`Widget::draw`], describing the layout of the [`Node`] produced by
|
2019-07-20 19:12:31 +02:00
|
|
|
/// [`Widget::node`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Node`]: struct.Node.html
|
2019-08-29 01:28:00 +02:00
|
|
|
/// [`Widget::on_event`]: widget/trait.Widget.html#method.on_event
|
|
|
|
|
/// [`Widget::draw`]: widget/trait.Widget.html#tymethod.draw
|
|
|
|
|
/// [`Widget::node`]: widget/trait.Widget.html#tymethod.node
|
2019-11-10 01:55:32 +01:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Layout {
|
|
|
|
|
bounds: Rectangle,
|
|
|
|
|
children: Vec<Layout>,
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-10 01:55:32 +01:00
|
|
|
impl Layout {
|
|
|
|
|
pub fn new(bounds: Rectangle) -> Self {
|
|
|
|
|
Layout {
|
|
|
|
|
bounds,
|
|
|
|
|
children: Vec::new(),
|
|
|
|
|
}
|
2019-07-23 10:49:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-10 01:55:32 +01:00
|
|
|
pub fn push(&mut self, mut child: Layout) {
|
|
|
|
|
child.bounds.x += self.bounds.x;
|
|
|
|
|
child.bounds.y += self.bounds.y;
|
2019-07-20 19:12:31 +02:00
|
|
|
|
2019-11-10 01:55:32 +01:00
|
|
|
self.children.push(child);
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Gets the bounds of the [`Layout`].
|
|
|
|
|
///
|
|
|
|
|
/// The returned [`Rectangle`] describes the position and size of a
|
|
|
|
|
/// [`Node`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Layout`]: struct.Layout.html
|
2019-08-29 01:28:00 +02:00
|
|
|
/// [`Rectangle`]: struct.Rectangle.html
|
2019-07-20 19:12:31 +02:00
|
|
|
/// [`Node`]: struct.Node.html
|
2019-08-31 04:31:13 +02:00
|
|
|
pub fn bounds(&self) -> Rectangle {
|
2019-11-10 01:55:32 +01:00
|
|
|
self.bounds
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns an iterator over the [`Layout`] of the children of a [`Node`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Layout`]: struct.Layout.html
|
|
|
|
|
/// [`Node`]: struct.Node.html
|
2019-11-10 01:55:32 +01:00
|
|
|
pub fn children(&self) -> impl Iterator<Item = &Layout> {
|
|
|
|
|
self.children.iter()
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
}
|