summaryrefslogtreecommitdiffstats
path: root/native/src/layout/node.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-04 05:37:11 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-04 05:37:11 +0100
commit3a0d34c0240f4421737a6a08761f99d6f8140d02 (patch)
treec9a4a6b8e9c1db1b8fcd05bc98e3f131d5ef4bd5 /native/src/layout/node.rs
parentc54409d1711e1f615c7ea4b02c082954e340632a (diff)
downloadiced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.gz
iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.tar.bz2
iced-3a0d34c0240f4421737a6a08761f99d6f8140d02.zip
Create `iced_widget` subcrate and re-organize the whole codebase
Diffstat (limited to 'native/src/layout/node.rs')
-rw-r--r--native/src/layout/node.rs91
1 files changed, 0 insertions, 91 deletions
diff --git a/native/src/layout/node.rs b/native/src/layout/node.rs
deleted file mode 100644
index e0c7dcb2..00000000
--- a/native/src/layout/node.rs
+++ /dev/null
@@ -1,91 +0,0 @@
-use crate::{Alignment, Point, Rectangle, Size, Vector};
-
-/// The bounds of an element and its children.
-#[derive(Debug, Clone, Default)]
-pub struct Node {
- bounds: Rectangle,
- children: Vec<Node>,
-}
-
-impl Node {
- /// Creates a new [`Node`] with the given [`Size`].
- pub const fn new(size: Size) -> Self {
- Self::with_children(size, Vec::new())
- }
-
- /// Creates a new [`Node`] with the given [`Size`] and children.
- pub const fn with_children(size: Size, children: Vec<Node>) -> Self {
- Node {
- bounds: Rectangle {
- x: 0.0,
- y: 0.0,
- width: size.width,
- height: size.height,
- },
- children,
- }
- }
-
- /// Returns the [`Size`] of the [`Node`].
- pub fn size(&self) -> Size {
- Size::new(self.bounds.width, self.bounds.height)
- }
-
- /// Returns the bounds of the [`Node`].
- pub fn bounds(&self) -> Rectangle {
- self.bounds
- }
-
- /// Returns the children of the [`Node`].
- pub fn children(&self) -> &[Node] {
- &self.children
- }
-
- /// Aligns the [`Node`] in the given space.
- pub fn align(
- &mut self,
- horizontal_alignment: Alignment,
- vertical_alignment: Alignment,
- space: Size,
- ) {
- match horizontal_alignment {
- Alignment::Start => {}
- Alignment::Center => {
- self.bounds.x += (space.width - self.bounds.width) / 2.0;
- }
- Alignment::End => {
- self.bounds.x += space.width - self.bounds.width;
- }
- Alignment::Fill => {
- self.bounds.width = space.width;
- }
- }
-
- match vertical_alignment {
- Alignment::Start => {}
- Alignment::Center => {
- self.bounds.y += (space.height - self.bounds.height) / 2.0;
- }
- Alignment::End => {
- self.bounds.y += space.height - self.bounds.height;
- }
- Alignment::Fill => {
- self.bounds.height = space.height;
- }
- }
- }
-
- /// Moves the [`Node`] to the given position.
- pub fn move_to(&mut self, position: Point) {
- self.bounds.x = position.x;
- self.bounds.y = position.y;
- }
-
- /// Translates the [`Node`] by the given translation.
- pub fn translate(self, translation: Vector) -> Self {
- Self {
- bounds: self.bounds + translation,
- ..self
- }
- }
-}