Skip to content

Commit

Permalink
Introduce and use CrossAlign enum for Column and Row
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Sep 20, 2021
1 parent 95e4791 commit 5fae6e5
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 115 deletions.
23 changes: 23 additions & 0 deletions core/src/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,34 @@ pub enum Align {

/// 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 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod rectangle;
mod size;
mod vector;

pub use align::{Align, HorizontalAlignment, VerticalAlignment};
pub use align::{Align, CrossAlign, HorizontalAlignment, VerticalAlignment};
pub use background::Background;
pub use color::Color;
pub use font::Font;
Expand Down
5 changes: 3 additions & 2 deletions examples/bezier_tool/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This example showcases an interactive `Canvas` for drawing Bézier curves.
use iced::{
button, Align, Button, Column, Element, Length, Sandbox, Settings, Text,
button, Button, Column, CrossAlign, Element, Length, Sandbox, Settings,
Text,
};

pub fn main() -> iced::Result {
Expand Down Expand Up @@ -51,7 +52,7 @@ impl Sandbox for Example {
Column::new()
.padding(20)
.spacing(20)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(
Text::new("Bezier tool example")
.width(Length::Shrink)
Expand Down
8 changes: 4 additions & 4 deletions examples/color_palette/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use iced::canvas::{self, Cursor, Frame, Geometry, Path};
use iced::{
slider, Align, Canvas, Color, Column, Element, HorizontalAlignment, Length,
Point, Rectangle, Row, Sandbox, Settings, Size, Slider, Text, Vector,
VerticalAlignment,
slider, Canvas, Color, Column, CrossAlign, Element, HorizontalAlignment,
Length, Point, Rectangle, Row, Sandbox, Settings, Size, Slider, Text,
Vector, VerticalAlignment,
};
use palette::{self, Hsl, Limited, Srgb};
use std::marker::PhantomData;
Expand Down Expand Up @@ -298,7 +298,7 @@ impl<C: 'static + ColorSpace + Copy> ColorPicker<C> {

Row::new()
.spacing(10)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(Text::new(C::LABEL).width(Length::Units(50)))
.push(slider(s1, cr1, c1, move |v| C::new(v, c2, c3)))
.push(slider(s2, cr2, c2, move |v| C::new(c1, v, c3)))
Expand Down
6 changes: 4 additions & 2 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use iced::{button, Align, Button, Column, Element, Sandbox, Settings, Text};
use iced::{
button, Button, Column, CrossAlign, Element, Sandbox, Settings, Text,
};

pub fn main() -> iced::Result {
Counter::run(Settings::default())
Expand Down Expand Up @@ -42,7 +44,7 @@ impl Sandbox for Counter {
fn view(&mut self) -> Element<Message> {
Column::new()
.padding(20)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(
Button::new(&mut self.increment_button, Text::new("Increment"))
.on_press(Message::IncrementPressed),
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod circle {

use circle::Circle;
use iced::{
slider, Align, Column, Container, Element, Length, Sandbox, Settings,
slider, Column, Container, CrossAlign, Element, Length, Sandbox, Settings,
Slider, Text,
};

Expand Down Expand Up @@ -129,7 +129,7 @@ impl Sandbox for Example {
.padding(20)
.spacing(20)
.max_width(500)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(Circle::new(self.radius))
.push(Text::new(format!("Radius: {:.2}", self.radius)))
.push(
Expand Down
12 changes: 6 additions & 6 deletions examples/download_progress/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::{
button, executor, Align, Application, Button, Column, Command, Container,
Element, Length, ProgressBar, Settings, Subscription, Text,
button, executor, Application, Button, Column, Command, Container,
CrossAlign, Element, Length, ProgressBar, Settings, Subscription, Text,
};

mod download;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Application for Example {
.on_press(Message::Add)
.padding(10),
)
.align_items(Align::End);
.align_items(CrossAlign::End);

Container::new(downloads)
.width(Length::Fill)
Expand Down Expand Up @@ -182,7 +182,7 @@ impl Download {
}
State::Finished { button } => Column::new()
.spacing(10)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(Text::new("Download finished!"))
.push(
Button::new(button, Text::new("Start again"))
Expand All @@ -195,7 +195,7 @@ impl Download {
}
State::Errored { button } => Column::new()
.spacing(10)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(Text::new("Something went wrong :("))
.push(
Button::new(button, Text::new("Try again"))
Expand All @@ -207,7 +207,7 @@ impl Download {
Column::new()
.spacing(10)
.padding(10)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(progress_bar)
.push(control)
.into()
Expand Down
8 changes: 4 additions & 4 deletions examples/events/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use iced::{
button, executor, Align, Application, Button, Checkbox, Column, Command,
Container, Element, HorizontalAlignment, Length, Settings, Subscription,
Text,
button, executor, Application, Button, Checkbox, Column, Command,
Container, CrossAlign, Element, HorizontalAlignment, Length, Settings,
Subscription, Text,
};
use iced_native::{window, Event};

Expand Down Expand Up @@ -98,7 +98,7 @@ impl Application for Events {
.on_press(Message::Exit);

let content = Column::new()
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.spacing(20)
.push(events)
.push(toggle)
Expand Down
8 changes: 4 additions & 4 deletions examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use iced::slider::{self, Slider};
use iced::time;
use iced::window;
use iced::{
Align, Application, Checkbox, Column, Command, Container, Element, Length,
Row, Settings, Subscription, Text,
Application, Checkbox, Column, Command, Container, CrossAlign, Element,
Length, Row, Settings, Subscription, Text,
};
use preset::Preset;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -844,7 +844,7 @@ impl Controls {

let speed_controls = Row::new()
.width(Length::Fill)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.spacing(10)
.push(
Slider::new(
Expand All @@ -860,7 +860,7 @@ impl Controls {
Row::new()
.padding(10)
.spacing(20)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(playback_controls)
.push(speed_controls)
.push(
Expand Down
6 changes: 3 additions & 3 deletions examples/geometry/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ mod rainbow {
}

use iced::{
scrollable, Align, Column, Container, Element, Length, Sandbox, Scrollable,
Settings, Text,
scrollable, Column, Container, CrossAlign, Element, Length, Sandbox,
Scrollable, Settings, Text,
};
use rainbow::Rainbow;

Expand Down Expand Up @@ -194,7 +194,7 @@ impl Sandbox for Example {
.padding(20)
.spacing(20)
.max_width(500)
.align_items(Align::Start)
.align_items(CrossAlign::Start)
.push(Rainbow::new())
.push(Text::new(
"In this example we draw a custom widget Rainbow, using \
Expand Down
6 changes: 3 additions & 3 deletions examples/integration_opengl/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced_glow::Renderer;
use iced_glutin::{
slider, Align, Color, Column, Command, Element, Length, Program, Row,
slider, Color, Column, Command, CrossAlign, Element, Length, Program, Row,
Slider, Text,
};

Expand Down Expand Up @@ -79,11 +79,11 @@ impl Program for Controls {
Row::new()
.width(Length::Fill)
.height(Length::Fill)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(
Column::new()
.width(Length::Fill)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(
Column::new()
.padding(10)
Expand Down
6 changes: 3 additions & 3 deletions examples/integration_wgpu/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced_wgpu::Renderer;
use iced_winit::{
slider, Align, Color, Column, Command, Element, Length, Program, Row,
slider, Color, Column, Command, CrossAlign, Element, Length, Program, Row,
Slider, Text,
};

Expand Down Expand Up @@ -79,11 +79,11 @@ impl Program for Controls {
Row::new()
.width(Length::Fill)
.height(Length::Fill)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(
Column::new()
.width(Length::Fill)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(
Column::new()
.padding(10)
Expand Down
9 changes: 5 additions & 4 deletions examples/pane_grid/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use iced::{
button, executor, keyboard, pane_grid, scrollable, Align, Application,
Button, Color, Column, Command, Container, Element, HorizontalAlignment,
Length, PaneGrid, Row, Scrollable, Settings, Subscription, Text,
button, executor, keyboard, pane_grid, scrollable, Application, Button,
Color, Column, Command, Container, CrossAlign, Element,
HorizontalAlignment, Length, PaneGrid, Row, Scrollable, Settings,
Subscription, Text,
};
use iced_native::{event, subscription, Event};

Expand Down Expand Up @@ -329,7 +330,7 @@ impl Content {
let content = Scrollable::new(scroll)
.width(Length::Fill)
.spacing(10)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(controls);

Container::new(content)
Expand Down
4 changes: 2 additions & 2 deletions examples/pick_list/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iced::{
pick_list, scrollable, Align, Container, Element, Length, PickList,
pick_list, scrollable, Container, CrossAlign, Element, Length, PickList,
Sandbox, Scrollable, Settings, Space, Text,
};

Expand Down Expand Up @@ -49,7 +49,7 @@ impl Sandbox for Example {

let mut content = Scrollable::new(&mut self.scroll)
.width(Length::Fill)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.spacing(10)
.push(Space::with_height(Length::Units(600)))
.push(Text::new("Which is your favorite language?"))
Expand Down
12 changes: 6 additions & 6 deletions examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::{
button, futures, image, Align, Application, Button, Column, Command,
Container, Element, Length, Row, Settings, Text,
button, futures, image, Application, Button, Column, Command, Container,
CrossAlign, Element, Length, Row, Settings, Text,
};

pub fn main() -> iced::Result {
Expand Down Expand Up @@ -85,14 +85,14 @@ impl Application for Pokedex {
Pokedex::Loaded { pokemon, search } => Column::new()
.max_width(500)
.spacing(20)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(pokemon.view())
.push(
button(search, "Keep searching!").on_press(Message::Search),
),
Pokedex::Errored { try_again, .. } => Column::new()
.spacing(20)
.align_items(Align::End)
.align_items(CrossAlign::End)
.push(Text::new("Whoops! Something went wrong...").size(40))
.push(button(try_again, "Try again").on_press(Message::Search)),
};
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Pokemon {
fn view(&mut self) -> Element<Message> {
Row::new()
.spacing(20)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(image::Viewer::new(
&mut self.image_viewer,
self.image.clone(),
Expand All @@ -131,7 +131,7 @@ impl Pokemon {
.spacing(20)
.push(
Row::new()
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.spacing(20)
.push(
Text::new(&self.name)
Expand Down
4 changes: 2 additions & 2 deletions examples/qr_code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use iced::qr_code::{self, QRCode};
use iced::text_input::{self, TextInput};
use iced::{
Align, Column, Container, Element, Length, Sandbox, Settings, Text,
Column, Container, CrossAlign, Element, Length, Sandbox, Settings, Text,
};

pub fn main() -> iced::Result {
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Sandbox for QRGenerator {
let mut content = Column::new()
.width(Length::Units(700))
.spacing(20)
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.push(title)
.push(input);

Expand Down
6 changes: 3 additions & 3 deletions examples/stopwatch/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::{
button, executor, time, Align, Application, Button, Column, Command,
Container, Element, HorizontalAlignment, Length, Row, Settings,
button, executor, time, Application, Button, Column, Command, Container,
CrossAlign, Element, HorizontalAlignment, Length, Row, Settings,
Subscription, Text,
};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Application for Stopwatch {
.push(reset_button);

let content = Column::new()
.align_items(Align::Center)
.align_items(CrossAlign::Center)
.spacing(20)
.push(duration)
.push(controls);
Expand Down
Loading

0 comments on commit 5fae6e5

Please sign in to comment.