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,64 +0,0 @@
/// Alignment on an axis of a container.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Align {
/// Align at the start of the axis.
Start,
/// Align at the center of the axis.
Center,
/// Align at the end of the axis.
End,
}
/// Alignment on the cross axis of a container.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CrossAlign {
/// Align at the start of the axis.
Start,
/// Align at the center of the axis.
Center,
/// Align at the end of the axis.
End,
/// Fill the entire axis.
Fill,
}
impl From<Align> for CrossAlign {
fn from(align: Align) -> Self {
match align {
Align::Start => Self::Start,
Align::Center => Self::Center,
Align::End => Self::End,
}
}
}
/// The horizontal alignment of some resource.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HorizontalAlignment {
/// Align left
Left,
/// Horizontally centered
Center,
/// Align right
Right,
}
/// The vertical alignment of some resource.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VerticalAlignment {
/// Align top
Top,
/// Vertically centered
Center,
/// Align bottom
Bottom,
}

63
core/src/alignment.rs Normal file
View file

@ -0,0 +1,63 @@
//! Align and position widgets.
/// Alignment on the axis of a container.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Alignment {
/// Align at the start of the axis.
Start,
/// Align at the center of the axis.
Center,
/// Align at the end of the axis.
End,
/// Fill the entire axis.
Fill,
}
impl From<Horizontal> for Alignment {
fn from(horizontal: Horizontal) -> Self {
match horizontal {
Horizontal::Left => Self::Start,
Horizontal::Center => Self::Center,
Horizontal::Right => Self::End,
}
}
}
impl From<Vertical> for Alignment {
fn from(vertical: Vertical) -> Self {
match vertical {
Vertical::Top => Self::Start,
Vertical::Center => Self::Center,
Vertical::Bottom => Self::End,
}
}
}
/// The horizontal [`Alignment`] of some resource.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Horizontal {
/// Align left
Left,
/// Horizontally centered
Center,
/// Align right
Right,
}
/// The vertical [`Alignment`] of some resource.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Vertical {
/// Align top
Top,
/// Vertically centered
Center,
/// Align bottom
Bottom,
}

View file

@ -14,11 +14,11 @@
#![deny(unused_results)] #![deny(unused_results)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![forbid(rust_2018_idioms)] #![forbid(rust_2018_idioms)]
pub mod alignment;
pub mod keyboard; pub mod keyboard;
pub mod mouse; pub mod mouse;
pub mod text; pub mod text;
mod align;
mod background; mod background;
mod color; mod color;
mod font; mod font;
@ -29,7 +29,7 @@ mod rectangle;
mod size; mod size;
mod vector; mod vector;
pub use align::{Align, CrossAlign, HorizontalAlignment, VerticalAlignment}; pub use alignment::Alignment;
pub use background::Background; pub use background::Background;
pub use color::Color; pub use color::Color;
pub use font::Font; pub use font::Font;

View file

@ -1,7 +1,6 @@
//! This example showcases an interactive `Canvas` for drawing Bézier curves. //! This example showcases an interactive `Canvas` for drawing Bézier curves.
use iced::{ use iced::{
button, Button, Column, CrossAlign, Element, Length, Sandbox, Settings, button, Alignment, Button, Column, Element, Length, Sandbox, Settings, Text,
Text,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -52,7 +51,7 @@ impl Sandbox for Example {
Column::new() Column::new()
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push( .push(
Text::new("Bezier tool example") Text::new("Bezier tool example")
.width(Length::Shrink) .width(Length::Shrink)

View file

@ -1,8 +1,7 @@
use iced::canvas::{self, Cursor, Frame, Geometry, Path}; use iced::canvas::{self, Cursor, Frame, Geometry, Path};
use iced::{ use iced::{
slider, Canvas, Color, Column, CrossAlign, Element, HorizontalAlignment, alignment, slider, Alignment, Canvas, Color, Column, Element, Length,
Length, Point, Rectangle, Row, Sandbox, Settings, Size, Slider, Text, Point, Rectangle, Row, Sandbox, Settings, Size, Slider, Text, Vector,
Vector, VerticalAlignment,
}; };
use palette::{self, Hsl, Limited, Srgb}; use palette::{self, Hsl, Limited, Srgb};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -163,8 +162,8 @@ impl Theme {
}); });
let mut text = canvas::Text { let mut text = canvas::Text {
horizontal_alignment: HorizontalAlignment::Center, horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: VerticalAlignment::Top, vertical_alignment: alignment::Vertical::Top,
size: 15.0, size: 15.0,
..canvas::Text::default() ..canvas::Text::default()
}; };
@ -206,7 +205,7 @@ impl Theme {
}); });
} }
text.vertical_alignment = VerticalAlignment::Bottom; text.vertical_alignment = alignment::Vertical::Bottom;
let hsl = Hsl::from(Srgb::from(self.base)); let hsl = Hsl::from(Srgb::from(self.base));
for i in 0..self.len() { for i in 0..self.len() {
@ -298,7 +297,7 @@ impl<C: 'static + ColorSpace + Copy> ColorPicker<C> {
Row::new() Row::new()
.spacing(10) .spacing(10)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(Text::new(C::LABEL).width(Length::Units(50))) .push(Text::new(C::LABEL).width(Length::Units(50)))
.push(slider(s1, cr1, c1, move |v| C::new(v, c2, c3))) .push(slider(s1, cr1, c1, move |v| C::new(v, c2, c3)))
.push(slider(s2, cr2, c2, move |v| C::new(c1, v, c3))) .push(slider(s2, cr2, c2, move |v| C::new(c1, v, c3)))

View file

@ -1,5 +1,5 @@
use iced::{ use iced::{
button, Button, Column, CrossAlign, Element, Sandbox, Settings, Text, button, Alignment, Button, Column, Element, Sandbox, Settings, Text,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -44,7 +44,7 @@ impl Sandbox for Counter {
fn view(&mut self) -> Element<Message> { fn view(&mut self) -> Element<Message> {
Column::new() Column::new()
.padding(20) .padding(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push( .push(
Button::new(&mut self.increment_button, Text::new("Increment")) Button::new(&mut self.increment_button, Text::new("Increment"))
.on_press(Message::IncrementPressed), .on_press(Message::IncrementPressed),

View file

@ -84,7 +84,7 @@ mod circle {
use circle::Circle; use circle::Circle;
use iced::{ use iced::{
slider, Column, Container, CrossAlign, Element, Length, Sandbox, Settings, slider, Alignment, Column, Container, Element, Length, Sandbox, Settings,
Slider, Text, Slider, Text,
}; };
@ -129,7 +129,7 @@ impl Sandbox for Example {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.max_width(500) .max_width(500)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(Circle::new(self.radius)) .push(Circle::new(self.radius))
.push(Text::new(format!("Radius: {:.2}", self.radius))) .push(Text::new(format!("Radius: {:.2}", self.radius)))
.push( .push(

View file

@ -1,6 +1,6 @@
use iced::{ use iced::{
button, executor, Application, Button, Column, Command, Container, button, executor, Alignment, Application, Button, Column, Command,
CrossAlign, Element, Length, ProgressBar, Settings, Subscription, Text, Container, Element, Length, ProgressBar, Settings, Subscription, Text,
}; };
mod download; mod download;
@ -83,7 +83,7 @@ impl Application for Example {
.on_press(Message::Add) .on_press(Message::Add)
.padding(10), .padding(10),
) )
.align_items(CrossAlign::End); .align_items(Alignment::End);
Container::new(downloads) Container::new(downloads)
.width(Length::Fill) .width(Length::Fill)
@ -182,7 +182,7 @@ impl Download {
} }
State::Finished { button } => Column::new() State::Finished { button } => Column::new()
.spacing(10) .spacing(10)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(Text::new("Download finished!")) .push(Text::new("Download finished!"))
.push( .push(
Button::new(button, Text::new("Start again")) Button::new(button, Text::new("Start again"))
@ -195,7 +195,7 @@ impl Download {
} }
State::Errored { button } => Column::new() State::Errored { button } => Column::new()
.spacing(10) .spacing(10)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(Text::new("Something went wrong :(")) .push(Text::new("Something went wrong :("))
.push( .push(
Button::new(button, Text::new("Try again")) Button::new(button, Text::new("Try again"))
@ -207,7 +207,7 @@ impl Download {
Column::new() Column::new()
.spacing(10) .spacing(10)
.padding(10) .padding(10)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(progress_bar) .push(progress_bar)
.push(control) .push(control)
.into() .into()

View file

@ -1,7 +1,6 @@
use iced::{ use iced::{
button, executor, Application, Button, Checkbox, Column, Command, alignment, button, executor, Alignment, Application, Button, Checkbox,
Container, CrossAlign, Element, HorizontalAlignment, Length, Settings, Column, Command, Container, Element, Length, Settings, Subscription, Text,
Subscription, Text,
}; };
use iced_native::{window, Event}; use iced_native::{window, Event};
@ -91,14 +90,14 @@ impl Application for Events {
&mut self.exit, &mut self.exit,
Text::new("Exit") Text::new("Exit")
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
.width(Length::Units(100)) .width(Length::Units(100))
.padding(10) .padding(10)
.on_press(Message::Exit); .on_press(Message::Exit);
let content = Column::new() let content = Column::new()
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(20) .spacing(20)
.push(events) .push(events)
.push(toggle) .push(toggle)

View file

@ -11,7 +11,7 @@ use iced::slider::{self, Slider};
use iced::time; use iced::time;
use iced::window; use iced::window;
use iced::{ use iced::{
Application, Checkbox, Column, Command, Container, CrossAlign, Element, Alignment, Application, Checkbox, Column, Command, Container, Element,
Length, Row, Settings, Subscription, Text, Length, Row, Settings, Subscription, Text,
}; };
use preset::Preset; use preset::Preset;
@ -158,10 +158,10 @@ impl Application for GameOfLife {
mod grid { mod grid {
use crate::Preset; use crate::Preset;
use iced::{ use iced::{
alignment,
canvas::event::{self, Event}, canvas::event::{self, Event},
canvas::{self, Cache, Canvas, Cursor, Frame, Geometry, Path, Text}, canvas::{self, Cache, Canvas, Cursor, Frame, Geometry, Path, Text},
mouse, Color, Element, HorizontalAlignment, Length, Point, Rectangle, mouse, Color, Element, Length, Point, Rectangle, Size, Vector,
Size, Vector, VerticalAlignment,
}; };
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use std::future::Future; use std::future::Future;
@ -498,8 +498,8 @@ mod grid {
color: Color::WHITE, color: Color::WHITE,
size: 14.0, size: 14.0,
position: Point::new(frame.width(), frame.height()), position: Point::new(frame.width(), frame.height()),
horizontal_alignment: HorizontalAlignment::Right, horizontal_alignment: alignment::Horizontal::Right,
vertical_alignment: VerticalAlignment::Bottom, vertical_alignment: alignment::Vertical::Bottom,
..Text::default() ..Text::default()
}; };
@ -844,7 +844,7 @@ impl Controls {
let speed_controls = Row::new() let speed_controls = Row::new()
.width(Length::Fill) .width(Length::Fill)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(10) .spacing(10)
.push( .push(
Slider::new( Slider::new(
@ -860,7 +860,7 @@ impl Controls {
Row::new() Row::new()
.padding(10) .padding(10)
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(playback_controls) .push(playback_controls)
.push(speed_controls) .push(speed_controls)
.push( .push(

View file

@ -161,7 +161,7 @@ mod rainbow {
} }
use iced::{ use iced::{
scrollable, Column, Container, CrossAlign, Element, Length, Sandbox, scrollable, Alignment, Column, Container, Element, Length, Sandbox,
Scrollable, Settings, Text, Scrollable, Settings, Text,
}; };
use rainbow::Rainbow; use rainbow::Rainbow;
@ -194,7 +194,7 @@ impl Sandbox for Example {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.max_width(500) .max_width(500)
.align_items(CrossAlign::Start) .align_items(Alignment::Start)
.push(Rainbow::new()) .push(Rainbow::new())
.push(Text::new( .push(Text::new(
"In this example we draw a custom widget Rainbow, using \ "In this example we draw a custom widget Rainbow, using \

View file

@ -1,7 +1,8 @@
use iced_glow::Renderer; use iced_glow::Renderer;
use iced_glutin::slider;
use iced_glutin::{ use iced_glutin::{
slider, Color, Column, Command, CrossAlign, Element, Length, Program, Row, Alignment, Color, Column, Command, Element, Length, Program, Row, Slider,
Slider, Text, Text,
}; };
pub struct Controls { pub struct Controls {
@ -79,11 +80,11 @@ impl Program for Controls {
Row::new() Row::new()
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push( .push(
Column::new() Column::new()
.width(Length::Fill) .width(Length::Fill)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push( .push(
Column::new() Column::new()
.padding(10) .padding(10)

View file

@ -1,6 +1,6 @@
use iced_wgpu::Renderer; use iced_wgpu::Renderer;
use iced_winit::{ use iced_winit::{
slider, Color, Column, Command, CrossAlign, Element, Length, Program, Row, slider, Alignment, Color, Column, Command, Element, Length, Program, Row,
Slider, Text, Slider, Text,
}; };
@ -79,11 +79,11 @@ impl Program for Controls {
Row::new() Row::new()
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push( .push(
Column::new() Column::new()
.width(Length::Fill) .width(Length::Fill)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push( .push(
Column::new() Column::new()
.padding(10) .padding(10)

View file

@ -1,8 +1,7 @@
use iced::{ use iced::{
button, executor, keyboard, pane_grid, scrollable, Application, Button, alignment, button, executor, keyboard, pane_grid, scrollable, Alignment,
Color, Column, Command, Container, CrossAlign, Element, Application, Button, Color, Column, Command, Container, Element, Length,
HorizontalAlignment, Length, PaneGrid, Row, Scrollable, Settings, PaneGrid, Row, Scrollable, Settings, Subscription, Text,
Subscription, Text,
}; };
use iced_native::{event, subscription, Event}; use iced_native::{event, subscription, Event};
@ -293,7 +292,7 @@ impl Content {
state, state,
Text::new(label) Text::new(label)
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center) .horizontal_alignment(alignment::Horizontal::Center)
.size(16), .size(16),
) )
.width(Length::Fill) .width(Length::Fill)
@ -330,7 +329,7 @@ impl Content {
let content = Scrollable::new(scroll) let content = Scrollable::new(scroll)
.width(Length::Fill) .width(Length::Fill)
.spacing(10) .spacing(10)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(controls); .push(controls);
Container::new(content) Container::new(content)

View file

@ -1,5 +1,5 @@
use iced::{ use iced::{
pick_list, scrollable, Container, CrossAlign, Element, Length, PickList, pick_list, scrollable, Alignment, Container, Element, Length, PickList,
Sandbox, Scrollable, Settings, Space, Text, Sandbox, Scrollable, Settings, Space, Text,
}; };
@ -49,7 +49,7 @@ impl Sandbox for Example {
let mut content = Scrollable::new(&mut self.scroll) let mut content = Scrollable::new(&mut self.scroll)
.width(Length::Fill) .width(Length::Fill)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(10) .spacing(10)
.push(Space::with_height(Length::Units(600))) .push(Space::with_height(Length::Units(600)))
.push(Text::new("Which is your favorite language?")) .push(Text::new("Which is your favorite language?"))

View file

@ -1,6 +1,6 @@
use iced::{ use iced::{
button, futures, image, Application, Button, Column, Command, Container, button, futures, image, Alignment, Application, Button, Column, Command,
CrossAlign, Element, Length, Row, Settings, Text, Container, Element, Length, Row, Settings, Text,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -85,14 +85,14 @@ impl Application for Pokedex {
Pokedex::Loaded { pokemon, search } => Column::new() Pokedex::Loaded { pokemon, search } => Column::new()
.max_width(500) .max_width(500)
.spacing(20) .spacing(20)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push(pokemon.view()) .push(pokemon.view())
.push( .push(
button(search, "Keep searching!").on_press(Message::Search), button(search, "Keep searching!").on_press(Message::Search),
), ),
Pokedex::Errored { try_again, .. } => Column::new() Pokedex::Errored { try_again, .. } => Column::new()
.spacing(20) .spacing(20)
.align_items(CrossAlign::End) .align_items(Alignment::End)
.push(Text::new("Whoops! Something went wrong...").size(40)) .push(Text::new("Whoops! Something went wrong...").size(40))
.push(button(try_again, "Try again").on_press(Message::Search)), .push(button(try_again, "Try again").on_press(Message::Search)),
}; };
@ -121,7 +121,7 @@ impl Pokemon {
fn view(&mut self) -> Element<Message> { fn view(&mut self) -> Element<Message> {
Row::new() Row::new()
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(image::Viewer::new( .push(image::Viewer::new(
&mut self.image_viewer, &mut self.image_viewer,
self.image.clone(), self.image.clone(),
@ -131,7 +131,7 @@ impl Pokemon {
.spacing(20) .spacing(20)
.push( .push(
Row::new() Row::new()
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(20) .spacing(20)
.push( .push(
Text::new(&self.name) Text::new(&self.name)

View file

@ -1,7 +1,7 @@
use iced::qr_code::{self, QRCode}; use iced::qr_code::{self, QRCode};
use iced::text_input::{self, TextInput}; use iced::text_input::{self, TextInput};
use iced::{ use iced::{
Column, Container, CrossAlign, Element, Length, Sandbox, Settings, Text, Alignment, Column, Container, Element, Length, Sandbox, Settings, Text,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -62,7 +62,7 @@ impl Sandbox for QRGenerator {
let mut content = Column::new() let mut content = Column::new()
.width(Length::Units(700)) .width(Length::Units(700))
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(title) .push(title)
.push(input); .push(input);

View file

@ -1,7 +1,6 @@
use iced::{ use iced::{
button, executor, time, Application, Button, Column, Command, Container, alignment, button, executor, time, Alignment, Application, Button, Column,
CrossAlign, Element, HorizontalAlignment, Length, Row, Settings, Command, Container, Element, Length, Row, Settings, Subscription, Text,
Subscription, Text,
}; };
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -104,7 +103,7 @@ impl Application for Stopwatch {
Button::new( Button::new(
state, state,
Text::new(label) Text::new(label)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
.min_width(80) .min_width(80)
.padding(10) .padding(10)
@ -130,7 +129,7 @@ impl Application for Stopwatch {
.push(reset_button); .push(reset_button);
let content = Column::new() let content = Column::new()
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(20) .spacing(20)
.push(duration) .push(duration)
.push(controls); .push(controls);

View file

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, scrollable, slider, text_input, Button, Checkbox, Column, button, scrollable, slider, text_input, Alignment, Button, Checkbox,
Container, CrossAlign, Element, Length, ProgressBar, Radio, Row, Rule, Column, Container, Element, Length, ProgressBar, Radio, Row, Rule, Sandbox,
Sandbox, Scrollable, Settings, Slider, Space, Text, TextInput, Toggler, Scrollable, Settings, Slider, Space, Text, TextInput, Toggler,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -132,7 +132,7 @@ impl Sandbox for Styling {
Row::new() Row::new()
.spacing(10) .spacing(10)
.height(Length::Units(100)) .height(Length::Units(100))
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(scrollable) .push(scrollable)
.push(Rule::vertical(38).style(self.theme)) .push(Rule::vertical(38).style(self.theme))
.push( .push(

View file

@ -1,7 +1,10 @@
use iced::alignment::{self, Alignment};
use iced::button::{self, Button};
use iced::scrollable::{self, Scrollable};
use iced::text_input::{self, TextInput};
use iced::{ use iced::{
button, scrollable, text_input, Application, Button, Checkbox, Column, Application, Checkbox, Column, Command, Container, Element, Font, Length,
Command, Container, CrossAlign, Element, Font, HorizontalAlignment, Length, Row, Settings, Text,
Row, Scrollable, Settings, Text, TextInput,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -151,7 +154,7 @@ impl Application for Todos {
.width(Length::Fill) .width(Length::Fill)
.size(100) .size(100)
.color([0.5, 0.5, 0.5]) .color([0.5, 0.5, 0.5])
.horizontal_alignment(HorizontalAlignment::Center); .horizontal_alignment(alignment::Horizontal::Center);
let input = TextInput::new( let input = TextInput::new(
input, input,
@ -295,7 +298,7 @@ impl Task {
Row::new() Row::new()
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(checkbox) .push(checkbox)
.push( .push(
Button::new(edit_button, edit_icon()) Button::new(edit_button, edit_icon())
@ -320,7 +323,7 @@ impl Task {
Row::new() Row::new()
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push(text_input) .push(text_input)
.push( .push(
Button::new( Button::new(
@ -369,7 +372,7 @@ impl Controls {
Row::new() Row::new()
.spacing(20) .spacing(20)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push( .push(
Text::new(&format!( Text::new(&format!(
"{} {} left", "{} {} left",
@ -431,7 +434,7 @@ impl Filter {
fn loading_message<'a>() -> Element<'a, Message> { fn loading_message<'a>() -> Element<'a, Message> {
Container::new( Container::new(
Text::new("Loading...") Text::new("Loading...")
.horizontal_alignment(HorizontalAlignment::Center) .horizontal_alignment(alignment::Horizontal::Center)
.size(50), .size(50),
) )
.width(Length::Fill) .width(Length::Fill)
@ -445,7 +448,7 @@ fn empty_message<'a>(message: &str) -> Element<'a, Message> {
Text::new(message) Text::new(message)
.width(Length::Fill) .width(Length::Fill)
.size(25) .size(25)
.horizontal_alignment(HorizontalAlignment::Center) .horizontal_alignment(alignment::Horizontal::Center)
.color([0.7, 0.7, 0.7]), .color([0.7, 0.7, 0.7]),
) )
.width(Length::Fill) .width(Length::Fill)
@ -464,7 +467,7 @@ fn icon(unicode: char) -> Text {
Text::new(&unicode.to_string()) Text::new(&unicode.to_string())
.font(ICONS) .font(ICONS)
.width(Length::Units(20)) .width(Length::Units(20))
.horizontal_alignment(HorizontalAlignment::Center) .horizontal_alignment(alignment::Horizontal::Center)
.size(20) .size(20)
} }

View file

@ -1,8 +1,7 @@
use iced::tooltip::{self, Tooltip}; use iced::tooltip::{self, Tooltip};
use iced::{ use iced::{
button, Button, Column, Container, CrossAlign, Element, alignment, button, Alignment, Button, Column, Container, Element, Length,
HorizontalAlignment, Length, Row, Sandbox, Settings, Text, Row, Sandbox, Settings, Text,
VerticalAlignment,
}; };
pub fn main() { pub fn main() {
@ -61,7 +60,7 @@ impl Sandbox for Example {
]) ])
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.spacing(50); .spacing(50);
let follow_cursor = tooltip( let follow_cursor = tooltip(
@ -105,8 +104,8 @@ fn tooltip<'a>(
.size(40) .size(40)
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center) .horizontal_alignment(alignment::Horizontal::Center)
.vertical_alignment(VerticalAlignment::Center), .vertical_alignment(alignment::Vertical::Center),
) )
.on_press(Message) .on_press(Message)
.width(Length::Fill) .width(Length::Fill)

View file

@ -1,7 +1,7 @@
use iced::{ use iced::{
button, scrollable, slider, text_input, Button, Checkbox, Color, Column, alignment, button, scrollable, slider, text_input, Button, Checkbox, Color,
Container, Element, HorizontalAlignment, Image, Length, Radio, Row, Column, Container, Element, Image, Length, Radio, Row, Sandbox, Scrollable,
Sandbox, Scrollable, Settings, Slider, Space, Text, TextInput, Toggler, Settings, Slider, Space, Text, TextInput, Toggler,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -419,7 +419,7 @@ impl<'a> Step {
.push( .push(
Text::new(&value.to_string()) Text::new(&value.to_string())
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
} }
@ -466,7 +466,7 @@ impl<'a> Step {
.push( .push(
Text::new(&format!("{} px", spacing)) Text::new(&format!("{} px", spacing))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
); );
Self::container("Rows and columns") Self::container("Rows and columns")
@ -591,7 +591,7 @@ impl<'a> Step {
.push( .push(
Text::new(&format!("Width: {} px", width.to_string())) Text::new(&format!("Width: {} px", width.to_string()))
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
} }
@ -612,7 +612,7 @@ impl<'a> Step {
Text::new("You are halfway there!") Text::new("You are halfway there!")
.width(Length::Fill) .width(Length::Fill)
.size(30) .size(30)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
.push(Column::new().height(Length::Units(4096))) .push(Column::new().height(Length::Units(4096)))
.push(ferris(300)) .push(ferris(300))
@ -620,7 +620,7 @@ impl<'a> Step {
Text::new("You made it!") Text::new("You made it!")
.width(Length::Fill) .width(Length::Fill)
.size(50) .size(50)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
} }
@ -662,7 +662,7 @@ impl<'a> Step {
value value
}) })
.width(Length::Fill) .width(Length::Fill)
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
} }
@ -680,7 +680,7 @@ impl<'a> Step {
Element::new( Element::new(
Text::new("Not available on web yet!") Text::new("Not available on web yet!")
.color([0.7, 0.7, 0.7]) .color([0.7, 0.7, 0.7])
.horizontal_alignment(HorizontalAlignment::Center), .horizontal_alignment(alignment::Horizontal::Center),
) )
} else { } else {
Element::new(Checkbox::new( Element::new(Checkbox::new(
@ -725,7 +725,7 @@ fn button<'a, Message: Clone>(
) -> Button<'a, Message> { ) -> Button<'a, Message> {
Button::new( Button::new(
state, state,
Text::new(label).horizontal_alignment(HorizontalAlignment::Center), Text::new(label).horizontal_alignment(alignment::Horizontal::Center),
) )
.padding(12) .padding(12)
.min_width(100) .min_width(100)

View file

@ -7,8 +7,9 @@ use iced_graphics::backend;
use iced_graphics::font; use iced_graphics::font;
use iced_graphics::Layer; use iced_graphics::Layer;
use iced_graphics::Primitive; use iced_graphics::Primitive;
use iced_native::alignment;
use iced_native::mouse; use iced_native::mouse;
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment}; use iced_native::{Font, Size};
/// A [`glow`] graphics backend for [`iced`]. /// A [`glow`] graphics backend for [`iced`].
/// ///
@ -147,24 +148,24 @@ impl Backend {
}], }],
layout: glow_glyph::Layout::default() layout: glow_glyph::Layout::default()
.h_align(match text.horizontal_alignment { .h_align(match text.horizontal_alignment {
HorizontalAlignment::Left => { alignment::Horizontal::Left => {
glow_glyph::HorizontalAlign::Left glow_glyph::HorizontalAlign::Left
} }
HorizontalAlignment::Center => { alignment::Horizontal::Center => {
glow_glyph::HorizontalAlign::Center glow_glyph::HorizontalAlign::Center
} }
HorizontalAlignment::Right => { alignment::Horizontal::Right => {
glow_glyph::HorizontalAlign::Right glow_glyph::HorizontalAlign::Right
} }
}) })
.v_align(match text.vertical_alignment { .v_align(match text.vertical_alignment {
VerticalAlignment::Top => { alignment::Vertical::Top => {
glow_glyph::VerticalAlign::Top glow_glyph::VerticalAlign::Top
} }
VerticalAlignment::Center => { alignment::Vertical::Center => {
glow_glyph::VerticalAlign::Center glow_glyph::VerticalAlign::Center
} }
VerticalAlignment::Bottom => { alignment::Vertical::Bottom => {
glow_glyph::VerticalAlign::Bottom glow_glyph::VerticalAlign::Bottom
} }
}), }),

View file

@ -29,10 +29,9 @@ pub(crate) use iced_graphics::Transformation;
pub use widget::*; pub use widget::*;
pub use iced_graphics::{Error, Viewport}; pub use iced_graphics::{Error, Viewport};
pub use iced_native::{
Background, Color, Command, HorizontalAlignment, Length, Vector, pub use iced_native::alignment;
VerticalAlignment, pub use iced_native::{Alignment, Background, Color, Command, Length, Vector};
};
/// A [`glow`] graphics renderer for [`iced`]. /// A [`glow`] graphics renderer for [`iced`].
/// ///

View file

@ -1,10 +1,10 @@
//! Organize rendering primitives into a flattened list of layers. //! Organize rendering primitives into a flattened list of layers.
use crate::alignment;
use crate::image; use crate::image;
use crate::svg; use crate::svg;
use crate::triangle; use crate::triangle;
use crate::{ use crate::{
Background, Font, HorizontalAlignment, Point, Primitive, Rectangle, Size, Background, Font, Point, Primitive, Rectangle, Size, Vector, Viewport,
Vector, VerticalAlignment, Viewport,
}; };
/// A group of primitives that should be clipped together. /// 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], color: [0.9, 0.9, 0.9, 1.0],
size: 20.0, size: 20.0,
font: Font::Default, font: Font::Default,
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Top, vertical_alignment: alignment::Vertical::Top,
}; };
overlay.text.push(text); overlay.text.push(text);
@ -293,10 +293,10 @@ pub struct Text<'a> {
pub font: Font, pub font: Font,
/// The horizontal alignment of the [`Text`]. /// The horizontal alignment of the [`Text`].
pub horizontal_alignment: HorizontalAlignment, pub horizontal_alignment: alignment::Horizontal,
/// The vertical alignment of the [`Text`]. /// The vertical alignment of the [`Text`].
pub vertical_alignment: VerticalAlignment, pub vertical_alignment: alignment::Vertical,
} }
/// A raster or vector image. /// A raster or vector image.

View file

@ -39,7 +39,7 @@ pub use renderer::Renderer;
pub use transformation::Transformation; pub use transformation::Transformation;
pub use viewport::Viewport; pub use viewport::Viewport;
pub use iced_native::alignment;
pub use iced_native::{ pub use iced_native::{
Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size, Alignment, Background, Color, Font, Point, Rectangle, Size, Vector,
Vector, VerticalAlignment,
}; };

View file

@ -1,10 +1,9 @@
//! Build and show dropdown menus. //! Build and show dropdown menus.
use crate::alignment;
use crate::backend::{self, Backend}; use crate::backend::{self, Backend};
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{
mouse, overlay, Color, Font, HorizontalAlignment, Padding, Point, use iced_native::{mouse, overlay, Color, Font, Padding, Point, Rectangle};
Rectangle, VerticalAlignment,
};
pub use iced_style::menu::Style; pub use iced_style::menu::Style;
@ -100,8 +99,8 @@ where
} else { } else {
style.text_color style.text_color
}, },
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Center, vertical_alignment: alignment::Vertical::Center,
}); });
} }

View file

@ -1,9 +1,10 @@
use iced_native::{ use iced_native::{
image, svg, Background, Color, Font, HorizontalAlignment, Rectangle, Size, image, svg, Background, Color, Font, Rectangle, Size, Vector,
Vector, VerticalAlignment,
}; };
use crate::alignment;
use crate::triangle; use crate::triangle;
use std::sync::Arc; use std::sync::Arc;
/// A rendering primitive. /// A rendering primitive.
@ -29,9 +30,9 @@ pub enum Primitive {
/// The font of the text /// The font of the text
font: Font, font: Font,
/// The horizontal alignment of the text /// The horizontal alignment of the text
horizontal_alignment: HorizontalAlignment, horizontal_alignment: alignment::Horizontal,
/// The vertical alignment of the text /// The vertical alignment of the text
vertical_alignment: VerticalAlignment, vertical_alignment: alignment::Vertical,
}, },
/// A quad primitive /// A quad primitive
Quad { Quad {

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 /// A bunch of text that can be drawn to a canvas
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -14,9 +15,9 @@ pub struct Text {
/// The font of the text /// The font of the text
pub font: Font, pub font: Font,
/// The horizontal alignment of the text /// The horizontal alignment of the text
pub horizontal_alignment: HorizontalAlignment, pub horizontal_alignment: alignment::Horizontal,
/// The vertical alignment of the text /// The vertical alignment of the text
pub vertical_alignment: VerticalAlignment, pub vertical_alignment: alignment::Vertical,
} }
impl Default for Text { impl Default for Text {
@ -27,8 +28,8 @@ impl Default for Text {
color: Color::BLACK, color: Color::BLACK,
size: 16.0, size: 16.0,
font: Font::Default, font: Font::Default,
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Top, vertical_alignment: alignment::Vertical::Top,
} }
} }
} }

View file

@ -1,9 +1,10 @@
//! Show toggle controls using checkboxes. //! Show toggle controls using checkboxes.
use crate::alignment;
use crate::backend::{self, Backend}; use crate::backend::{self, Backend};
use crate::{Primitive, Renderer}; use crate::{Primitive, Rectangle, Renderer};
use iced_native::checkbox; use iced_native::checkbox;
use iced_native::mouse; use iced_native::mouse;
use iced_native::{HorizontalAlignment, Rectangle, VerticalAlignment};
pub use iced_style::checkbox::{Style, StyleSheet}; pub use iced_style::checkbox::{Style, StyleSheet};
@ -57,8 +58,8 @@ where
..bounds ..bounds
}, },
color: style.checkmark_color, color: style.checkmark_color,
horizontal_alignment: HorizontalAlignment::Center, horizontal_alignment: alignment::Horizontal::Center,
vertical_alignment: VerticalAlignment::Center, vertical_alignment: alignment::Vertical::Center,
}; };
vec![checkbox, check, label] vec![checkbox, check, label]

View file

@ -1,10 +1,9 @@
//! Display a dropdown list of selectable values. //! Display a dropdown list of selectable values.
use crate::alignment;
use crate::backend::{self, Backend}; use crate::backend::{self, Backend};
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::{
mouse, Font, HorizontalAlignment, Padding, Point, Rectangle, use iced_native::{mouse, Font, Padding, Point, Rectangle};
VerticalAlignment,
};
use iced_style::menu; use iced_style::menu;
pub use iced_native::pick_list::State; pub use iced_native::pick_list::State;
@ -64,8 +63,8 @@ where
..bounds ..bounds
}, },
color: style.text_color, color: style.text_color,
horizontal_alignment: HorizontalAlignment::Right, horizontal_alignment: alignment::Horizontal::Right,
vertical_alignment: VerticalAlignment::Center, vertical_alignment: alignment::Vertical::Center,
}; };
( (
@ -85,8 +84,8 @@ where
y: bounds.center_y(), y: bounds.center_y(),
..bounds ..bounds
}, },
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Center, vertical_alignment: alignment::Vertical::Center,
}; };
vec![background, label, arrow_down] vec![background, label, arrow_down]

View file

@ -1,11 +1,10 @@
//! Write some text for your users to read. //! Write some text for your users to read.
use crate::backend::{self, Backend}; use crate::backend::{self, Backend};
use crate::{Primitive, Renderer}; use crate::{Primitive, Renderer};
use iced_native::alignment;
use iced_native::mouse; use iced_native::mouse;
use iced_native::text; use iced_native::text;
use iced_native::{ use iced_native::{Color, Font, Point, Rectangle, Size};
Color, Font, HorizontalAlignment, Point, Rectangle, Size, VerticalAlignment,
};
/// A paragraph of text. /// A paragraph of text.
/// ///
@ -62,19 +61,19 @@ where
size: u16, size: u16,
font: Font, font: Font,
color: Option<Color>, color: Option<Color>,
horizontal_alignment: HorizontalAlignment, horizontal_alignment: alignment::Horizontal,
vertical_alignment: VerticalAlignment, vertical_alignment: alignment::Vertical,
) -> Self::Output { ) -> Self::Output {
let x = match horizontal_alignment { let x = match horizontal_alignment {
iced_native::HorizontalAlignment::Left => bounds.x, alignment::Horizontal::Left => bounds.x,
iced_native::HorizontalAlignment::Center => bounds.center_x(), alignment::Horizontal::Center => bounds.center_x(),
iced_native::HorizontalAlignment::Right => bounds.x + bounds.width, alignment::Horizontal::Right => bounds.x + bounds.width,
}; };
let y = match vertical_alignment { let y = match vertical_alignment {
iced_native::VerticalAlignment::Top => bounds.y, alignment::Vertical::Top => bounds.y,
iced_native::VerticalAlignment::Center => bounds.center_y(), alignment::Vertical::Center => bounds.center_y(),
iced_native::VerticalAlignment::Bottom => bounds.y + bounds.height, alignment::Vertical::Bottom => bounds.y + bounds.height,
}; };
( (

View file

@ -1,14 +1,15 @@
//! Display fields that can be filled with text. //! Display fields that can be filled with text.
//! //!
//! A [`TextInput`] has some local [`State`]. //! A [`TextInput`] has some local [`State`].
use crate::alignment;
use crate::backend::{self, Backend}; 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::mouse;
use iced_native::text_input::{self, cursor}; use iced_native::text_input::{self, cursor};
use iced_native::{
Background, Color, Font, HorizontalAlignment, Point, Rectangle, Size,
Vector, VerticalAlignment,
};
use std::f32; use std::f32;
pub use iced_native::text_input::State; pub use iced_native::text_input::State;
@ -116,8 +117,8 @@ where
..text_bounds ..text_bounds
}, },
size: f32::from(size), size: f32::from(size),
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Center, vertical_alignment: alignment::Vertical::Center,
}; };
let (contents_primitive, offset) = if state.is_focused() { let (contents_primitive, offset) = if state.is_focused() {

View file

@ -16,11 +16,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crate::layout::{Limits, Node};
use crate::{ use crate::{Alignment, Element, Padding, Point, Size};
layout::{Limits, Node},
CrossAlign, Element, Padding, Point, Size,
};
/// The main axis of a flex layout. /// The main axis of a flex layout.
#[derive(Debug)] #[derive(Debug)]
@ -65,7 +62,7 @@ pub fn resolve<Message, Renderer>(
limits: &Limits, limits: &Limits,
padding: Padding, padding: Padding,
spacing: f32, spacing: f32,
align_items: CrossAlign, align_items: Alignment,
items: &[Element<'_, Message, Renderer>], items: &[Element<'_, Message, Renderer>],
) -> Node ) -> Node
where where
@ -82,7 +79,7 @@ where
let mut nodes: Vec<Node> = Vec::with_capacity(items.len()); let mut nodes: Vec<Node> = Vec::with_capacity(items.len());
nodes.resize(items.len(), Node::default()); nodes.resize(items.len(), Node::default());
if align_items == CrossAlign::Fill { if align_items == Alignment::Fill {
let mut fill_cross = axis.cross(limits.min()); let mut fill_cross = axis.cross(limits.min());
items.iter().for_each(|child| { items.iter().for_each(|child| {
@ -116,13 +113,13 @@ where
.fill_factor(); .fill_factor();
if fill_factor == 0 { if fill_factor == 0 {
let (min_width, min_height) = if align_items == CrossAlign::Fill { let (min_width, min_height) = if align_items == Alignment::Fill {
axis.pack(0.0, cross) axis.pack(0.0, cross)
} else { } else {
axis.pack(0.0, 0.0) axis.pack(0.0, 0.0)
}; };
let (max_width, max_height) = if align_items == CrossAlign::Fill { let (max_width, max_height) = if align_items == Alignment::Fill {
axis.pack(available, cross) axis.pack(available, cross)
} else { } else {
axis.pack(available, max_cross) axis.pack(available, max_cross)
@ -138,7 +135,7 @@ where
available -= axis.main(size); available -= axis.main(size);
if align_items != CrossAlign::Fill { if align_items != Alignment::Fill {
cross = cross.max(axis.cross(size)); cross = cross.max(axis.cross(size));
} }
@ -165,13 +162,13 @@ where
max_main max_main
}; };
let (min_width, min_height) = if align_items == CrossAlign::Fill { let (min_width, min_height) = if align_items == Alignment::Fill {
axis.pack(min_main, cross) axis.pack(min_main, cross)
} else { } else {
axis.pack(min_main, axis.cross(limits.min())) axis.pack(min_main, axis.cross(limits.min()))
}; };
let (max_width, max_height) = if align_items == CrossAlign::Fill { let (max_width, max_height) = if align_items == Alignment::Fill {
axis.pack(max_main, cross) axis.pack(max_main, cross)
} else { } else {
axis.pack(max_main, max_cross) axis.pack(max_main, max_cross)
@ -184,7 +181,7 @@ where
let layout = child.layout(renderer, &child_limits); let layout = child.layout(renderer, &child_limits);
if align_items != CrossAlign::Fill { if align_items != Alignment::Fill {
cross = cross.max(axis.cross(layout.size())); cross = cross.max(axis.cross(layout.size()));
} }
@ -207,7 +204,7 @@ where
match axis { match axis {
Axis::Horizontal => { Axis::Horizontal => {
node.align( node.align(
CrossAlign::Start, Alignment::Start,
align_items, align_items,
Size::new(0.0, cross), Size::new(0.0, cross),
); );
@ -215,7 +212,7 @@ where
Axis::Vertical => { Axis::Vertical => {
node.align( node.align(
align_items, align_items,
CrossAlign::Start, Alignment::Start,
Size::new(cross, 0.0), Size::new(cross, 0.0),
); );
} }

View file

@ -1,4 +1,4 @@
use crate::{CrossAlign, Point, Rectangle, Size}; use crate::{Alignment, Point, Rectangle, Size};
/// The bounds of an element and its children. /// The bounds of an element and its children.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
@ -44,32 +44,32 @@ impl Node {
/// Aligns the [`Node`] in the given space. /// Aligns the [`Node`] in the given space.
pub fn align( pub fn align(
&mut self, &mut self,
horizontal_alignment: CrossAlign, horizontal_alignment: Alignment,
vertical_alignment: CrossAlign, vertical_alignment: Alignment,
space: Size, space: Size,
) { ) {
match horizontal_alignment { match horizontal_alignment {
CrossAlign::Start => {} Alignment::Start => {}
CrossAlign::Center => { Alignment::Center => {
self.bounds.x += (space.width - self.bounds.width) / 2.0; self.bounds.x += (space.width - self.bounds.width) / 2.0;
} }
CrossAlign::End => { Alignment::End => {
self.bounds.x += space.width - self.bounds.width; self.bounds.x += space.width - self.bounds.width;
} }
CrossAlign::Fill => { Alignment::Fill => {
self.bounds.width = space.width; self.bounds.width = space.width;
} }
} }
match vertical_alignment { match vertical_alignment {
CrossAlign::Start => {} Alignment::Start => {}
CrossAlign::Center => { Alignment::Center => {
self.bounds.y += (space.height - self.bounds.height) / 2.0; self.bounds.y += (space.height - self.bounds.height) / 2.0;
} }
CrossAlign::End => { Alignment::End => {
self.bounds.y += space.height - self.bounds.height; self.bounds.y += space.height - self.bounds.height;
} }
CrossAlign::Fill => { Alignment::Fill => {
self.bounds.height = space.height; self.bounds.height = space.height;
} }
} }

View file

@ -61,9 +61,10 @@ mod debug;
#[path = "debug/null.rs"] #[path = "debug/null.rs"]
mod debug; mod debug;
pub use iced_core::alignment;
pub use iced_core::{ pub use iced_core::{
Align, Background, Color, CrossAlign, Font, HorizontalAlignment, Length, Alignment, Background, Color, Font, Length, Padding, Point, Rectangle,
Padding, Point, Rectangle, Size, Vector, VerticalAlignment, Size, Vector,
}; };
pub use iced_futures::{executor, futures}; pub use iced_futures::{executor, futures};

View file

@ -1,8 +1,19 @@
use crate::alignment;
use crate::button;
use crate::checkbox;
use crate::column;
use crate::container;
use crate::pane_grid;
use crate::progress_bar;
use crate::radio;
use crate::row;
use crate::scrollable;
use crate::slider;
use crate::text;
use crate::text_input;
use crate::toggler;
use crate::{ use crate::{
button, checkbox, column, container, pane_grid, progress_bar, radio, row, Color, Element, Font, Layout, Padding, Point, Rectangle, Renderer, Size,
scrollable, slider, text, text_input, toggler, Color, Element, Font,
HorizontalAlignment, Layout, Padding, Point, Rectangle, Renderer, Size,
VerticalAlignment,
}; };
/// A renderer that does nothing. /// A renderer that does nothing.
@ -87,8 +98,8 @@ impl text::Renderer for Null {
_size: u16, _size: u16,
_font: Font, _font: Font,
_color: Option<Color>, _color: Option<Color>,
_horizontal_alignment: HorizontalAlignment, _horizontal_alignment: alignment::Horizontal,
_vertical_alignment: VerticalAlignment, _vertical_alignment: alignment::Vertical,
) { ) {
} }
} }

View file

@ -1,6 +1,7 @@
//! Show toggle controls using checkboxes. //! Show toggle controls using checkboxes.
use std::hash::Hash; use std::hash::Hash;
use crate::alignment::{self, Alignment};
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::mouse; use crate::mouse;
@ -8,8 +9,8 @@ use crate::row;
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{ use crate::{
Clipboard, Color, CrossAlign, Element, Hasher, HorizontalAlignment, Layout, Clipboard, Color, Element, Hasher, Layout, Length, Point, Rectangle, Row,
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, Text, Widget,
}; };
/// A box that can be checked. /// A box that can be checked.
@ -138,7 +139,7 @@ where
Row::<(), Renderer>::new() Row::<(), Renderer>::new()
.width(self.width) .width(self.width)
.spacing(self.spacing) .spacing(self.spacing)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push( .push(
Row::new() Row::new()
.width(Length::Units(self.size)) .width(Length::Units(self.size))
@ -202,8 +203,8 @@ where
self.text_size.unwrap_or(renderer.default_size()), self.text_size.unwrap_or(renderer.default_size()),
self.font, self.font,
self.text_color, self.text_color,
HorizontalAlignment::Left, alignment::Horizontal::Left,
VerticalAlignment::Center, alignment::Vertical::Center,
); );
let is_mouse_over = bounds.contains(cursor_position); let is_mouse_over = bounds.contains(cursor_position);

View file

@ -5,7 +5,7 @@ use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{ use crate::{
Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, Point, Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget, Rectangle, Widget,
}; };
@ -20,7 +20,7 @@ pub struct Column<'a, Message, Renderer> {
height: Length, height: Length,
max_width: u32, max_width: u32,
max_height: u32, max_height: u32,
align_items: CrossAlign, align_items: Alignment,
children: Vec<Element<'a, Message, Renderer>>, children: Vec<Element<'a, Message, Renderer>>,
} }
@ -41,7 +41,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
align_items: CrossAlign::Start, align_items: Alignment::Start,
children, children,
} }
} }
@ -87,7 +87,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
} }
/// Sets the horizontal alignment of the contents of the [`Column`] . /// Sets the horizontal alignment of the contents of the [`Column`] .
pub fn align_items(mut self, align: CrossAlign) -> Self { pub fn align_items(mut self, align: Alignment) -> Self {
self.align_items = align; self.align_items = align;
self self
} }

View file

@ -1,12 +1,13 @@
//! Decorate content and apply alignment. //! Decorate content and apply alignment.
use std::hash::Hash; use std::hash::Hash;
use crate::alignment::{self, Alignment};
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{ use crate::{
Align, Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, Clipboard, Element, Hasher, Layout, Length, Padding, Point, Rectangle,
Point, Rectangle, Widget, Widget,
}; };
use std::u32; use std::u32;
@ -21,8 +22,8 @@ pub struct Container<'a, Message, Renderer: self::Renderer> {
height: Length, height: Length,
max_width: u32, max_width: u32,
max_height: u32, max_height: u32,
horizontal_alignment: Align, horizontal_alignment: alignment::Horizontal,
vertical_alignment: Align, vertical_alignment: alignment::Vertical,
style: Renderer::Style, style: Renderer::Style,
content: Element<'a, Message, Renderer>, content: Element<'a, Message, Renderer>,
} }
@ -42,8 +43,8 @@ where
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
horizontal_alignment: Align::Start, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: Align::Start, vertical_alignment: alignment::Vertical::Top,
style: Renderer::Style::default(), style: Renderer::Style::default(),
content: content.into(), content: content.into(),
} }
@ -80,26 +81,26 @@ where
} }
/// Sets the content alignment for the horizontal axis of the [`Container`]. /// Sets the content alignment for the horizontal axis of the [`Container`].
pub fn align_x(mut self, alignment: Align) -> Self { pub fn align_x(mut self, alignment: alignment::Horizontal) -> Self {
self.horizontal_alignment = alignment; self.horizontal_alignment = alignment;
self self
} }
/// Sets the content alignment for the vertical axis of the [`Container`]. /// Sets the content alignment for the vertical axis of the [`Container`].
pub fn align_y(mut self, alignment: Align) -> Self { pub fn align_y(mut self, alignment: alignment::Vertical) -> Self {
self.vertical_alignment = alignment; self.vertical_alignment = alignment;
self self
} }
/// Centers the contents in the horizontal axis of the [`Container`]. /// Centers the contents in the horizontal axis of the [`Container`].
pub fn center_x(mut self) -> Self { pub fn center_x(mut self) -> Self {
self.horizontal_alignment = Align::Center; self.horizontal_alignment = alignment::Horizontal::Center;
self self
} }
/// Centers the contents in the vertical axis of the [`Container`]. /// Centers the contents in the vertical axis of the [`Container`].
pub fn center_y(mut self) -> Self { pub fn center_y(mut self) -> Self {
self.vertical_alignment = Align::Center; self.vertical_alignment = alignment::Vertical::Center;
self self
} }
@ -144,8 +145,8 @@ where
self.padding.top.into(), self.padding.top.into(),
)); ));
content.align( content.align(
CrossAlign::from(self.horizontal_alignment), Alignment::from(self.horizontal_alignment),
CrossAlign::from(self.vertical_alignment), Alignment::from(self.vertical_alignment),
size, size,
); );

View file

@ -1,15 +1,16 @@
//! Create choices using radio buttons. //! Create choices using radio buttons.
use std::hash::Hash; use std::hash::Hash;
use crate::alignment::{self, Alignment};
use crate::event::{self, Event}; use crate::event::{self, Event};
use crate::layout;
use crate::mouse; use crate::mouse;
use crate::row; use crate::row;
use crate::text; use crate::text;
use crate::touch; use crate::touch;
use crate::{layout, Color};
use crate::{ use crate::{
Clipboard, CrossAlign, Element, Hasher, HorizontalAlignment, Layout, Clipboard, Color, Element, Hasher, Layout, Length, Point, Rectangle, Row,
Length, Point, Rectangle, Row, Text, VerticalAlignment, Widget, Text, Widget,
}; };
/// A circular button representing a choice. /// A circular button representing a choice.
@ -153,7 +154,7 @@ where
Row::<(), Renderer>::new() Row::<(), Renderer>::new()
.width(self.width) .width(self.width)
.spacing(self.spacing) .spacing(self.spacing)
.align_items(CrossAlign::Center) .align_items(Alignment::Center)
.push( .push(
Row::new() Row::new()
.width(Length::Units(self.size)) .width(Length::Units(self.size))
@ -214,8 +215,8 @@ where
self.text_size.unwrap_or(renderer.default_size()), self.text_size.unwrap_or(renderer.default_size()),
self.font, self.font,
self.text_color, self.text_color,
HorizontalAlignment::Left, alignment::Horizontal::Left,
VerticalAlignment::Center, alignment::Vertical::Center,
); );
let is_mouse_over = bounds.contains(cursor_position); let is_mouse_over = bounds.contains(cursor_position);

View file

@ -3,7 +3,7 @@ use crate::event::{self, Event};
use crate::layout; use crate::layout;
use crate::overlay; use crate::overlay;
use crate::{ use crate::{
Clipboard, CrossAlign, Element, Hasher, Layout, Length, Padding, Point, Alignment, Clipboard, Element, Hasher, Layout, Length, Padding, Point,
Rectangle, Widget, Rectangle, Widget,
}; };
@ -19,7 +19,7 @@ pub struct Row<'a, Message, Renderer> {
height: Length, height: Length,
max_width: u32, max_width: u32,
max_height: u32, max_height: u32,
align_items: CrossAlign, align_items: Alignment,
children: Vec<Element<'a, Message, Renderer>>, children: Vec<Element<'a, Message, Renderer>>,
} }
@ -40,7 +40,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
align_items: CrossAlign::Start, align_items: Alignment::Start,
children, children,
} }
} }
@ -86,7 +86,7 @@ impl<'a, Message, Renderer> Row<'a, Message, Renderer> {
} }
/// Sets the vertical alignment of the contents of the [`Row`] . /// Sets the vertical alignment of the contents of the [`Row`] .
pub fn align_items(mut self, align: CrossAlign) -> Self { pub fn align_items(mut self, align: Alignment) -> Self {
self.align_items = align; self.align_items = align;
self self
} }

View file

@ -6,7 +6,7 @@ use crate::mouse;
use crate::overlay; use crate::overlay;
use crate::touch; use crate::touch;
use crate::{ use crate::{
Clipboard, Column, CrossAlign, Element, Hasher, Layout, Length, Padding, Alignment, Clipboard, Column, Element, Hasher, Layout, Length, Padding,
Point, Rectangle, Size, Vector, Widget, Point, Rectangle, Size, Vector, Widget,
}; };
@ -84,7 +84,7 @@ impl<'a, Message, Renderer: self::Renderer> Scrollable<'a, Message, Renderer> {
} }
/// Sets the horizontal alignment of the contents of the [`Scrollable`] . /// Sets the horizontal alignment of the contents of the [`Scrollable`] .
pub fn align_items(mut self, align_items: CrossAlign) -> Self { pub fn align_items(mut self, align_items: Alignment) -> Self {
self.content = self.content.align_items(align_items); self.content = self.content.align_items(align_items);
self self
} }

View file

@ -1,7 +1,8 @@
//! Write some text for your users to read. //! Write some text for your users to read.
use crate::alignment;
use crate::layout;
use crate::{ use crate::{
layout, Color, Element, Hasher, HorizontalAlignment, Layout, Length, Point, Color, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
Rectangle, Size, VerticalAlignment, Widget,
}; };
pub use iced_core::text::Hit; pub use iced_core::text::Hit;
@ -29,8 +30,8 @@ pub struct Text<Renderer: self::Renderer> {
font: Renderer::Font, font: Renderer::Font,
width: Length, width: Length,
height: Length, height: Length,
horizontal_alignment: HorizontalAlignment, horizontal_alignment: alignment::Horizontal,
vertical_alignment: VerticalAlignment, vertical_alignment: alignment::Vertical,
} }
impl<Renderer: self::Renderer> Text<Renderer> { impl<Renderer: self::Renderer> Text<Renderer> {
@ -43,8 +44,8 @@ impl<Renderer: self::Renderer> Text<Renderer> {
font: Default::default(), font: Default::default(),
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Top, vertical_alignment: alignment::Vertical::Top,
} }
} }
@ -83,14 +84,17 @@ impl<Renderer: self::Renderer> Text<Renderer> {
/// Sets the [`HorizontalAlignment`] of the [`Text`]. /// Sets the [`HorizontalAlignment`] of the [`Text`].
pub fn horizontal_alignment( pub fn horizontal_alignment(
mut self, mut self,
alignment: HorizontalAlignment, alignment: alignment::Horizontal,
) -> Self { ) -> Self {
self.horizontal_alignment = alignment; self.horizontal_alignment = alignment;
self self
} }
/// Sets the [`VerticalAlignment`] of the [`Text`]. /// Sets the [`VerticalAlignment`] of the [`Text`].
pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self { pub fn vertical_alignment(
mut self,
alignment: alignment::Vertical,
) -> Self {
self.vertical_alignment = alignment; self.vertical_alignment = alignment;
self self
} }
@ -215,8 +219,8 @@ pub trait Renderer: crate::Renderer {
size: u16, size: u16,
font: Self::Font, font: Self::Font,
color: Option<Color>, color: Option<Color>,
horizontal_alignment: HorizontalAlignment, horizontal_alignment: alignment::Horizontal,
vertical_alignment: VerticalAlignment, vertical_alignment: alignment::Vertical,
) -> Self::Output; ) -> Self::Output;
} }

View file

@ -1,10 +1,15 @@
//! Show toggle controls using togglers. //! Show toggle controls using togglers.
use std::hash::Hash; use std::hash::Hash;
use crate::alignment;
use crate::event;
use crate::layout;
use crate::mouse;
use crate::row;
use crate::text;
use crate::{ use crate::{
event, layout, mouse, row, text, Clipboard, CrossAlign, Element, Event, Alignment, Clipboard, Element, Event, Hasher, Layout, Length, Point,
Hasher, HorizontalAlignment, Layout, Length, Point, Rectangle, Row, Text, Rectangle, Row, Text, Widget,
VerticalAlignment, Widget,
}; };
/// A toggler widget /// A toggler widget
@ -30,7 +35,7 @@ pub struct Toggler<Message, Renderer: self::Renderer + text::Renderer> {
width: Length, width: Length,
size: u16, size: u16,
text_size: Option<u16>, text_size: Option<u16>,
text_alignment: HorizontalAlignment, text_alignment: alignment::Horizontal,
spacing: u16, spacing: u16,
font: Renderer::Font, font: Renderer::Font,
style: Renderer::Style, style: Renderer::Style,
@ -62,7 +67,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
width: Length::Fill, width: Length::Fill,
size: <Renderer as self::Renderer>::DEFAULT_SIZE, size: <Renderer as self::Renderer>::DEFAULT_SIZE,
text_size: None, text_size: None,
text_alignment: HorizontalAlignment::Left, text_alignment: alignment::Horizontal::Left,
spacing: 0, spacing: 0,
font: Renderer::Font::default(), font: Renderer::Font::default(),
style: Renderer::Style::default(), style: Renderer::Style::default(),
@ -88,7 +93,7 @@ impl<Message, Renderer: self::Renderer + text::Renderer>
} }
/// Sets the horizontal alignment of the text of the [`Toggler`] /// Sets the horizontal alignment of the text of the [`Toggler`]
pub fn text_alignment(mut self, alignment: HorizontalAlignment) -> Self { pub fn text_alignment(mut self, alignment: alignment::Horizontal) -> Self {
self.text_alignment = alignment; self.text_alignment = alignment;
self self
} }
@ -132,7 +137,7 @@ where
let mut row = Row::<(), Renderer>::new() let mut row = Row::<(), Renderer>::new()
.width(self.width) .width(self.width)
.spacing(self.spacing) .spacing(self.spacing)
.align_items(CrossAlign::Center); .align_items(Alignment::Center);
if let Some(label) = &self.label { if let Some(label) = &self.label {
row = row.push( row = row.push(
@ -202,7 +207,7 @@ where
self.font, self.font,
None, None,
self.text_alignment, self.text_alignment,
VerticalAlignment::Center, alignment::Vertical::Center,
)) ))
} }

View file

@ -245,8 +245,9 @@ pub use result::Result;
pub use sandbox::Sandbox; pub use sandbox::Sandbox;
pub use settings::Settings; pub use settings::Settings;
pub use runtime::alignment;
pub use runtime::futures;
pub use runtime::{ pub use runtime::{
futures, Align, Background, Color, Command, CrossAlign, Font, Alignment, Background, Color, Command, Font, Length, Point, Rectangle,
HorizontalAlignment, Length, Point, Rectangle, Size, Subscription, Vector, Size, Subscription, Vector,
VerticalAlignment,
}; };

View file

@ -1,5 +1,6 @@
//! Style your widgets. //! Style your widgets.
use crate::{bumpalo, Align, Background, Color, CrossAlign, Length, Padding}; use crate::bumpalo;
use crate::{Alignment, Background, Color, Length, Padding};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -195,22 +196,13 @@ pub fn background(background: Background) -> String {
} }
} }
/// Returns the style value for the given [`Align`]. /// Returns the style value for the given [`Alignment`].
pub fn align(align: Align) -> &'static str { pub fn alignment(alignment: Alignment) -> &'static str {
match align { match alignment {
Align::Start => "flex-start", Alignment::Start => "flex-start",
Align::Center => "center", Alignment::Center => "center",
Align::End => "flex-end", Alignment::End => "flex-end",
} Alignment::Fill => "stretch",
}
/// Returns the style value for the given [`CrossAlign`].
pub fn cross_align(align: CrossAlign) -> &'static str {
match align {
CrossAlign::Start => "flex-start",
CrossAlign::Center => "center",
CrossAlign::End => "flex-end",
CrossAlign::Fill => "stretch",
} }
} }

View file

@ -73,14 +73,19 @@ pub use css::Css;
pub use dodrio; pub use dodrio;
pub use element::Element; pub use element::Element;
pub use hasher::Hasher; pub use hasher::Hasher;
pub use iced_core::{
keyboard, mouse, Align, Background, Color, CrossAlign, Font,
HorizontalAlignment, Length, Padding, Point, Rectangle, Size, Vector,
VerticalAlignment,
};
pub use iced_futures::{executor, futures};
pub use subscription::Subscription; pub use subscription::Subscription;
pub use iced_core::alignment;
pub use iced_core::keyboard;
pub use iced_core::mouse;
pub use iced_futures::executor;
pub use iced_futures::futures;
pub use iced_core::{
Alignment, Background, Color, Font, Length, Padding, Point, Rectangle,
Size, Vector,
};
#[doc(no_inline)] #[doc(no_inline)]
pub use widget::*; pub use widget::*;

View file

@ -1,4 +1,5 @@
use crate::{css, Align, Bus, Css, Element, Length, Padding, Widget}; use crate::css;
use crate::{Alignment, Bus, Css, Element, Length, Padding, Widget};
use dodrio::bumpalo; use dodrio::bumpalo;
use std::u32; use std::u32;
@ -14,7 +15,7 @@ pub struct Column<'a, Message> {
height: Length, height: Length,
max_width: u32, max_width: u32,
max_height: u32, max_height: u32,
align_items: Align, align_items: Alignment,
children: Vec<Element<'a, Message>>, children: Vec<Element<'a, Message>>,
} }
@ -33,7 +34,7 @@ impl<'a, Message> Column<'a, Message> {
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
align_items: Align::Start, align_items: Alignment::Start,
children, children,
} }
} }
@ -79,7 +80,7 @@ impl<'a, Message> Column<'a, Message> {
} }
/// Sets the horizontal alignment of the contents of the [`Column`] . /// Sets the horizontal alignment of the contents of the [`Column`] .
pub fn align_items(mut self, align: Align) -> Self { pub fn align_items(mut self, align: Alignment) -> Self {
self.align_items = align; self.align_items = align;
self self
} }
@ -129,7 +130,7 @@ impl<'a, Message> Widget<Message> for Column<'a, Message> {
css::max_length(self.max_width), css::max_length(self.max_width),
css::max_length(self.max_height), css::max_length(self.max_height),
css::padding(self.padding), css::padding(self.padding),
css::align(self.align_items) css::alignment(self.align_items)
).into_bump_str() ).into_bump_str()
) )
.children(children) .children(children)

View file

@ -1,5 +1,8 @@
//! Decorate content and apply alignment. //! Decorate content and apply alignment.
use crate::{bumpalo, css, Align, Bus, Css, Element, Length, Padding, Widget}; use crate::alignment::{self, Alignment};
use crate::bumpalo;
use crate::css;
use crate::{Bus, Css, Element, Length, Padding, Widget};
pub use iced_style::container::{Style, StyleSheet}; pub use iced_style::container::{Style, StyleSheet};
@ -14,8 +17,8 @@ pub struct Container<'a, Message> {
max_width: u32, max_width: u32,
#[allow(dead_code)] #[allow(dead_code)]
max_height: u32, max_height: u32,
horizontal_alignment: Align, horizontal_alignment: alignment::Horizontal,
vertical_alignment: Align, vertical_alignment: alignment::Vertical,
style_sheet: Box<dyn StyleSheet>, style_sheet: Box<dyn StyleSheet>,
content: Element<'a, Message>, content: Element<'a, Message>,
} }
@ -34,8 +37,8 @@ impl<'a, Message> Container<'a, Message> {
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
horizontal_alignment: Align::Start, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: Align::Start, vertical_alignment: alignment::Vertical::Top,
style_sheet: Default::default(), style_sheet: Default::default(),
content: content.into(), content: content.into(),
} }
@ -73,14 +76,14 @@ impl<'a, Message> Container<'a, Message> {
/// Centers the contents in the horizontal axis of the [`Container`]. /// Centers the contents in the horizontal axis of the [`Container`].
pub fn center_x(mut self) -> Self { pub fn center_x(mut self) -> Self {
self.horizontal_alignment = Align::Center; self.horizontal_alignment = alignment::Horizontal::Center;
self self
} }
/// Centers the contents in the vertical axis of the [`Container`]. /// Centers the contents in the vertical axis of the [`Container`].
pub fn center_y(mut self) -> Self { pub fn center_y(mut self) -> Self {
self.vertical_alignment = Align::Center; self.vertical_alignment = alignment::Vertical::Center;
self self
} }
@ -122,8 +125,8 @@ where
css::length(self.height), css::length(self.height),
css::max_length(self.max_width), css::max_length(self.max_width),
css::padding(self.padding), css::padding(self.padding),
css::align(self.horizontal_alignment), css::alignment(Alignment::from(self.horizontal_alignment)),
css::align(self.vertical_alignment), css::alignment(Alignment::from(self.vertical_alignment)),
style.background.map(css::background).unwrap_or(String::from("initial")), style.background.map(css::background).unwrap_or(String::from("initial")),
style.text_color.map(css::color).unwrap_or(String::from("inherit")), style.text_color.map(css::color).unwrap_or(String::from("inherit")),
style.border_width, style.border_width,

View file

@ -1,4 +1,5 @@
use crate::{css, Align, Bus, Css, Element, Length, Padding, Widget}; use crate::css;
use crate::{Alignment, Bus, Css, Element, Length, Padding, Widget};
use dodrio::bumpalo; use dodrio::bumpalo;
use std::u32; use std::u32;
@ -14,7 +15,7 @@ pub struct Row<'a, Message> {
height: Length, height: Length,
max_width: u32, max_width: u32,
max_height: u32, max_height: u32,
align_items: Align, align_items: Alignment,
children: Vec<Element<'a, Message>>, children: Vec<Element<'a, Message>>,
} }
@ -33,7 +34,7 @@ impl<'a, Message> Row<'a, Message> {
height: Length::Shrink, height: Length::Shrink,
max_width: u32::MAX, max_width: u32::MAX,
max_height: u32::MAX, max_height: u32::MAX,
align_items: Align::Start, align_items: Alignment::Start,
children, children,
} }
} }
@ -79,7 +80,7 @@ impl<'a, Message> Row<'a, Message> {
} }
/// Sets the vertical alignment of the contents of the [`Row`] . /// Sets the vertical alignment of the contents of the [`Row`] .
pub fn align_items(mut self, align: Align) -> Self { pub fn align_items(mut self, align: Alignment) -> Self {
self.align_items = align; self.align_items = align;
self self
} }
@ -129,7 +130,7 @@ impl<'a, Message> Widget<Message> for Row<'a, Message> {
css::max_length(self.max_width), css::max_length(self.max_width),
css::max_length(self.max_height), css::max_length(self.max_height),
css::padding(self.padding), css::padding(self.padding),
css::align(self.align_items) css::alignment(self.align_items)
).into_bump_str() ).into_bump_str()
) )
.children(children) .children(children)

View file

@ -1,7 +1,7 @@
//! Navigate an endless amount of content with a scrollbar. //! Navigate an endless amount of content with a scrollbar.
use crate::{ use crate::bumpalo;
bumpalo, css, Align, Bus, Column, Css, Element, Length, Padding, Widget, use crate::css;
}; use crate::{Alignment, Bus, Column, Css, Element, Length, Padding, Widget};
pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet}; pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet};
@ -72,7 +72,7 @@ impl<'a, Message> Scrollable<'a, Message> {
} }
/// Sets the horizontal alignment of the contents of the [`Scrollable`] . /// Sets the horizontal alignment of the contents of the [`Scrollable`] .
pub fn align_items(mut self, align_items: Align) -> Self { pub fn align_items(mut self, align_items: Alignment) -> Self {
self.content = self.content.align_items(align_items); self.content = self.content.align_items(align_items);
self self
} }

View file

@ -1,7 +1,6 @@
use crate::{ use crate::alignment;
css, Bus, Color, Css, Element, Font, HorizontalAlignment, Length, use crate::css;
VerticalAlignment, Widget, use crate::{Bus, Color, Css, Element, Font, Length, Widget};
};
use dodrio::bumpalo; use dodrio::bumpalo;
/// A paragraph of text. /// A paragraph of text.
@ -22,8 +21,8 @@ pub struct Text {
font: Font, font: Font,
width: Length, width: Length,
height: Length, height: Length,
horizontal_alignment: HorizontalAlignment, horizontal_alignment: alignment::Horizontal,
vertical_alignment: VerticalAlignment, vertical_alignment: alignment::Vertical,
} }
impl Text { impl Text {
@ -36,8 +35,8 @@ impl Text {
font: Font::Default, font: Font::Default,
width: Length::Shrink, width: Length::Shrink,
height: Length::Shrink, height: Length::Shrink,
horizontal_alignment: HorizontalAlignment::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: VerticalAlignment::Top, vertical_alignment: alignment::Vertical::Top,
} }
} }
@ -74,14 +73,17 @@ impl Text {
/// Sets the [`HorizontalAlignment`] of the [`Text`]. /// Sets the [`HorizontalAlignment`] of the [`Text`].
pub fn horizontal_alignment( pub fn horizontal_alignment(
mut self, mut self,
alignment: HorizontalAlignment, alignment: alignment::Horizontal,
) -> Self { ) -> Self {
self.horizontal_alignment = alignment; self.horizontal_alignment = alignment;
self self
} }
/// Sets the [`VerticalAlignment`] of the [`Text`]. /// Sets the [`VerticalAlignment`] of the [`Text`].
pub fn vertical_alignment(mut self, alignment: VerticalAlignment) -> Self { pub fn vertical_alignment(
mut self,
alignment: alignment::Vertical,
) -> Self {
self.vertical_alignment = alignment; self.vertical_alignment = alignment;
self self
} }
@ -111,9 +113,9 @@ impl<'a, Message> Widget<Message> for Text {
let height = css::length(self.height); let height = css::length(self.height);
let text_align = match self.horizontal_alignment { let text_align = match self.horizontal_alignment {
HorizontalAlignment::Left => "left", alignment::Horizontal::Left => "left",
HorizontalAlignment::Center => "center", alignment::Horizontal::Center => "center",
HorizontalAlignment::Right => "right", alignment::Horizontal::Right => "right",
}; };
let style = bumpalo::format!( let style = bumpalo::format!(

View file

@ -7,8 +7,9 @@ use iced_graphics::backend;
use iced_graphics::font; use iced_graphics::font;
use iced_graphics::layer::Layer; use iced_graphics::layer::Layer;
use iced_graphics::{Primitive, Viewport}; use iced_graphics::{Primitive, Viewport};
use iced_native::alignment;
use iced_native::mouse; use iced_native::mouse;
use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment}; use iced_native::{Font, Size};
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image_rs", feature = "svg"))]
use crate::image; use crate::image;
@ -207,24 +208,24 @@ impl Backend {
}], }],
layout: wgpu_glyph::Layout::default() layout: wgpu_glyph::Layout::default()
.h_align(match text.horizontal_alignment { .h_align(match text.horizontal_alignment {
HorizontalAlignment::Left => { alignment::Horizontal::Left => {
wgpu_glyph::HorizontalAlign::Left wgpu_glyph::HorizontalAlign::Left
} }
HorizontalAlignment::Center => { alignment::Horizontal::Center => {
wgpu_glyph::HorizontalAlign::Center wgpu_glyph::HorizontalAlign::Center
} }
HorizontalAlignment::Right => { alignment::Horizontal::Right => {
wgpu_glyph::HorizontalAlign::Right wgpu_glyph::HorizontalAlign::Right
} }
}) })
.v_align(match text.vertical_alignment { .v_align(match text.vertical_alignment {
VerticalAlignment::Top => { alignment::Vertical::Top => {
wgpu_glyph::VerticalAlign::Top wgpu_glyph::VerticalAlign::Top
} }
VerticalAlignment::Center => { alignment::Vertical::Center => {
wgpu_glyph::VerticalAlign::Center wgpu_glyph::VerticalAlign::Center
} }
VerticalAlignment::Bottom => { alignment::Vertical::Bottom => {
wgpu_glyph::VerticalAlign::Bottom wgpu_glyph::VerticalAlign::Bottom
} }
}), }),