From a0ad3996225601aaa1ebe051cba115374b55c80e Mon Sep 17 00:00:00 2001
From: Héctor Ramón Jiménez <hector0193@gmail.com>
Date: Mon, 20 Sep 2021 15:09:55 +0700
Subject: Refactor alignment types into an `alignment` module

---
 graphics/src/widget/canvas/text.rs | 11 ++++++-----
 graphics/src/widget/checkbox.rs    |  9 +++++----
 graphics/src/widget/pick_list.rs   | 15 +++++++--------
 graphics/src/widget/text.rs        | 21 ++++++++++-----------
 graphics/src/widget/text_input.rs  | 15 ++++++++-------
 5 files changed, 36 insertions(+), 35 deletions(-)

(limited to 'graphics/src/widget')

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() {
-- 
cgit