diff options
| author | 2019-11-10 06:05:20 +0100 | |
|---|---|---|
| committer | 2019-11-11 03:08:00 +0100 | |
| commit | 0240c3981b716c82ecb3364945815335b420a63e (patch) | |
| tree | 441eebaa9441649a4e878bde71cdec20d4a67391 /core | |
| parent | 2303111e09d806ef2a652bddc2b73be6dccf6ae2 (diff) | |
| download | iced-0240c3981b716c82ecb3364945815335b420a63e.tar.gz iced-0240c3981b716c82ecb3364945815335b420a63e.tar.bz2 iced-0240c3981b716c82ecb3364945815335b420a63e.zip | |
Draft custom layout engine based on `druid`
Diffstat (limited to '')
| -rw-r--r-- | core/src/length.rs | 12 | ||||
| -rw-r--r-- | core/src/rectangle.rs | 2 | ||||
| -rw-r--r-- | core/src/widget/column.rs | 14 | ||||
| -rw-r--r-- | core/src/widget/row.rs | 14 | ||||
| -rw-r--r-- | core/src/widget/scrollable.rs | 10 | 
5 files changed, 34 insertions, 18 deletions
| diff --git a/core/src/length.rs b/core/src/length.rs index 0e670038..73c227d8 100644 --- a/core/src/length.rs +++ b/core/src/length.rs @@ -1,7 +1,17 @@  /// The strategy used to fill space in a specific dimension. -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Hash)]  pub enum Length {      Fill,      Shrink,      Units(u16),  } + +impl Length { +    pub fn fill_factor(&self) -> u16 { +        match self { +            Length::Fill => 1, +            Length::Shrink => 0, +            Length::Units(_) => 0, +        } +    } +} diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index c3191677..ee1e3807 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -1,7 +1,7 @@  use crate::Point;  /// A rectangle. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]  pub struct Rectangle<T = f32> {      /// X coordinate of the top-left corner.      pub x: T, diff --git a/core/src/widget/column.rs b/core/src/widget/column.rs index 2df327a0..f0c47f50 100644 --- a/core/src/widget/column.rs +++ b/core/src/widget/column.rs @@ -1,5 +1,7 @@  use crate::{Align, Justify, Length}; +use std::u32; +  /// A container that distributes its contents vertically.  ///  /// A [`Column`] will try to fill the horizontal space of its container. @@ -10,8 +12,8 @@ pub struct Column<Element> {      pub padding: u16,      pub width: Length,      pub height: Length, -    pub max_width: Length, -    pub max_height: Length, +    pub max_width: u32, +    pub max_height: u32,      pub align_self: Option<Align>,      pub align_items: Align,      pub justify_content: Justify, @@ -28,8 +30,8 @@ impl<Element> Column<Element> {              padding: 0,              width: Length::Fill,              height: Length::Shrink, -            max_width: Length::Shrink, -            max_height: Length::Shrink, +            max_width: u32::MAX, +            max_height: u32::MAX,              align_self: None,              align_items: Align::Start,              justify_content: Justify::Start, @@ -74,7 +76,7 @@ impl<Element> Column<Element> {      /// Sets the maximum width of the [`Column`].      ///      /// [`Column`]: struct.Column.html -    pub fn max_width(mut self, max_width: Length) -> Self { +    pub fn max_width(mut self, max_width: u32) -> Self {          self.max_width = max_width;          self      } @@ -82,7 +84,7 @@ impl<Element> Column<Element> {      /// Sets the maximum height of the [`Column`] in pixels.      ///      /// [`Column`]: struct.Column.html -    pub fn max_height(mut self, max_height: Length) -> Self { +    pub fn max_height(mut self, max_height: u32) -> Self {          self.max_height = max_height;          self      } diff --git a/core/src/widget/row.rs b/core/src/widget/row.rs index 6bdb4ed2..10716a7a 100644 --- a/core/src/widget/row.rs +++ b/core/src/widget/row.rs @@ -1,5 +1,7 @@  use crate::{Align, Justify, Length}; +use std::u32; +  /// A container that distributes its contents horizontally.  ///  /// A [`Row`] will try to fill the horizontal space of its container. @@ -10,8 +12,8 @@ pub struct Row<Element> {      pub padding: u16,      pub width: Length,      pub height: Length, -    pub max_width: Length, -    pub max_height: Length, +    pub max_width: u32, +    pub max_height: u32,      pub align_self: Option<Align>,      pub align_items: Align,      pub justify_content: Justify, @@ -28,8 +30,8 @@ impl<Element> Row<Element> {              padding: 0,              width: Length::Fill,              height: Length::Shrink, -            max_width: Length::Shrink, -            max_height: Length::Shrink, +            max_width: u32::MAX, +            max_height: u32::MAX,              align_self: None,              align_items: Align::Start,              justify_content: Justify::Start, @@ -74,7 +76,7 @@ impl<Element> Row<Element> {      /// Sets the maximum width of the [`Row`].      ///      /// [`Row`]: struct.Row.html -    pub fn max_width(mut self, max_width: Length) -> Self { +    pub fn max_width(mut self, max_width: u32) -> Self {          self.max_width = max_width;          self      } @@ -82,7 +84,7 @@ impl<Element> Row<Element> {      /// Sets the maximum height of the [`Row`].      ///      /// [`Row`]: struct.Row.html -    pub fn max_height(mut self, max_height: Length) -> Self { +    pub fn max_height(mut self, max_height: u32) -> Self {          self.max_height = max_height;          self      } diff --git a/core/src/widget/scrollable.rs b/core/src/widget/scrollable.rs index 31a5abed..c5a2fc59 100644 --- a/core/src/widget/scrollable.rs +++ b/core/src/widget/scrollable.rs @@ -1,10 +1,12 @@  use crate::{Align, Column, Length, Point, Rectangle}; +use std::u32; +  #[derive(Debug)]  pub struct Scrollable<'a, Element> {      pub state: &'a mut State,      pub height: Length, -    pub max_height: Length, +    pub max_height: u32,      pub align_self: Option<Align>,      pub content: Column<Element>,  } @@ -14,7 +16,7 @@ impl<'a, Element> Scrollable<'a, Element> {          Scrollable {              state,              height: Length::Shrink, -            max_height: Length::Shrink, +            max_height: u32::MAX,              align_self: None,              content: Column::new(),          } @@ -57,7 +59,7 @@ impl<'a, Element> Scrollable<'a, Element> {      /// Sets the maximum width of the [`Scrollable`].      ///      /// [`Scrollable`]: struct.Scrollable.html -    pub fn max_width(mut self, max_width: Length) -> Self { +    pub fn max_width(mut self, max_width: u32) -> Self {          self.content = self.content.max_width(max_width);          self      } @@ -65,7 +67,7 @@ impl<'a, Element> Scrollable<'a, Element> {      /// Sets the maximum height of the [`Scrollable`] in pixels.      ///      /// [`Scrollable`]: struct.Scrollable.html -    pub fn max_height(mut self, max_height: Length) -> Self { +    pub fn max_height(mut self, max_height: u32) -> Self {          self.max_height = max_height;          self      } | 
