summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-15 00:50:36 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-15 00:50:36 +0100
commit4969bfdb66cf2b33033cb642423bc326e288e15b (patch)
tree030a56e38af9af6704f1f02ff52997f34e126959
parentf5c80a6d75d5022b175d3562f0965598b6398bd7 (diff)
parentcf53026b51df390d98d37f93259b7b7b0a25c6f8 (diff)
downloadiced-4969bfdb66cf2b33033cb642423bc326e288e15b.tar.gz
iced-4969bfdb66cf2b33033cb642423bc326e288e15b.tar.bz2
iced-4969bfdb66cf2b33033cb642423bc326e288e15b.zip
Merge branch 'master' into feature/canvas
Diffstat (limited to '')
-rw-r--r--native/src/layout/flex.rs5
-rw-r--r--native/src/layout/node.rs17
-rw-r--r--native/src/widget/button.rs4
-rw-r--r--native/src/widget/container.rs16
-rw-r--r--native/src/widget/text_input.rs3
5 files changed, 34 insertions, 11 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;
+ }
}
diff --git a/native/src/widget/button.rs b/native/src/widget/button.rs
index 5b0d3e41..f1d46936 100644
--- a/native/src/widget/button.rs
+++ b/native/src/widget/button.rs
@@ -168,9 +168,7 @@ where
.pad(padding);
let mut content = self.content.layout(renderer, &limits);
-
- content.bounds.x = padding;
- content.bounds.y = padding;
+ content.move_to(Point::new(padding, padding));
let size = limits.resolve(content.size()).pad(padding);
diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs
index 5682fc87..3459a832 100644
--- a/native/src/widget/container.rs
+++ b/native/src/widget/container.rs
@@ -77,6 +77,22 @@ where
self.max_height = max_height;
self
}
+
+ /// Sets the content alignment for the horizontal axis of the [`Container`].
+ ///
+ /// [`Container`]: struct.Container.html
+ pub fn align_x(mut self, alignment: Align) -> Self {
+ self.horizontal_alignment = alignment;
+ self
+ }
+
+ /// Sets the content alignment for the vertical axis of the [`Container`].
+ ///
+ /// [`Container`]: struct.Container.html
+ pub fn align_y(mut self, alignment: Align) -> Self {
+ self.vertical_alignment = alignment;
+ self
+ }
/// Centers the contents in the horizontal axis of the [`Container`].
///
diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs
index 04118755..c068b895 100644
--- a/native/src/widget/text_input.rs
+++ b/native/src/widget/text_input.rs
@@ -184,8 +184,7 @@ where
.height(Length::Units(text_size));
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
- text.bounds.x = padding;
- text.bounds.y = padding;
+ text.move_to(Point::new(padding, padding));
layout::Node::with_children(text.size().pad(padding), vec![text])
}