Merge branch 'master' into feature/canvas
This commit is contained in:
commit
4969bfdb66
|
@ -18,7 +18,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
use crate::{
|
use crate::{
|
||||||
layout::{Limits, Node},
|
layout::{Limits, Node},
|
||||||
Align, Element, Size,
|
Align, Element, Point, Size,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The main axis of a flex layout.
|
/// The main axis of a flex layout.
|
||||||
|
@ -152,8 +152,7 @@ where
|
||||||
|
|
||||||
let (x, y) = axis.pack(main, padding);
|
let (x, y) = axis.pack(main, padding);
|
||||||
|
|
||||||
node.bounds.x = x;
|
node.move_to(Point::new(x, y));
|
||||||
node.bounds.y = y;
|
|
||||||
|
|
||||||
match axis {
|
match axis {
|
||||||
Axis::Horizontal => {
|
Axis::Horizontal => {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use crate::{Align, Rectangle, Size};
|
use crate::{Align, Point, Rectangle, Size};
|
||||||
|
|
||||||
/// The bounds of an element and its children.
|
/// The bounds of an element and its children.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub(crate) bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
children: Vec<Node>,
|
children: Vec<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,10 @@ impl Node {
|
||||||
&self.children
|
&self.children
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn align(
|
/// Aligns the [`Node`] in the given space.
|
||||||
|
///
|
||||||
|
/// [`Node`]: struct.Node.html
|
||||||
|
pub fn align(
|
||||||
&mut self,
|
&mut self,
|
||||||
horizontal_alignment: Align,
|
horizontal_alignment: Align,
|
||||||
vertical_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,9 +168,7 @@ where
|
||||||
.pad(padding);
|
.pad(padding);
|
||||||
|
|
||||||
let mut content = self.content.layout(renderer, &limits);
|
let mut content = self.content.layout(renderer, &limits);
|
||||||
|
content.move_to(Point::new(padding, padding));
|
||||||
content.bounds.x = padding;
|
|
||||||
content.bounds.y = padding;
|
|
||||||
|
|
||||||
let size = limits.resolve(content.size()).pad(padding);
|
let size = limits.resolve(content.size()).pad(padding);
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,22 @@ where
|
||||||
self
|
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`].
|
/// Centers the contents in the horizontal axis of the [`Container`].
|
||||||
///
|
///
|
||||||
/// [`Container`]: struct.Container.html
|
/// [`Container`]: struct.Container.html
|
||||||
|
|
|
@ -184,8 +184,7 @@ where
|
||||||
.height(Length::Units(text_size));
|
.height(Length::Units(text_size));
|
||||||
|
|
||||||
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
let mut text = layout::Node::new(limits.resolve(Size::ZERO));
|
||||||
text.bounds.x = padding;
|
text.move_to(Point::new(padding, padding));
|
||||||
text.bounds.y = padding;
|
|
||||||
|
|
||||||
layout::Node::with_children(text.size().pad(padding), vec![text])
|
layout::Node::with_children(text.size().pad(padding), vec![text])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue