summaryrefslogtreecommitdiffstats
path: root/native/src/layout
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-02-14 23:34:01 +0100
committerLibravatar GitHub <noreply@github.com>2020-02-14 23:34:01 +0100
commitcf53026b51df390d98d37f93259b7b7b0a25c6f8 (patch)
tree2074c0453d01515163603be8d94b105f46593465 /native/src/layout
parentf79b94111fcc8efef2226456b51778e9ee697d53 (diff)
parent8f83c805b15230a2f35002cfff88d9653ee08690 (diff)
downloadiced-cf53026b51df390d98d37f93259b7b7b0a25c6f8.tar.gz
iced-cf53026b51df390d98d37f93259b7b7b0a25c6f8.tar.bz2
iced-cf53026b51df390d98d37f93259b7b7b0a25c6f8.zip
Merge pull request #187 from daxpedda/pub-node-align
Add `Node::move_to` and make `Node::align` public
Diffstat (limited to 'native/src/layout')
-rw-r--r--native/src/layout/flex.rs5
-rw-r--r--native/src/layout/node.rs17
2 files changed, 16 insertions, 6 deletions
diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs
index bd37b75a..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 => {
diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs
index ed1cd3da..11e93b72 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>,
}
@@ -54,7 +54,10 @@ impl Node {
&self.children
}
- pub(crate) fn align(
+ /// Aligns the [`Node`] in the given space.
+ ///
+ /// [`Node`]: struct.Node.html
+ pub fn align(
&mut self,
horizontal_alignment: Align,
vertical_alignment: Align,
@@ -80,4 +83,12 @@ impl Node {
}
}
}
+
+ /// Moves the [`Node`] to the given position.
+ ///
+ /// [`Node`]: struct.Node.html
+ pub fn move_to(&mut self, position: Point) {
+ self.bounds.x = position.x;
+ self.bounds.y = position.y;
+ }
}