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/node.rs') 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/node.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'native/src/layout/node.rs') 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/node.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'native/src/layout/node.rs') 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/node.rs') 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