iced-yoda/native/src/layout.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

2019-11-10 01:55:32 +01:00
mod limits;
mod node;
pub mod flex;
2019-11-10 01:55:32 +01:00
pub use limits::Limits;
pub use node::Node;
2019-07-20 19:12:31 +02:00
use crate::{Point, Rectangle, Vector};
#[derive(Debug, Clone, Copy)]
pub struct Layout<'a> {
position: Point,
node: &'a Node,
2019-07-20 19:12:31 +02:00
}
impl<'a> Layout<'a> {
pub(crate) fn new(node: &'a Node) -> Self {
Self::with_offset(Vector::new(0.0, 0.0), node)
}
pub(crate) fn with_offset(offset: Vector, node: &'a Node) -> Self {
let bounds = node.bounds();
2019-07-20 19:12:31 +02:00
Self {
position: Point::new(bounds.x, bounds.y) + offset,
node,
}
2019-07-20 19:12:31 +02:00
}
pub fn bounds(&self) -> Rectangle {
let bounds = self.node.bounds();
Rectangle {
x: self.position.x,
y: self.position.y,
width: bounds.width,
height: bounds.height,
}
2019-07-20 19:12:31 +02:00
}
pub fn children(&'a self) -> impl Iterator<Item = Layout<'a>> {
self.node.children().iter().map(move |node| {
Layout::with_offset(
Vector::new(self.position.x, self.position.y),
node,
)
})
2019-07-20 19:12:31 +02:00
}
}