diff options
| author | 2021-09-20 15:09:55 +0700 | |
|---|---|---|
| committer | 2021-09-20 15:14:08 +0700 | |
| commit | a0ad3996225601aaa1ebe051cba115374b55c80e (patch) | |
| tree | 8420a91cd319a63b1ed257a6334453a1a673bdfb /graphics/src | |
| parent | 5fae6e59ffbc5913761df638dc7f0c35b7f43bc9 (diff) | |
| download | iced-a0ad3996225601aaa1ebe051cba115374b55c80e.tar.gz iced-a0ad3996225601aaa1ebe051cba115374b55c80e.tar.bz2 iced-a0ad3996225601aaa1ebe051cba115374b55c80e.zip | |
Refactor alignment types into an `alignment` module
Diffstat (limited to '')
| -rw-r--r-- | graphics/src/layer.rs | 12 | ||||
| -rw-r--r-- | graphics/src/lib.rs | 4 | ||||
| -rw-r--r-- | graphics/src/overlay/menu.rs | 11 | ||||
| -rw-r--r-- | graphics/src/primitive.rs | 9 | ||||
| -rw-r--r-- | graphics/src/widget/canvas/text.rs | 11 | ||||
| -rw-r--r-- | graphics/src/widget/checkbox.rs | 9 | ||||
| -rw-r--r-- | graphics/src/widget/pick_list.rs | 15 | ||||
| -rw-r--r-- | graphics/src/widget/text.rs | 21 | ||||
| -rw-r--r-- | graphics/src/widget/text_input.rs | 15 | 
9 files changed, 54 insertions, 53 deletions
| diff --git a/graphics/src/layer.rs b/graphics/src/layer.rs index 7dce1d4c..9653a2e4 100644 --- a/graphics/src/layer.rs +++ b/graphics/src/layer.rs @@ -1,10 +1,10 @@  //! Organize rendering primitives into a flattened list of layers. +use crate::alignment;  use crate::image;  use crate::svg;  use crate::triangle;  use crate::{ -    Background, Font, HorizontalAlignment, Point, Primitive, Rectangle, Size, -    Vector, VerticalAlignment, Viewport, +    Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,  };  /// A group of primitives that should be clipped together. @@ -55,8 +55,8 @@ impl<'a> Layer<'a> {                  color: [0.9, 0.9, 0.9, 1.0],                  size: 20.0,                  font: Font::Default, -                horizontal_alignment: HorizontalAlignment::Left, -                vertical_alignment: VerticalAlignment::Top, +                horizontal_alignment: alignment::Horizontal::Left, +                vertical_alignment: alignment::Vertical::Top,              };              overlay.text.push(text); @@ -293,10 +293,10 @@ pub struct Text<'a> {      pub font: Font,      /// The horizontal alignment of the [`Text`]. -    pub horizontal_alignment: HorizontalAlignment, +    pub horizontal_alignment: alignment::Horizontal,      /// The vertical alignment of the [`Text`]. -    pub vertical_alignment: VerticalAlignment, +    pub vertical_alignment: alignment::Vertical,  }  /// A raster or vector image. diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 14388653..54cdcb77 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -39,7 +39,7 @@ pub use renderer::Renderer;  pub use transformation::Transformation;  pub use viewport::Viewport; +pub use iced_native::alignment;  pub use iced_native::{ -    Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size, -    Vector, VerticalAlignment, +    Alignment, Background, Color, Font, Point, Rectangle, Size, Vector,  }; diff --git a/graphics/src/overlay/menu.rs b/graphics/src/overlay/menu.rs index 9e91a0ef..53f47984 100644 --- a/graphics/src/overlay/menu.rs +++ b/graphics/src/overlay/menu.rs @@ -1,10 +1,9 @@  //! Build and show dropdown menus. +use crate::alignment;  use crate::backend::{self, Backend};  use crate::{Primitive, Renderer}; -use iced_native::{ -    mouse, overlay, Color, Font, HorizontalAlignment, Padding, Point, -    Rectangle, VerticalAlignment, -}; + +use iced_native::{mouse, overlay, Color, Font, Padding, Point, Rectangle};  pub use iced_style::menu::Style; @@ -100,8 +99,8 @@ where                  } else {                      style.text_color                  }, -                horizontal_alignment: HorizontalAlignment::Left, -                vertical_alignment: VerticalAlignment::Center, +                horizontal_alignment: alignment::Horizontal::Left, +                vertical_alignment: alignment::Vertical::Center,              });          } diff --git a/graphics/src/primitive.rs b/graphics/src/primitive.rs index 30263bd4..32f8383d 100644 --- a/graphics/src/primitive.rs +++ b/graphics/src/primitive.rs @@ -1,9 +1,10 @@  use iced_native::{ -    image, svg, Background, Color, Font, HorizontalAlignment, Rectangle, Size, -    Vector, VerticalAlignment, +    image, svg, Background, Color, Font, Rectangle, Size, Vector,  }; +use crate::alignment;  use crate::triangle; +  use std::sync::Arc;  /// A rendering primitive. @@ -29,9 +30,9 @@ pub enum Primitive {          /// The font of the text          font: Font,          /// The horizontal alignment of the text -        horizontal_alignment: HorizontalAlignment, +        horizontal_alignment: alignment::Horizontal,          /// The vertical alignment of the text -        vertical_alignment: VerticalAlignment, +        vertical_alignment: alignment::Vertical,      },      /// A quad primitive      Quad { diff --git a/graphics/src/widget/canvas/text.rs b/graphics/src/widget/canvas/text.rs index c4cae30e..ab070a70 100644 --- a/graphics/src/widget/canvas/text.rs +++ b/graphics/src/widget/canvas/text.rs @@ -1,4 +1,5 @@ -use iced_native::{Color, Font, HorizontalAlignment, Point, VerticalAlignment}; +use crate::alignment; +use crate::{Color, Font, Point};  /// A bunch of text that can be drawn to a canvas  #[derive(Debug, Clone)] @@ -14,9 +15,9 @@ pub struct Text {      /// The font of the text      pub font: Font,      /// The horizontal alignment of the text -    pub horizontal_alignment: HorizontalAlignment, +    pub horizontal_alignment: alignment::Horizontal,      /// The vertical alignment of the text -    pub vertical_alignment: VerticalAlignment, +    pub vertical_alignment: alignment::Vertical,  }  impl Default for Text { @@ -27,8 +28,8 @@ impl Default for Text {              color: Color::BLACK,              size: 16.0,              font: Font::Default, -            horizontal_alignment: HorizontalAlignment::Left, -            vertical_alignment: VerticalAlignment::Top, +            horizontal_alignment: alignment::Horizontal::Left, +            vertical_alignment: alignment::Vertical::Top,          }      }  } diff --git a/graphics/src/widget/checkbox.rs b/graphics/src/widget/checkbox.rs index cb7fd2cf..620bfc9e 100644 --- a/graphics/src/widget/checkbox.rs +++ b/graphics/src/widget/checkbox.rs @@ -1,9 +1,10 @@  //! Show toggle controls using checkboxes. +use crate::alignment;  use crate::backend::{self, Backend}; -use crate::{Primitive, Renderer}; +use crate::{Primitive, Rectangle, Renderer}; +  use iced_native::checkbox;  use iced_native::mouse; -use iced_native::{HorizontalAlignment, Rectangle, VerticalAlignment};  pub use iced_style::checkbox::{Style, StyleSheet}; @@ -57,8 +58,8 @@ where                              ..bounds                          },                          color: style.checkmark_color, -                        horizontal_alignment: HorizontalAlignment::Center, -                        vertical_alignment: VerticalAlignment::Center, +                        horizontal_alignment: alignment::Horizontal::Center, +                        vertical_alignment: alignment::Vertical::Center,                      };                      vec![checkbox, check, label] diff --git a/graphics/src/widget/pick_list.rs b/graphics/src/widget/pick_list.rs index 88a590b5..532840b8 100644 --- a/graphics/src/widget/pick_list.rs +++ b/graphics/src/widget/pick_list.rs @@ -1,10 +1,9 @@  //! Display a dropdown list of selectable values. +use crate::alignment;  use crate::backend::{self, Backend};  use crate::{Primitive, Renderer}; -use iced_native::{ -    mouse, Font, HorizontalAlignment, Padding, Point, Rectangle, -    VerticalAlignment, -}; + +use iced_native::{mouse, Font, Padding, Point, Rectangle};  use iced_style::menu;  pub use iced_native::pick_list::State; @@ -64,8 +63,8 @@ where                  ..bounds              },              color: style.text_color, -            horizontal_alignment: HorizontalAlignment::Right, -            vertical_alignment: VerticalAlignment::Center, +            horizontal_alignment: alignment::Horizontal::Right, +            vertical_alignment: alignment::Vertical::Center,          };          ( @@ -85,8 +84,8 @@ where                              y: bounds.center_y(),                              ..bounds                          }, -                        horizontal_alignment: HorizontalAlignment::Left, -                        vertical_alignment: VerticalAlignment::Center, +                        horizontal_alignment: alignment::Horizontal::Left, +                        vertical_alignment: alignment::Vertical::Center,                      };                      vec![background, label, arrow_down] diff --git a/graphics/src/widget/text.rs b/graphics/src/widget/text.rs index 645c8414..d6d446d3 100644 --- a/graphics/src/widget/text.rs +++ b/graphics/src/widget/text.rs @@ -1,11 +1,10 @@  //! Write some text for your users to read.  use crate::backend::{self, Backend};  use crate::{Primitive, Renderer}; +use iced_native::alignment;  use iced_native::mouse;  use iced_native::text; -use iced_native::{ -    Color, Font, HorizontalAlignment, Point, Rectangle, Size, VerticalAlignment, -}; +use iced_native::{Color, Font, Point, Rectangle, Size};  /// A paragraph of text.  /// @@ -62,19 +61,19 @@ where          size: u16,          font: Font,          color: Option<Color>, -        horizontal_alignment: HorizontalAlignment, -        vertical_alignment: VerticalAlignment, +        horizontal_alignment: alignment::Horizontal, +        vertical_alignment: alignment::Vertical,      ) -> Self::Output {          let x = match horizontal_alignment { -            iced_native::HorizontalAlignment::Left => bounds.x, -            iced_native::HorizontalAlignment::Center => bounds.center_x(), -            iced_native::HorizontalAlignment::Right => bounds.x + bounds.width, +            alignment::Horizontal::Left => bounds.x, +            alignment::Horizontal::Center => bounds.center_x(), +            alignment::Horizontal::Right => bounds.x + bounds.width,          };          let y = match vertical_alignment { -            iced_native::VerticalAlignment::Top => bounds.y, -            iced_native::VerticalAlignment::Center => bounds.center_y(), -            iced_native::VerticalAlignment::Bottom => bounds.y + bounds.height, +            alignment::Vertical::Top => bounds.y, +            alignment::Vertical::Center => bounds.center_y(), +            alignment::Vertical::Bottom => bounds.y + bounds.height,          };          ( diff --git a/graphics/src/widget/text_input.rs b/graphics/src/widget/text_input.rs index c269022b..1516b007 100644 --- a/graphics/src/widget/text_input.rs +++ b/graphics/src/widget/text_input.rs @@ -1,14 +1,15 @@  //! Display fields that can be filled with text.  //!  //! A [`TextInput`] has some local [`State`]. +use crate::alignment;  use crate::backend::{self, Backend}; -use crate::{Primitive, Renderer}; +use crate::{ +    Background, Color, Font, Point, Primitive, Rectangle, Renderer, Size, +    Vector, +}; +  use iced_native::mouse;  use iced_native::text_input::{self, cursor}; -use iced_native::{ -    Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size, -    Vector, VerticalAlignment, -};  use std::f32;  pub use iced_native::text_input::State; @@ -116,8 +117,8 @@ where                  ..text_bounds              },              size: f32::from(size), -            horizontal_alignment: HorizontalAlignment::Left, -            vertical_alignment: VerticalAlignment::Center, +            horizontal_alignment: alignment::Horizontal::Left, +            vertical_alignment: alignment::Vertical::Center,          };          let (contents_primitive, offset) = if state.is_focused() { | 
