summaryrefslogtreecommitdiffstats
path: root/native/src/layout
diff options
context:
space:
mode:
authorLibravatar daxpedda <daxpedda@gmail.com>2020-02-14 21:41:35 +0100
committerLibravatar daxpedda <daxpedda@gmail.com>2020-02-14 21:41:35 +0100
commitf4b8bce837513cdd06df3a3ceba86fd9256d3cc5 (patch)
tree5770a36750aac47a7bc656d809f6e217177c6a49 /native/src/layout
parent60b40fdc99647d77febaae1d483fc5642c4ba50d (diff)
downloadiced-f4b8bce837513cdd06df3a3ceba86fd9256d3cc5.tar.gz
iced-f4b8bce837513cdd06df3a3ceba86fd9256d3cc5.tar.bz2
iced-f4b8bce837513cdd06df3a3ceba86fd9256d3cc5.zip
Revert changing the constructor and implement new method.
Diffstat (limited to 'native/src/layout')
-rw-r--r--native/src/layout/flex.rs6
-rw-r--r--native/src/layout/node.rs22
2 files changed, 17 insertions, 11 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs
index 02037b14..2f65f1c1 100644
--- a/native/src/layout/flex.rs
+++ b/native/src/layout/flex.rs
@@ -18,7 +18,7 @@
// limitations under the License.
use crate::{
layout::{Limits, Node},
- Align, Element, Size,
+ Align, Element, Point, Size,
};
/// The main axis of a flex layout.
@@ -152,8 +152,7 @@ where
let (x, y) = axis.pack(main, padding);
- node.bounds.x = x;
- node.bounds.y = y;
+ node.move_to(Point::new(x, y));
match axis {
Axis::Horizontal => {
@@ -174,7 +173,6 @@ where
Node::with_children(
Size::new(size.width + padding * 2.0, size.height + padding * 2.0),
- Size::ZERO,
nodes,
)
}
diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs
index e9885725..777a57fb 100644
--- a/native/src/layout/node.rs
+++ b/native/src/layout/node.rs
@@ -1,9 +1,9 @@
-use crate::{Align, Rectangle, Size};
+use crate::{Align, Point, Rectangle, Size};
/// The bounds of an element and its children.
#[derive(Debug, Clone, Default)]
pub struct Node {
- pub(crate) bounds: Rectangle,
+ bounds: Rectangle,
children: Vec<Node>,
}
@@ -12,19 +12,19 @@ impl Node {
///
/// [`Node`]: struct.Node.html
/// [`Size`]: ../struct.Size.html
- pub fn new(size: Size, bound: Size) -> Self {
- Self::with_children(size, bound, Vec::new())
+ pub fn new(size: Size) -> Self {
+ Self::with_children(size, Vec::new())
}
/// Creates a new [`Node`] with the given [`Size`] and children.
///
/// [`Node`]: struct.Node.html
/// [`Size`]: ../struct.Size.html
- pub fn with_children(size: Size, bound: Size, children: Vec<Node>) -> Self {
+ pub fn with_children(size: Size, children: Vec<Node>) -> Self {
Node {
bounds: Rectangle {
- x: bound.width,
- y: bound.height,
+ x: 0.0,
+ y: 0.0,
width: size.width,
height: size.height,
},
@@ -84,4 +84,12 @@ impl Node {
}
}
}
+
+ /// Move item to [`Point`].
+ ///
+ /// [`Point`]: ../struct.Point.html
+ pub fn move_to(&mut self, position: Point) {
+ self.bounds.x = position.x;
+ self.bounds.y = position.y;
+ }
}