Refactor alignment types into an alignment module

This commit is contained in:
Héctor Ramón Jiménez 2021-09-20 15:09:55 +07:00
parent 5fae6e59ff
commit a0ad399622
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
54 changed files with 402 additions and 377 deletions

View file

@ -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,
}
}
}

View file

@ -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]

View file

@ -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]

View file

@ -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,
};
(

View file

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