Refactor alignment types into an alignment module
This commit is contained in:
parent
5fae6e59ff
commit
a0ad399622
54 changed files with 402 additions and 377 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
||||
(
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue