From 0240c3981b716c82ecb3364945815335b420a63e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 10 Nov 2019 06:05:20 +0100 Subject: Draft custom layout engine based on `druid` --- native/src/layout/node.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 native/src/layout/node.rs (limited to 'native/src/layout/node.rs') diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs new file mode 100644 index 00000000..7537ad3b --- /dev/null +++ b/native/src/layout/node.rs @@ -0,0 +1,37 @@ +use crate::{Rectangle, Size}; + +#[derive(Debug, Clone, Default)] +pub struct Node { + pub bounds: Rectangle, + children: Vec, +} + +impl Node { + pub fn new(size: Size) -> Self { + Self::with_children(size, Vec::new()) + } + + pub fn with_children(size: Size, children: Vec) -> Self { + Node { + bounds: Rectangle { + x: 0.0, + y: 0.0, + width: size.width, + height: size.height, + }, + children, + } + } + + pub fn size(&self) -> Size { + Size::new(self.bounds.width, self.bounds.height) + } + + pub fn bounds(&self) -> Rectangle { + self.bounds + } + + pub fn children(&self) -> &[Node] { + &self.children + } +} -- cgit From ceb02f4a36769c488c2525db2fb73f092a6c2706 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 11 Nov 2019 05:26:08 +0100 Subject: Implement `Container` widget Remove `align_self` and `justify_content` methods --- native/src/layout/node.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 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 7537ad3b..9d8ad57d 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -1,4 +1,4 @@ -use crate::{Rectangle, Size}; +use crate::{Align, Rectangle, Size}; #[derive(Debug, Clone, Default)] pub struct Node { @@ -34,4 +34,27 @@ impl Node { pub fn children(&self) -> &[Node] { &self.children } + + pub fn align( + &mut self, + horizontal_alignment: Align, + vertical_alignment: Align, + space: Size, + ) { + match horizontal_alignment { + Align::Start => {} + Align::Center => { + self.bounds.x += (space.width - self.bounds.width) / 2.0; + } + Align::End => {} + } + + match vertical_alignment { + Align::Start => {} + Align::Center => { + self.bounds.y += (space.height - self.bounds.height) / 2.0; + } + Align::End => {} + } + } } -- cgit From d4d14b68f47e9527554a728ebbba9b840832626a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 11 Nov 2019 05:37:51 +0100 Subject: Remove `padding` from `Container` for now --- native/src/layout/node.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'native/src/layout/node.rs') diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs index 9d8ad57d..64ebf2d0 100644 --- a/native/src/layout/node.rs +++ b/native/src/layout/node.rs @@ -46,7 +46,9 @@ impl Node { Align::Center => { self.bounds.x += (space.width - self.bounds.width) / 2.0; } - Align::End => {} + Align::End => { + self.bounds.x += space.width - self.bounds.width; + } } match vertical_alignment { @@ -54,7 +56,9 @@ impl Node { Align::Center => { self.bounds.y += (space.height - self.bounds.height) / 2.0; } - Align::End => {} + Align::End => { + self.bounds.y += space.height - self.bounds.height; + } } } } -- cgit