summaryrefslogtreecommitdiffstats
path: root/native/src/layout.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-10 01:55:32 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-10 01:55:32 +0100
commit2303111e09d806ef2a652bddc2b73be6dccf6ae2 (patch)
treeba57c5a2fe67d8a58d4f9b32c2b32fee32932f06 /native/src/layout.rs
parent839e039dbf2fb89dcb8c141503740777d2af2eb3 (diff)
downloadiced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.tar.gz
iced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.tar.bz2
iced-2303111e09d806ef2a652bddc2b73be6dccf6ae2.zip
Draft new layout API
Diffstat (limited to 'native/src/layout.rs')
-rw-r--r--native/src/layout.rs47
1 files changed, 21 insertions, 26 deletions
diff --git a/native/src/layout.rs b/native/src/layout.rs
index 32630f35..520bcd88 100644
--- a/native/src/layout.rs
+++ b/native/src/layout.rs
@@ -1,6 +1,8 @@
-use stretch::result;
+use crate::Rectangle;
-use crate::{Point, Rectangle, Vector};
+mod limits;
+
+pub use limits::Limits;
/// The computed bounds of a [`Node`] and its children.
///
@@ -12,25 +14,25 @@ use crate::{Point, Rectangle, Vector};
/// [`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
-#[derive(Debug, Clone, Copy)]
-pub struct Layout<'a> {
- layout: &'a result::Layout,
- position: Point,
+#[derive(Debug, Clone)]
+pub struct Layout {
+ bounds: Rectangle,
+ children: Vec<Layout>,
}
-impl<'a> Layout<'a> {
- pub(crate) fn new(layout: &'a result::Layout) -> Self {
- Self::with_parent_position(layout, Point::new(0.0, 0.0))
+impl Layout {
+ pub fn new(bounds: Rectangle) -> Self {
+ Layout {
+ bounds,
+ children: Vec::new(),
+ }
}
- fn with_parent_position(
- layout: &'a result::Layout,
- parent_position: Point,
- ) -> Self {
- let position =
- parent_position + Vector::new(layout.location.x, layout.location.y);
+ pub fn push(&mut self, mut child: Layout) {
+ child.bounds.x += self.bounds.x;
+ child.bounds.y += self.bounds.y;
- Layout { layout, position }
+ self.children.push(child);
}
/// Gets the bounds of the [`Layout`].
@@ -42,21 +44,14 @@ impl<'a> Layout<'a> {
/// [`Rectangle`]: struct.Rectangle.html
/// [`Node`]: struct.Node.html
pub fn bounds(&self) -> Rectangle {
- Rectangle {
- x: self.position.x,
- y: self.position.y,
- width: self.layout.size.width,
- height: self.layout.size.height,
- }
+ self.bounds
}
/// Returns an iterator over the [`Layout`] of the children of a [`Node`].
///
/// [`Layout`]: struct.Layout.html
/// [`Node`]: struct.Node.html
- pub fn children(&'a self) -> impl Iterator<Item = Layout<'a>> {
- self.layout.children.iter().map(move |layout| {
- Layout::with_parent_position(layout, self.position)
- })
+ pub fn children(&self) -> impl Iterator<Item = &Layout> {
+ self.children.iter()
}
}