From 457d6f616af7359029b07d34d7e6cc1ab6cc6793 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 14 Feb 2020 15:36:33 +0100 Subject: Make `Node::align` public. --- native/src/layout/node.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'native/src/layout') diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index ed1cd3da..fae6e330 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -54,7 +54,11 @@ impl Node { &self.children } - pub(crate) fn align( + /// Aligns item according to [`Align`] and [`Size`]. + /// + /// [`Align`]: ../enum.Align.html + /// [`Size`]: ../struct.Size.html + pub fn align( &mut self, horizontal_alignment: Align, vertical_alignment: Align, -- cgit From b72bd0b2b5c9c2a5c3f508a13ad9578169046a36 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 14 Feb 2020 15:57:07 +0100 Subject: Add `bound` to `Node` constructor. --- native/src/layout/flex.rs | 1 + native/src/layout/node.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'native/src/layout') diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index bd37b75a..02037b14 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -174,6 +174,7 @@ 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 fae6e330..e9885725 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -12,19 +12,19 @@ impl Node { /// /// [`Node`]: struct.Node.html /// [`Size`]: ../struct.Size.html - pub fn new(size: Size) -> Self { - Self::with_children(size, Vec::new()) + pub fn new(size: Size, bound: Size) -> Self { + Self::with_children(size, bound, 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, children: Vec) -> Self { + pub fn with_children(size: Size, bound: Size, children: Vec) -> Self { Node { bounds: Rectangle { - x: 0.0, - y: 0.0, + x: bound.width, + y: bound.height, width: size.width, height: size.height, }, -- cgit From f4b8bce837513cdd06df3a3ceba86fd9256d3cc5 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 14 Feb 2020 21:41:35 +0100 Subject: Revert changing the constructor and implement new method. --- native/src/layout/flex.rs | 6 ++---- native/src/layout/node.rs | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'native/src/layout') 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, } @@ -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) -> Self { + pub fn with_children(size: Size, children: Vec) -> 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; + } } -- cgit From 8f83c805b15230a2f35002cfff88d9653ee08690 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 14 Feb 2020 23:23:45 +0100 Subject: Improve documentation for new `Node` methods --- native/src/layout/node.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'native/src/layout') diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index 777a57fb..11e93b72 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -54,10 +54,9 @@ impl Node { &self.children } - /// Aligns item according to [`Align`] and [`Size`]. - /// - /// [`Align`]: ../enum.Align.html - /// [`Size`]: ../struct.Size.html + /// Aligns the [`Node`] in the given space. + /// + /// [`Node`]: struct.Node.html pub fn align( &mut self, horizontal_alignment: Align, @@ -85,9 +84,9 @@ impl Node { } } - /// Move item to [`Point`]. + /// Moves the [`Node`] to the given position. /// - /// [`Point`]: ../struct.Point.html + /// [`Node`]: struct.Node.html pub fn move_to(&mut self, position: Point) { self.bounds.x = position.x; self.bounds.y = position.y; -- cgit