Re-export variants of Length and alignment types

This commit is contained in:
Héctor Ramón Jiménez 2024-07-12 18:12:34 +02:00
parent f9dd5cbb09
commit 76737351ea
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
51 changed files with 255 additions and 395 deletions

View file

@ -1,30 +1,5 @@
//! Align and position widgets. //! Align and position widgets.
/// Returns a value representing center alignment.
pub const fn center() -> Alignment {
Alignment::Center
}
/// Returns a value representing left alignment.
pub const fn left() -> Horizontal {
Horizontal::Left
}
/// Returns a value representing right alignment.
pub const fn right() -> Horizontal {
Horizontal::Right
}
/// Returns a value representing top alignment.
pub const fn top() -> Vertical {
Vertical::Top
}
/// Returns a value representing bottom alignment.
pub const fn bottom() -> Vertical {
Vertical::Bottom
}
/// Alignment on the axis of a container. /// Alignment on the axis of a container.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Alignment { pub enum Alignment {

View file

@ -88,37 +88,8 @@ where
/// Centers the [`Text`], both horizontally and vertically. /// Centers the [`Text`], both horizontally and vertically.
pub fn center(self) -> Self { pub fn center(self) -> Self {
self.center_x().center_y() self.align_x(alignment::Horizontal::Center)
} .align_y(alignment::Vertical::Center)
/// Centers the [`Text`] horizontally.
pub fn center_x(self) -> Self {
self.align_x(alignment::center())
}
/// Aligns the [`Text`] to the left, the default.
pub fn align_left(self) -> Self {
self.align_x(alignment::left())
}
/// Aligns the [`Text`] to the right.
pub fn align_right(self) -> Self {
self.align_x(alignment::right())
}
/// Centers the [`Text`] vertically.
pub fn center_y(self) -> Self {
self.align_y(alignment::center())
}
/// Aligns the [`Text`] to the top, the default.
pub fn align_top(self) -> Self {
self.align_y(alignment::top())
}
/// Aligns the [`Text`] to the bottom.
pub fn align_bottom(self) -> Self {
self.align_y(alignment::bottom())
} }
/// Sets the [`alignment::Horizontal`] of the [`Text`]. /// Sets the [`alignment::Horizontal`] of the [`Text`].

View file

@ -4,7 +4,7 @@ use iced::mouse;
use iced::widget::canvas::{ use iced::widget::canvas::{
self, stroke, Cache, Canvas, Geometry, Path, Stroke, self, stroke, Cache, Canvas, Geometry, Path, Stroke,
}; };
use iced::{Element, Length, Point, Rectangle, Renderer, Subscription, Theme}; use iced::{Element, Fill, Point, Rectangle, Renderer, Subscription, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Arc - Iced", Arc::update, Arc::view) iced::application("Arc - Iced", Arc::update, Arc::view)
@ -30,10 +30,7 @@ impl Arc {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
Canvas::new(self) Canvas::new(self).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {

View file

@ -1,6 +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::widget::{button, container, horizontal_space, hover}; use iced::widget::{button, container, horizontal_space, hover};
use iced::{Element, Length, Theme}; use iced::{Element, Fill, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Bezier Tool - Iced", Example::update, Example::view) iced::application("Bezier Tool - Iced", Example::update, Example::view)
@ -47,8 +47,7 @@ impl Example {
.on_press(Message::Clear), .on_press(Message::Clear),
) )
.padding(10) .padding(10)
.width(Length::Fill) .align_right(Fill)
.align_right()
}, },
)) ))
.padding(20) .padding(20)
@ -60,7 +59,7 @@ mod bezier {
use iced::mouse; use iced::mouse;
use iced::widget::canvas::event::{self, Event}; use iced::widget::canvas::event::{self, Event};
use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path, Stroke}; use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path, Stroke};
use iced::{Element, Length, Point, Rectangle, Renderer, Theme}; use iced::{Element, Fill, Point, Rectangle, Renderer, Theme};
#[derive(Default)] #[derive(Default)]
pub struct State { pub struct State {
@ -73,8 +72,8 @@ mod bezier {
state: self, state: self,
curves, curves,
}) })
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.into() .into()
} }

View file

@ -4,7 +4,7 @@ use iced::time;
use iced::widget::canvas::{stroke, Cache, Geometry, LineCap, Path, Stroke}; use iced::widget::canvas::{stroke, Cache, Geometry, LineCap, Path, Stroke};
use iced::widget::{canvas, container}; use iced::widget::{canvas, container};
use iced::{ use iced::{
Degrees, Element, Font, Length, Point, Rectangle, Renderer, Subscription, Degrees, Element, Fill, Font, Point, Rectangle, Renderer, Subscription,
Theme, Vector, Theme, Vector,
}; };
@ -43,15 +43,9 @@ impl Clock {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
let canvas = canvas(self as &Self) let canvas = canvas(self as &Self).width(Fill).height(Fill);
.width(Length::Fill)
.height(Length::Fill);
container(canvas) container(canvas).padding(20).into()
.width(Length::Fill)
.height(Length::Fill)
.padding(20)
.into()
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {

View file

@ -3,8 +3,8 @@ use iced::mouse;
use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path}; use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path};
use iced::widget::{column, row, text, Slider}; use iced::widget::{column, row, text, Slider};
use iced::{ use iced::{
Color, Element, Font, Length, Pixels, Point, Rectangle, Renderer, Size, Center, Color, Element, Fill, Font, Pixels, Point, Rectangle, Renderer,
Vector, Size, Vector,
}; };
use palette::{convert::FromColor, rgb::Rgb, Darken, Hsl, Lighten, ShiftHue}; use palette::{convert::FromColor, rgb::Rgb, Darken, Hsl, Lighten, ShiftHue};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -150,10 +150,7 @@ impl Theme {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
Canvas::new(self) Canvas::new(self).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
fn draw(&self, frame: &mut Frame, text_color: Color) { fn draw(&self, frame: &mut Frame, text_color: Color) {
@ -320,7 +317,7 @@ impl<C: ColorSpace + Copy> ColorPicker<C> {
text(color.to_string()).width(185).size(12), text(color.to_string()).width(185).size(12),
] ]
.spacing(10) .spacing(10)
.center_y() .align_y(Center)
.into() .into()
} }
} }

View file

@ -1,7 +1,7 @@
use iced::widget::{ use iced::widget::{
center, column, combo_box, scrollable, text, vertical_space, center, column, combo_box, scrollable, text, vertical_space,
}; };
use iced::{Element, Length}; use iced::{Center, Element, Fill};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("Combo Box - Iced", Example::update, Example::view) iced::run("Combo Box - Iced", Example::update, Example::view)
@ -64,8 +64,8 @@ impl Example {
combo_box, combo_box,
vertical_space().height(150), vertical_space().height(150),
] ]
.width(Length::Fill) .width(Fill)
.center_x() .align_x(Center)
.spacing(10); .spacing(10);
center(scrollable(content)).into() center(scrollable(content)).into()

View file

@ -35,7 +35,7 @@ impl Component {
mod numeric_input { mod numeric_input {
use iced::widget::{button, component, row, text, text_input, Component}; use iced::widget::{button, component, row, text, text_input, Component};
use iced::{Element, Length, Size}; use iced::{Center, Element, Fill, Length, Size};
pub struct NumericInput<Message> { pub struct NumericInput<Message> {
value: Option<u32>, value: Option<u32>,
@ -103,15 +103,10 @@ mod numeric_input {
fn view(&self, _state: &Self::State) -> Element<'_, Event, Theme> { fn view(&self, _state: &Self::State) -> Element<'_, Event, Theme> {
let button = |label, on_press| { let button = |label, on_press| {
button( button(text(label).width(Fill).height(Fill).center())
text(label) .width(40)
.width(Length::Fill) .height(40)
.height(Length::Fill) .on_press(on_press)
.center(),
)
.width(40)
.height(40)
.on_press(on_press)
}; };
row![ row![
@ -128,7 +123,7 @@ mod numeric_input {
.padding(10), .padding(10),
button("+", Event::IncrementPressed), button("+", Event::IncrementPressed),
] ]
.center_y() .align_y(Center)
.spacing(10) .spacing(10)
.into() .into()
} }

View file

@ -1,4 +1,5 @@
use iced::widget::{button, column, text, Column}; use iced::widget::{button, column, text, Column};
use iced::Center;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("A cool counter", Counter::update, Counter::view) iced::run("A cool counter", Counter::update, Counter::view)
@ -34,6 +35,6 @@ impl Counter {
button("Decrement").on_press(Message::Decrement) button("Decrement").on_press(Message::Decrement)
] ]
.padding(20) .padding(20)
.center_x() .align_x(Center)
} }
} }

View file

@ -82,7 +82,7 @@ mod quad {
} }
use iced::widget::{center, column, slider, text}; use iced::widget::{center, column, slider, text};
use iced::{Color, Element, Shadow, Vector}; use iced::{Center, Color, Element, Shadow, Vector};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("Custom Quad - Iced", Example::update, Example::view) iced::run("Custom Quad - Iced", Example::update, Example::view)
@ -185,7 +185,7 @@ impl Example {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.max_width(500) .max_width(500)
.center_x(); .align_x(Center);
center(content).into() center(content).into()
} }

View file

@ -6,7 +6,7 @@ use iced::time::Instant;
use iced::widget::shader::wgpu; use iced::widget::shader::wgpu;
use iced::widget::{center, checkbox, column, row, shader, slider, text}; use iced::widget::{center, checkbox, column, row, shader, slider, text};
use iced::window; use iced::window;
use iced::{Color, Element, Length, Subscription}; use iced::{Center, Color, Element, Fill, Subscription};
fn main() -> iced::Result { fn main() -> iced::Result {
iced::application( iced::application(
@ -122,12 +122,11 @@ impl IcedCubes {
let controls = column![top_controls, bottom_controls,] let controls = column![top_controls, bottom_controls,]
.spacing(10) .spacing(10)
.padding(20) .padding(20)
.center_x(); .align_x(Center);
let shader = let shader = shader(&self.scene).width(Fill).height(Fill);
shader(&self.scene).width(Length::Fill).height(Length::Fill);
center(column![shader, controls].center_x()).into() center(column![shader, controls].align_x(Center)).into()
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {

View file

@ -83,7 +83,7 @@ mod circle {
use circle::circle; use circle::circle;
use iced::widget::{center, column, slider, text}; use iced::widget::{center, column, slider, text};
use iced::Element; use iced::{Center, Element};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("Custom Widget - Iced", Example::update, Example::view) iced::run("Custom Widget - Iced", Example::update, Example::view)
@ -120,7 +120,7 @@ impl Example {
.padding(20) .padding(20)
.spacing(20) .spacing(20)
.max_width(500) .max_width(500)
.center_x(); .align_x(Center);
center(content).into() center(content).into()
} }

View file

@ -1,7 +1,7 @@
mod download; mod download;
use iced::widget::{button, center, column, progress_bar, text, Column}; use iced::widget::{button, center, column, progress_bar, text, Column};
use iced::{Element, Subscription}; use iced::{Center, Element, Right, Subscription};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application( iced::application(
@ -69,7 +69,7 @@ impl Example {
.padding(10), .padding(10),
) )
.spacing(20) .spacing(20)
.align_right(); .align_x(Right);
center(downloads).padding(20).into() center(downloads).padding(20).into()
} }
@ -160,7 +160,7 @@ impl Download {
State::Finished => { State::Finished => {
column!["Download finished!", button("Start again")] column!["Download finished!", button("Start again")]
.spacing(10) .spacing(10)
.center_x() .align_x(Center)
.into() .into()
} }
State::Downloading { .. } => { State::Downloading { .. } => {
@ -171,14 +171,14 @@ impl Download {
button("Try again").on_press(Message::Download(self.id)), button("Try again").on_press(Message::Download(self.id)),
] ]
.spacing(10) .spacing(10)
.center_x() .align_x(Center)
.into(), .into(),
}; };
Column::new() Column::new()
.spacing(10) .spacing(10)
.padding(10) .padding(10)
.center_x() .align_x(Center)
.push(progress_bar) .push(progress_bar)
.push(control) .push(control)
.into() .into()

View file

@ -4,7 +4,7 @@ use iced::widget::{
button, column, container, horizontal_space, pick_list, row, text, button, column, container, horizontal_space, pick_list, row, text,
text_editor, tooltip, text_editor, tooltip,
}; };
use iced::{Element, Font, Length, Subscription, Task, Theme}; use iced::{Center, Element, Fill, Font, Subscription, Task, Theme};
use std::ffi; use std::ffi;
use std::io; use std::io;
@ -158,7 +158,7 @@ impl Editor {
.padding([5, 10]) .padding([5, 10])
] ]
.spacing(10) .spacing(10)
.center_y(); .align_y(Center);
let status = row![ let status = row![
text(if let Some(path) = &self.file { text(if let Some(path) = &self.file {
@ -184,7 +184,7 @@ impl Editor {
column![ column![
controls, controls,
text_editor(&self.content) text_editor(&self.content)
.height(Length::Fill) .height(Fill)
.on_action(Message::ActionPerformed) .on_action(Message::ActionPerformed)
.highlight::<Highlighter>( .highlight::<Highlighter>(
highlighter::Settings { highlighter::Settings {

View file

@ -1,7 +1,7 @@
use iced::event::{self, Event}; use iced::event::{self, Event};
use iced::widget::{button, center, checkbox, text, Column}; use iced::widget::{button, center, checkbox, text, Column};
use iced::window; use iced::window;
use iced::{Element, Length, Subscription, Task}; use iced::{Center, Element, Fill, Subscription, Task};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Events - Iced", Events::update, Events::view) iced::application("Events - Iced", Events::update, Events::view)
@ -66,13 +66,13 @@ impl Events {
let toggle = checkbox("Listen to runtime events", self.enabled) let toggle = checkbox("Listen to runtime events", self.enabled)
.on_toggle(Message::Toggled); .on_toggle(Message::Toggled);
let exit = button(text("Exit").width(Length::Fill).center_x()) let exit = button(text("Exit").width(Fill).align_x(Center))
.width(100) .width(100)
.padding(10) .padding(10)
.on_press(Message::Exit); .on_press(Message::Exit);
let content = Column::new() let content = Column::new()
.center_x() .align_x(Center)
.spacing(20) .spacing(20)
.push(events) .push(events)
.push(toggle) .push(toggle)

View file

@ -1,6 +1,6 @@
use iced::widget::{button, center, column}; use iced::widget::{button, center, column};
use iced::window; use iced::window;
use iced::{Element, Task}; use iced::{Center, Element, Task};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Exit - Iced", Exit::update, Exit::view).run() iced::application("Exit - Iced", Exit::update, Exit::view).run()
@ -44,7 +44,7 @@ impl Exit {
] ]
} }
.spacing(10) .spacing(10)
.center_x(); .align_x(Center);
center(content).padding(20).into() center(content).padding(20).into()
} }

View file

@ -4,8 +4,8 @@ use iced::widget::{
}; };
use iced::window; use iced::window;
use iced::{ use iced::{
Color, ContentFit, Degrees, Element, Length, Radians, Rotation, Bottom, Center, Color, ContentFit, Degrees, Element, Fill, Radians,
Subscription, Theme, Rotation, Subscription, Theme,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -108,7 +108,7 @@ impl Image {
"I am Ferris!" "I am Ferris!"
] ]
.spacing(20) .spacing(20)
.center_x(); .align_x(Center);
let fit = row![ let fit = row![
pick_list( pick_list(
@ -122,7 +122,7 @@ impl Image {
Some(self.content_fit), Some(self.content_fit),
Message::ContentFitChanged Message::ContentFitChanged
) )
.width(Length::Fill), .width(Fill),
pick_list( pick_list(
[RotationStrategy::Floating, RotationStrategy::Solid], [RotationStrategy::Floating, RotationStrategy::Solid],
Some(match self.rotation { Some(match self.rotation {
@ -131,10 +131,10 @@ impl Image {
}), }),
Message::RotationStrategyChanged, Message::RotationStrategyChanged,
) )
.width(Length::Fill), .width(Fill),
] ]
.spacing(10) .spacing(10)
.align_bottom(); .align_y(Bottom);
let properties = row![ let properties = row![
with_value( with_value(
@ -159,12 +159,12 @@ impl Image {
.size(12) .size(12)
] ]
.spacing(10) .spacing(10)
.center_y(), .align_y(Center),
format!("Rotation: {:.0}°", f32::from(self.rotation.degrees())) format!("Rotation: {:.0}°", f32::from(self.rotation.degrees()))
) )
] ]
.spacing(10) .spacing(10)
.align_bottom(); .align_y(Bottom);
container(column![fit, center(i_am_ferris), properties].spacing(10)) container(column![fit, center(i_am_ferris), properties].spacing(10))
.padding(10) .padding(10)
@ -206,6 +206,6 @@ fn with_value<'a>(
) -> Element<'a, Message> { ) -> Element<'a, Message> {
column![control.into(), text(value).size(12).line_height(1.0)] column![control.into(), text(value).size(12).line_height(1.0)]
.spacing(2) .spacing(2)
.center_x() .align_x(Center)
.into() .into()
} }

View file

@ -9,7 +9,7 @@ use iced::time;
use iced::widget::{ use iced::widget::{
button, checkbox, column, container, pick_list, row, slider, text, button, checkbox, column, container, pick_list, row, slider, text,
}; };
use iced::{Element, Length, Subscription, Task, Theme}; use iced::{Center, Element, Fill, Subscription, Task, Theme};
use std::time::Duration; use std::time::Duration;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -135,12 +135,9 @@ impl GameOfLife {
.map(move |message| Message::Grid(message, version)), .map(move |message| Message::Grid(message, version)),
controls, controls,
] ]
.height(Length::Fill); .height(Fill);
container(content) container(content).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
} }
@ -169,7 +166,7 @@ fn view_controls<'a>(
slider(1.0..=1000.0, speed as f32, Message::SpeedChanged), slider(1.0..=1000.0, speed as f32, Message::SpeedChanged),
text!("x{speed}").size(16), text!("x{speed}").size(16),
] ]
.center_y() .align_y(Center)
.spacing(10); .spacing(10);
row![ row![
@ -186,7 +183,7 @@ fn view_controls<'a>(
] ]
.padding(10) .padding(10)
.spacing(20) .spacing(20)
.center_y() .align_y(Center)
.into() .into()
} }
@ -199,7 +196,7 @@ mod grid {
use iced::widget::canvas::event::{self, Event}; use iced::widget::canvas::event::{self, Event};
use iced::widget::canvas::{Cache, Canvas, Frame, Geometry, Path, Text}; use iced::widget::canvas::{Cache, Canvas, Frame, Geometry, Path, Text};
use iced::{ use iced::{
Color, Element, Length, Point, Rectangle, Renderer, Size, Theme, Vector, Color, Element, Fill, Point, Rectangle, Renderer, Size, Theme, Vector,
}; };
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use std::future::Future; use std::future::Future;
@ -333,10 +330,7 @@ mod grid {
} }
pub fn view(&self) -> Element<Message> { pub fn view(&self) -> Element<Message> {
Canvas::new(self) Canvas::new(self).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {

View file

@ -3,7 +3,7 @@ use iced::gradient;
use iced::widget::{ use iced::widget::{
checkbox, column, container, horizontal_space, row, slider, text, checkbox, column, container, horizontal_space, row, slider, text,
}; };
use iced::{Color, Element, Length, Radians, Theme}; use iced::{Center, Color, Element, Fill, Radians, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
@ -67,8 +67,8 @@ impl Gradient {
gradient.into() gradient.into()
}) })
.width(Length::Fill) .width(Fill)
.height(Length::Fill); .height(Fill);
let angle_picker = row![ let angle_picker = row![
text("Angle").width(64), text("Angle").width(64),
@ -77,7 +77,7 @@ impl Gradient {
] ]
.spacing(8) .spacing(8)
.padding(8) .padding(8)
.center_y(); .align_y(Center);
let transparency_toggle = iced::widget::Container::new( let transparency_toggle = iced::widget::Container::new(
checkbox("Transparent window", transparent) checkbox("Transparent window", transparent)
@ -129,6 +129,6 @@ fn color_picker(label: &str, color: Color) -> Element<'_, Color> {
] ]
.spacing(8) .spacing(8)
.padding(8) .padding(8)
.center_y() .align_y(Center)
.into() .into()
} }

View file

@ -1,6 +1,6 @@
use iced_wgpu::Renderer; use iced_wgpu::Renderer;
use iced_widget::{column, container, row, slider, text, text_input}; use iced_widget::{column, container, row, slider, text, text_input};
use iced_winit::core::{Color, Element, Length, Theme}; use iced_winit::core::{Color, Element, Length::*, Theme};
use iced_winit::runtime::{Program, Task}; use iced_winit::runtime::{Program, Task};
pub struct Controls { pub struct Controls {
@ -85,8 +85,7 @@ impl Program for Controls {
.spacing(10), .spacing(10),
) )
.padding(10) .padding(10)
.height(Length::Fill) .align_bottom(Fill)
.align_bottom()
.into() .into()
} }
} }

View file

@ -5,8 +5,8 @@ use iced::widget::{
pick_list, row, scrollable, text, pick_list, row, scrollable, text,
}; };
use iced::{ use iced::{
color, Element, Font, Length, Point, Rectangle, Renderer, Subscription, color, Center, Element, Fill, Font, Length, Point, Rectangle, Renderer,
Theme, Subscription, Theme,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -74,7 +74,7 @@ impl Layout {
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeSelected), pick_list(Theme::ALL, Some(&self.theme), Message::ThemeSelected),
] ]
.spacing(20) .spacing(20)
.center_y(); .align_y(Center);
let example = center(if self.explain { let example = center(if self.explain {
self.example.view().explain(color!(0x0000ff)) self.example.view().explain(color!(0x0000ff))
@ -234,7 +234,7 @@ fn application<'a>() -> Element<'a, Message> {
square(40), square(40),
] ]
.padding(10) .padding(10)
.center_y(), .align_y(Center),
) )
.style(|theme| { .style(|theme| {
let palette = theme.extended_palette(); let palette = theme.extended_palette();
@ -248,10 +248,10 @@ fn application<'a>() -> Element<'a, Message> {
.spacing(40) .spacing(40)
.padding(10) .padding(10)
.width(200) .width(200)
.center_x(), .align_x(Center),
) )
.style(container::rounded_box) .style(container::rounded_box)
.center_y(Length::Fill); .center_y(Fill);
let content = container( let content = container(
scrollable( scrollable(
@ -263,10 +263,10 @@ fn application<'a>() -> Element<'a, Message> {
"The end" "The end"
] ]
.spacing(40) .spacing(40)
.center_x() .align_x(Center)
.width(Length::Fill), .width(Fill),
) )
.height(Length::Fill), .height(Fill),
) )
.padding(10); .padding(10);

View file

@ -2,7 +2,7 @@ use iced::widget::{
button, column, horizontal_space, lazy, pick_list, row, scrollable, text, button, column, horizontal_space, lazy, pick_list, row, scrollable, text,
text_input, text_input,
}; };
use iced::{Element, Length}; use iced::{Element, Fill};
use std::collections::HashSet; use std::collections::HashSet;
use std::hash::Hash; use std::hash::Hash;
@ -187,7 +187,7 @@ impl App {
}); });
column![ column![
scrollable(options).height(Length::Fill), scrollable(options).height(Fill),
row![ row![
text_input("Add a new option", &self.input) text_input("Add a new option", &self.input)
.on_input(Message::InputChanged) .on_input(Message::InputChanged)

View file

@ -1,5 +1,5 @@
use iced::widget::{center, column, row, slider, text}; use iced::widget::{center, column, row, slider, text};
use iced::Element; use iced::{Center, Element};
use std::time::Duration; use std::time::Duration;
@ -67,7 +67,7 @@ impl LoadingSpinners {
Duration::from_secs_f32(self.cycle_duration) Duration::from_secs_f32(self.cycle_duration)
) )
] ]
.center_y() .align_y(Center)
.spacing(20.0), .spacing(20.0),
) )
}) })
@ -83,7 +83,7 @@ impl LoadingSpinners {
.width(200.0), .width(200.0),
text!("{:.2}s", self.cycle_duration), text!("{:.2}s", self.cycle_duration),
] ]
.center_y() .align_y(Center)
.spacing(20.0), .spacing(20.0),
), ),
) )

View file

@ -1,5 +1,5 @@
use iced::widget::{button, center, column, text}; use iced::widget::{button, center, column, text};
use iced::Element; use iced::{Center, Element};
use loupe::loupe; use loupe::loupe;
@ -39,7 +39,7 @@ impl Loupe {
button("Decrement").on_press(Message::Decrement) button("Decrement").on_press(Message::Decrement)
] ]
.padding(20) .padding(20)
.center_x(), .align_x(Center),
)) ))
.into() .into()
} }

View file

@ -5,7 +5,7 @@ use iced::widget::{
self, button, center, column, container, horizontal_space, mouse_area, self, button, center, column, container, horizontal_space, mouse_area,
opaque, pick_list, row, stack, text, text_input, opaque, pick_list, row, stack, text, text_input,
}; };
use iced::{Color, Element, Length, Subscription, Task}; use iced::{Bottom, Color, Element, Fill, Subscription, Task};
use std::fmt; use std::fmt;
@ -96,17 +96,17 @@ impl App {
let content = container( let content = container(
column![ column![
row![text("Top Left"), horizontal_space(), text("Top Right")] row![text("Top Left"), horizontal_space(), text("Top Right")]
.height(Length::Fill), .height(Fill),
center(button(text("Show Modal")).on_press(Message::ShowModal)), center(button(text("Show Modal")).on_press(Message::ShowModal)),
row![ row![
text("Bottom Left"), text("Bottom Left"),
horizontal_space(), horizontal_space(),
text("Bottom Right") text("Bottom Right")
] ]
.align_bottom() .align_y(Bottom)
.height(Length::Fill), .height(Fill),
] ]
.height(Length::Fill), .height(Fill),
) )
.padding(10); .padding(10);

View file

@ -3,7 +3,7 @@ use iced::widget::{
text_input, text_input,
}; };
use iced::window; use iced::window;
use iced::{Element, Length, Subscription, Task, Theme, Vector}; use iced::{Center, Element, Fill, Subscription, Task, Theme, Vector};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -188,8 +188,8 @@ impl Window {
let content = scrollable( let content = scrollable(
column![scale_input, title_input, new_window_button] column![scale_input, title_input, new_window_button]
.spacing(50) .spacing(50)
.width(Length::Fill) .width(Fill)
.center_x(), .align_x(Center),
); );
container(content).center_x(200).into() container(content).center_x(200).into()

View file

@ -6,7 +6,7 @@ use iced::touch;
use iced::widget::canvas::event; use iced::widget::canvas::event;
use iced::widget::canvas::stroke::{self, Stroke}; use iced::widget::canvas::stroke::{self, Stroke};
use iced::widget::canvas::{self, Canvas, Geometry}; use iced::widget::canvas::{self, Canvas, Geometry};
use iced::{Color, Element, Length, Point, Rectangle, Renderer, Theme}; use iced::{Color, Element, Fill, Point, Rectangle, Renderer, Theme};
use std::collections::HashMap; use std::collections::HashMap;
@ -46,10 +46,7 @@ impl Multitouch {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
Canvas::new(self) Canvas::new(self).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
} }

View file

@ -3,7 +3,7 @@ use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{ use iced::widget::{
button, column, container, responsive, row, scrollable, text, button, column, container, responsive, row, scrollable, text,
}; };
use iced::{Color, Element, Length, Size, Subscription}; use iced::{Center, Color, Element, Fill, Size, Subscription};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Pane Grid - Iced", Example::update, Example::view) iced::application("Pane Grid - Iced", Example::update, Example::view)
@ -177,16 +177,16 @@ impl Example {
style::pane_active style::pane_active
}) })
}) })
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.spacing(10) .spacing(10)
.on_click(Message::Clicked) .on_click(Message::Clicked)
.on_drag(Message::Dragged) .on_drag(Message::Dragged)
.on_resize(10, Message::Resized); .on_resize(10, Message::Resized);
container(pane_grid) container(pane_grid)
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.padding(10) .padding(10)
.into() .into()
} }
@ -254,8 +254,8 @@ fn view_content<'a>(
size: Size, size: Size,
) -> Element<'a, Message> { ) -> Element<'a, Message> {
let button = |label, message| { let button = |label, message| {
button(text(label).width(Length::Fill).center_x().size(16)) button(text(label).width(Fill).align_x(Center).size(16))
.width(Length::Fill) .width(Fill)
.padding(8) .padding(8)
.on_press(message) .on_press(message)
}; };
@ -281,10 +281,10 @@ fn view_content<'a>(
let content = let content =
column![text!("{}x{}", size.width, size.height).size(24), controls,] column![text!("{}x{}", size.width, size.height).size(24), controls,]
.spacing(10) .spacing(10)
.center_x(); .align_x(Center);
container(scrollable(content)) container(scrollable(content))
.center_y(Length::Fill) .center_y(Fill)
.padding(5) .padding(5)
.into() .into()
} }

View file

@ -1,5 +1,5 @@
use iced::widget::{column, pick_list, scrollable, vertical_space}; use iced::widget::{column, pick_list, scrollable, vertical_space};
use iced::{Element, Length}; use iced::{Center, Element, Fill};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("Pick List - Iced", Example::update, Example::view) iced::run("Pick List - Iced", Example::update, Example::view)
@ -38,8 +38,8 @@ impl Example {
pick_list, pick_list,
vertical_space().height(600), vertical_space().height(600),
] ]
.width(Length::Fill) .width(Fill)
.center_x() .align_x(Center)
.spacing(10); .spacing(10);
scrollable(content).into() scrollable(content).into()

View file

@ -1,6 +1,6 @@
use iced::futures; use iced::futures;
use iced::widget::{self, center, column, image, row, text}; use iced::widget::{self, center, column, image, row, text};
use iced::{Element, Length, Task}; use iced::{Center, Element, Fill, Right, Task};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application(Pokedex::title, Pokedex::update, Pokedex::view) iced::application(Pokedex::title, Pokedex::update, Pokedex::view)
@ -63,10 +63,9 @@ impl Pokedex {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
let content = match self { let content: Element<_> = match self {
Pokedex::Loading => { Pokedex::Loading => {
column![text("Searching for Pokémon...").size(40),] text("Searching for Pokémon...").size(40).into()
.width(Length::Shrink)
} }
Pokedex::Loaded { pokemon } => column![ Pokedex::Loaded { pokemon } => column![
pokemon.view(), pokemon.view(),
@ -74,13 +73,15 @@ impl Pokedex {
] ]
.max_width(500) .max_width(500)
.spacing(20) .spacing(20)
.align_right(), .align_x(Right)
.into(),
Pokedex::Errored => column![ Pokedex::Errored => column![
text("Whoops! Something went wrong...").size(40), text("Whoops! Something went wrong...").size(40),
button("Try again").on_press(Message::Search) button("Try again").on_press(Message::Search)
] ]
.spacing(20) .spacing(20)
.align_right(), .align_x(Right)
.into(),
}; };
center(content).into() center(content).into()
@ -103,17 +104,17 @@ impl Pokemon {
image::viewer(self.image.clone()), image::viewer(self.image.clone()),
column![ column![
row![ row![
text(&self.name).size(30).width(Length::Fill), text(&self.name).size(30).width(Fill),
text!("#{}", self.number).size(20).color([0.5, 0.5, 0.5]), text!("#{}", self.number).size(20).color([0.5, 0.5, 0.5]),
] ]
.center_y() .align_y(Center)
.spacing(20), .spacing(20),
self.description.as_ref(), self.description.as_ref(),
] ]
.spacing(20), .spacing(20),
] ]
.spacing(20) .spacing(20)
.center_y() .align_y(Center)
.into() .into()
} }

View file

@ -1,5 +1,5 @@
use iced::widget::{center, column, pick_list, qr_code, row, text, text_input}; use iced::widget::{center, column, pick_list, qr_code, row, text, text_input};
use iced::{Element, Theme}; use iced::{Center, Element, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application( iced::application(
@ -58,7 +58,7 @@ impl QRGenerator {
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged,) pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged,)
] ]
.spacing(10) .spacing(10)
.center_y(); .align_y(Center);
let content = column![title, input, choose_theme] let content = column![title, input, choose_theme]
.push_maybe( .push_maybe(
@ -68,7 +68,7 @@ impl QRGenerator {
) )
.width(700) .width(700)
.spacing(20) .spacing(20)
.center_x(); .align_x(Center);
center(content).padding(20).into() center(content).padding(20).into()
} }

View file

@ -2,7 +2,10 @@ use iced::keyboard;
use iced::widget::{button, column, container, image, row, text, text_input}; use iced::widget::{button, column, container, image, row, text, text_input};
use iced::window; use iced::window;
use iced::window::screenshot::{self, Screenshot}; use iced::window::screenshot::{self, Screenshot};
use iced::{ContentFit, Element, Length, Rectangle, Subscription, Task}; use iced::{
Center, ContentFit, Element, Fill, FillPortion, Rectangle, Subscription,
Task,
};
use ::image as img; use ::image as img;
use ::image::ColorType; use ::image::ColorType;
@ -111,15 +114,15 @@ impl Example {
screenshot.clone(), screenshot.clone(),
)) ))
.content_fit(ContentFit::Contain) .content_fit(ContentFit::Contain)
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.into() .into()
} else { } else {
text("Press the button to take a screenshot!").into() text("Press the button to take a screenshot!").into()
}; };
let image = container(image) let image = container(image)
.center_y(Length::FillPortion(2)) .center_y(FillPortion(2))
.padding(10) .padding(10)
.style(container::rounded_box); .style(container::rounded_box);
@ -130,7 +133,7 @@ impl Example {
numeric_input("0", self.y_input_value).map(Message::YInputChanged) numeric_input("0", self.y_input_value).map(Message::YInputChanged)
] ]
.spacing(10) .spacing(10)
.center_y(); .align_y(Center);
let crop_dimension_controls = row![ let crop_dimension_controls = row![
text("W:").width(30), text("W:").width(30),
@ -141,7 +144,7 @@ impl Example {
.map(Message::HeightInputChanged) .map(Message::HeightInputChanged)
] ]
.spacing(10) .spacing(10)
.center_y(); .align_y(Center);
let crop_controls = let crop_controls =
column![crop_origin_controls, crop_dimension_controls] column![crop_origin_controls, crop_dimension_controls]
@ -151,7 +154,7 @@ impl Example {
.map(|error| text!("Crop error! \n{error}")), .map(|error| text!("Crop error! \n{error}")),
) )
.spacing(10) .spacing(10)
.center_x(); .align_x(Center);
let controls = { let controls = {
let save_result = let save_result =
@ -168,7 +171,7 @@ impl Example {
column![ column![
button(centered_text("Screenshot!")) button(centered_text("Screenshot!"))
.padding([10, 20, 10, 20]) .padding([10, 20, 10, 20])
.width(Length::Fill) .width(Fill)
.on_press(Message::Screenshot), .on_press(Message::Screenshot),
if !self.png_saving { if !self.png_saving {
button(centered_text("Save as png")).on_press_maybe( button(centered_text("Save as png")).on_press_maybe(
@ -180,7 +183,7 @@ impl Example {
} }
.style(button::secondary) .style(button::secondary)
.padding([10, 20, 10, 20]) .padding([10, 20, 10, 20])
.width(Length::Fill) .width(Fill)
] ]
.spacing(10), .spacing(10),
column![ column![
@ -189,22 +192,22 @@ impl Example {
.on_press(Message::Crop) .on_press(Message::Crop)
.style(button::danger) .style(button::danger)
.padding([10, 20, 10, 20]) .padding([10, 20, 10, 20])
.width(Length::Fill), .width(Fill),
] ]
.spacing(10) .spacing(10)
.center_x(), .align_x(Center),
] ]
.push_maybe(save_result.map(text)) .push_maybe(save_result.map(text))
.spacing(40) .spacing(40)
}; };
let side_content = container(controls).center_y(Length::Fill); let side_content = container(controls).center_y(Fill);
let content = row![side_content, image] let content = row![side_content, image]
.spacing(10) .spacing(10)
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.center_y(); .align_y(Center);
container(content).padding(10).into() container(content).padding(10).into()
} }
@ -265,5 +268,5 @@ fn numeric_input(
} }
fn centered_text(content: &str) -> Element<'_, Message> { fn centered_text(content: &str) -> Element<'_, Message> {
text(content).width(Length::Fill).center_x().into() text(content).width(Fill).align_x(Center).into()
} }

View file

@ -2,7 +2,7 @@ use iced::widget::{
button, column, container, horizontal_space, progress_bar, radio, row, button, column, container, horizontal_space, progress_bar, radio, row,
scrollable, slider, text, vertical_space, scrollable, slider, text, vertical_space,
}; };
use iced::{Border, Color, Element, Length, Task, Theme}; use iced::{Border, Center, Color, Element, Fill, Task, Theme};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -212,7 +212,7 @@ impl ScrollableDemo {
text("End!"), text("End!"),
scroll_to_beginning_button(), scroll_to_beginning_button(),
] ]
.center_x() .align_x(Center)
.padding([40, 0, 40, 0]) .padding([40, 0, 40, 0])
.spacing(40), .spacing(40),
) )
@ -223,8 +223,8 @@ impl ScrollableDemo {
.scroller_width(self.scroller_width) .scroller_width(self.scroller_width)
.anchor(self.anchor), .anchor(self.anchor),
)) ))
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.id(SCROLLABLE_ID.clone()) .id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled), .on_scroll(Message::Scrolled),
Direction::Horizontal => scrollable( Direction::Horizontal => scrollable(
@ -238,7 +238,7 @@ impl ScrollableDemo {
scroll_to_beginning_button(), scroll_to_beginning_button(),
] ]
.height(450) .height(450)
.center_y() .align_y(Center)
.padding([0, 40, 0, 40]) .padding([0, 40, 0, 40])
.spacing(40), .spacing(40),
) )
@ -249,8 +249,8 @@ impl ScrollableDemo {
.scroller_width(self.scroller_width) .scroller_width(self.scroller_width)
.anchor(self.anchor), .anchor(self.anchor),
)) ))
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.id(SCROLLABLE_ID.clone()) .id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled), .on_scroll(Message::Scrolled),
Direction::Multi => scrollable( Direction::Multi => scrollable(
@ -280,7 +280,7 @@ impl ScrollableDemo {
text("Horizontal - End!"), text("Horizontal - End!"),
scroll_to_beginning_button(), scroll_to_beginning_button(),
] ]
.center_y() .align_y(Center)
.padding([0, 40, 0, 40]) .padding([0, 40, 0, 40])
.spacing(40), .spacing(40),
) )
@ -296,8 +296,8 @@ impl ScrollableDemo {
vertical: scrollbar, vertical: scrollbar,
} }
}) })
.width(Length::Fill) .width(Fill)
.height(Length::Fill) .height(Fill)
.id(SCROLLABLE_ID.clone()) .id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled), .on_scroll(Message::Scrolled),
}); });
@ -322,7 +322,7 @@ impl ScrollableDemo {
let content: Element<Message> = let content: Element<Message> =
column![scroll_controls, scrollable_content, progress_bars] column![scroll_controls, scrollable_content, progress_bars]
.center_x() .align_x(Center)
.spacing(10) .spacing(10)
.into(); .into();

View file

@ -2,7 +2,7 @@ use iced::mouse;
use iced::widget::canvas::event::{self, Event}; use iced::widget::canvas::event::{self, Event};
use iced::widget::canvas::{self, Canvas, Geometry}; use iced::widget::canvas::{self, Canvas, Geometry};
use iced::widget::{column, row, slider, text}; use iced::widget::{column, row, slider, text};
use iced::{Color, Length, Point, Rectangle, Renderer, Size, Theme}; use iced::{Center, Color, Fill, Point, Rectangle, Renderer, Size, Theme};
use rand::Rng; use rand::Rng;
use std::fmt::Debug; use std::fmt::Debug;
@ -50,9 +50,7 @@ impl SierpinskiEmulator {
fn view(&self) -> iced::Element<'_, Message> { fn view(&self) -> iced::Element<'_, Message> {
column![ column![
Canvas::new(&self.graph) Canvas::new(&self.graph).width(Fill).height(Fill),
.width(Length::Fill)
.height(Length::Fill),
row![ row![
text!("Iteration: {:?}", self.graph.iteration), text!("Iteration: {:?}", self.graph.iteration),
slider(0..=10000, self.graph.iteration, Message::IterationSet) slider(0..=10000, self.graph.iteration, Message::IterationSet)
@ -60,7 +58,7 @@ impl SierpinskiEmulator {
.padding(10) .padding(10)
.spacing(20), .spacing(20),
] ]
.center_x() .align_x(Center)
.into() .into()
} }
} }

View file

@ -1,5 +1,5 @@
use iced::widget::{column, container, iced, slider, text, vertical_slider}; use iced::widget::{column, container, iced, slider, text, vertical_slider};
use iced::{Element, Length}; use iced::{Center, Element, Fill};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("Slider - Iced", Slider::update, Slider::view) iced::run("Slider - Iced", Slider::update, Slider::view)
@ -45,8 +45,8 @@ impl Slider {
let text = text(self.value); let text = text(self.value);
column![v_slider, h_slider, text, iced(self.value as f32),] column![v_slider, h_slider, text, iced(self.value as f32),]
.width(Length::Fill) .width(Fill)
.center_x() .align_x(Center)
.spacing(20) .spacing(20)
.padding(20) .padding(20)
.into() .into()

View file

@ -13,7 +13,7 @@ use iced::widget::canvas::stroke::{self, Stroke};
use iced::widget::canvas::{Geometry, Path}; use iced::widget::canvas::{Geometry, Path};
use iced::window; use iced::window;
use iced::{ use iced::{
Color, Element, Length, Point, Rectangle, Renderer, Size, Subscription, Color, Element, Fill, Point, Rectangle, Renderer, Size, Subscription,
Theme, Vector, Theme, Vector,
}; };
@ -52,10 +52,7 @@ impl SolarSystem {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
canvas(&self.state) canvas(&self.state).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
fn theme(&self) -> Theme { fn theme(&self) -> Theme {

View file

@ -1,7 +1,7 @@
use iced::keyboard; use iced::keyboard;
use iced::time; use iced::time;
use iced::widget::{button, center, column, row, text}; use iced::widget::{button, center, column, row, text};
use iced::{Element, Subscription, Theme}; use iced::{Center, Element, Subscription, Theme};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -101,7 +101,7 @@ impl Stopwatch {
.size(40); .size(40);
let button = let button =
|label| button(text(label).center_x()).padding(10).width(80); |label| button(text(label).align_x(Center)).padding(10).width(80);
let toggle_button = { let toggle_button = {
let label = match self.state { let label = match self.state {
@ -118,7 +118,7 @@ impl Stopwatch {
let controls = row![toggle_button, reset_button].spacing(20); let controls = row![toggle_button, reset_button].spacing(20);
let content = column![duration, controls].center_x().spacing(20); let content = column![duration, controls].align_x(Center).spacing(20);
center(content).into() center(content).into()
} }

View file

@ -3,7 +3,7 @@ use iced::widget::{
row, scrollable, slider, text, text_input, toggler, vertical_rule, row, scrollable, slider, text, text_input, toggler, vertical_rule,
vertical_space, vertical_space,
}; };
use iced::{Element, Length, Theme}; use iced::{Center, Element, Fill, Theme};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application("Styling - Iced", Styling::update, Styling::view) iced::application("Styling - Iced", Styling::update, Styling::view)
@ -48,7 +48,7 @@ impl Styling {
let choose_theme = column![ let choose_theme = column![
text("Theme:"), text("Theme:"),
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged) pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged)
.width(Length::Fill), .width(Fill),
] ]
.spacing(10); .spacing(10);
@ -71,7 +71,7 @@ impl Styling {
vertical_space().height(800), vertical_space().height(800),
"You did it!" "You did it!"
]) ])
.width(Length::Fill) .width(Fill)
.height(100); .height(100);
let checkbox = checkbox("Check me!", self.checkbox_value) let checkbox = checkbox("Check me!", self.checkbox_value)
@ -82,13 +82,12 @@ impl Styling {
self.toggler_value, self.toggler_value,
Message::TogglerToggled, Message::TogglerToggled,
) )
.width(Length::Shrink)
.spacing(10); .spacing(10);
let content = column![ let content = column![
choose_theme, choose_theme,
horizontal_rule(38), horizontal_rule(38),
row![text_input, button].spacing(10).center_y(), row![text_input, button].spacing(10).align_y(Center),
slider, slider,
progress_bar, progress_bar,
row![ row![
@ -98,7 +97,7 @@ impl Styling {
] ]
.spacing(10) .spacing(10)
.height(100) .height(100)
.center_y(), .align_y(Center),
] ]
.spacing(20) .spacing(20)
.padding(20) .padding(20)

View file

@ -1,5 +1,5 @@
use iced::widget::{center, checkbox, column, container, svg}; use iced::widget::{center, checkbox, column, container, svg};
use iced::{color, Element, Length}; use iced::{color, Element, Fill};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run("SVG - Iced", Tiger::update, Tiger::view) iced::run("SVG - Iced", Tiger::update, Tiger::view)
@ -30,24 +30,26 @@ impl Tiger {
env!("CARGO_MANIFEST_DIR") env!("CARGO_MANIFEST_DIR")
)); ));
let svg = svg(handle).width(Length::Fill).height(Length::Fill).style( let svg =
|_theme, _status| svg::Style { svg(handle)
color: if self.apply_color_filter { .width(Fill)
Some(color!(0x0000ff)) .height(Fill)
} else { .style(|_theme, _status| svg::Style {
None color: if self.apply_color_filter {
}, Some(color!(0x0000ff))
}, } else {
); None
},
});
let apply_color_filter = let apply_color_filter =
checkbox("Apply a color filter", self.apply_color_filter) checkbox("Apply a color filter", self.apply_color_filter)
.on_toggle(Message::ToggleColorFilter); .on_toggle(Message::ToggleColorFilter);
center( center(
column![svg, container(apply_color_filter).center_x(Length::Fill)] column![svg, container(apply_color_filter).center_x(Fill)]
.spacing(20) .spacing(20)
.height(Length::Fill), .height(Fill),
) )
.padding(20) .padding(20)
.into() .into()

View file

@ -2,8 +2,7 @@ use iced::mouse;
use iced::time::{self, Instant}; use iced::time::{self, Instant};
use iced::widget::canvas; use iced::widget::canvas;
use iced::{ use iced::{
Color, Element, Font, Length, Point, Rectangle, Renderer, Subscription, Color, Element, Fill, Font, Point, Rectangle, Renderer, Subscription, Theme,
Theme,
}; };
use std::cell::RefCell; use std::cell::RefCell;
@ -37,10 +36,7 @@ impl TheMatrix {
} }
fn view(&self) -> Element<Message> { fn view(&self) -> Element<Message> {
canvas(self as &Self) canvas(self as &Self).width(Fill).height(Fill).into()
.width(Length::Fill)
.height(Length::Fill)
.into()
} }
fn subscription(&self) -> Subscription<Message> { fn subscription(&self) -> Subscription<Message> {

View file

@ -4,7 +4,7 @@ use iced::keyboard::key;
use iced::widget::{ use iced::widget::{
self, button, center, column, pick_list, row, slider, text, text_input, self, button, center, column, pick_list, row, slider, text, text_input,
}; };
use iced::{Element, Length, Subscription, Task}; use iced::{Center, Element, Fill, Subscription, Task};
use toast::{Status, Toast}; use toast::{Status, Toast};
@ -125,7 +125,7 @@ impl App {
Some(self.editing.status), Some(self.editing.status),
Message::Status Message::Status
) )
.width(Length::Fill) .width(Fill)
.into() .into()
), ),
subtitle( subtitle(
@ -142,7 +142,7 @@ impl App {
.spacing(5) .spacing(5)
.into() .into()
), ),
column![add_toast].center_x() column![add_toast].align_x(Center)
] ]
.spacing(10) .spacing(10)
.max_width(200), .max_width(200),
@ -177,8 +177,8 @@ mod toast {
}; };
use iced::window; use iced::window;
use iced::{ use iced::{
Alignment, Element, Length, Point, Rectangle, Renderer, Size, Theme, Alignment, Center, Element, Fill, Length, Point, Rectangle, Renderer,
Vector, Size, Theme, Vector,
}; };
pub const DEFAULT_TIMEOUT: u64 = 5; pub const DEFAULT_TIMEOUT: u64 = 5;
@ -245,9 +245,9 @@ mod toast {
.on_press((on_close)(index)) .on_press((on_close)(index))
.padding(3), .padding(3),
] ]
.center_y() .align_y(Center)
) )
.width(Length::Fill) .width(Fill)
.padding(5) .padding(5)
.style(match toast.status { .style(match toast.status {
Status::Primary => primary, Status::Primary => primary,
@ -257,7 +257,7 @@ mod toast {
}), }),
horizontal_rule(1), horizontal_rule(1),
container(text(toast.body.as_str())) container(text(toast.body.as_str()))
.width(Length::Fill) .width(Fill)
.padding(5) .padding(5)
.style(container::rounded_box), .style(container::rounded_box),
]) ])
@ -479,8 +479,8 @@ mod toast {
layout::flex::Axis::Vertical, layout::flex::Axis::Vertical,
renderer, renderer,
&limits, &limits,
Length::Fill, Fill,
Length::Fill, Fill,
10.into(), 10.into(),
10.0, 10.0,
Alignment::End, Alignment::End,

View file

@ -4,7 +4,7 @@ use iced::widget::{
scrollable, text, text_input, Text, scrollable, text, text_input, Text,
}; };
use iced::window; use iced::window;
use iced::{Element, Font, Length, Subscription, Task as Command}; use iced::{Center, Element, Fill, Font, Subscription, Task as Command};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -192,10 +192,10 @@ impl Todos {
.. ..
}) => { }) => {
let title = text("todos") let title = text("todos")
.width(Length::Fill) .width(Fill)
.size(100) .size(100)
.color([0.5, 0.5, 0.5]) .color([0.5, 0.5, 0.5])
.center_x(); .align_x(Center);
let input = text_input("What needs to be done?", input_value) let input = text_input("What needs to be done?", input_value)
.id(INPUT_ID.clone()) .id(INPUT_ID.clone())
@ -239,10 +239,7 @@ impl Todos {
.spacing(20) .spacing(20)
.max_width(800); .max_width(800);
scrollable( scrollable(container(content).center_x(Fill).padding(40)).into()
container(content).center_x(Length::Fill).padding(40),
)
.into()
} }
} }
} }
@ -342,7 +339,7 @@ impl Task {
TaskState::Idle => { TaskState::Idle => {
let checkbox = checkbox(&self.description, self.completed) let checkbox = checkbox(&self.description, self.completed)
.on_toggle(TaskMessage::Completed) .on_toggle(TaskMessage::Completed)
.width(Length::Fill) .width(Fill)
.size(17) .size(17)
.text_shaping(text::Shaping::Advanced); .text_shaping(text::Shaping::Advanced);
@ -354,7 +351,7 @@ impl Task {
.style(button::text), .style(button::text),
] ]
.spacing(20) .spacing(20)
.center_y() .align_y(Center)
.into() .into()
} }
TaskState::Editing => { TaskState::Editing => {
@ -368,14 +365,16 @@ impl Task {
row![ row![
text_input, text_input,
button( button(
row![delete_icon(), "Delete"].spacing(10).center_y() row![delete_icon(), "Delete"]
.spacing(10)
.align_y(Center)
) )
.on_press(TaskMessage::Delete) .on_press(TaskMessage::Delete)
.padding(10) .padding(10)
.style(button::danger) .style(button::danger)
] ]
.spacing(20) .spacing(20)
.center_y() .align_y(Center)
.into() .into()
} }
} }
@ -402,17 +401,16 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element<Message> {
"{tasks_left} {} left", "{tasks_left} {} left",
if tasks_left == 1 { "task" } else { "tasks" } if tasks_left == 1 { "task" } else { "tasks" }
) )
.width(Length::Fill), .width(Fill),
row![ row![
filter_button("All", Filter::All, current_filter), filter_button("All", Filter::All, current_filter),
filter_button("Active", Filter::Active, current_filter), filter_button("Active", Filter::Active, current_filter),
filter_button("Completed", Filter::Completed, current_filter,), filter_button("Completed", Filter::Completed, current_filter,),
] ]
.width(Length::Shrink)
.spacing(10) .spacing(10)
] ]
.spacing(20) .spacing(20)
.center_y() .align_y(Center)
.into() .into()
} }
@ -437,15 +435,15 @@ impl Filter {
} }
fn loading_message<'a>() -> Element<'a, Message> { fn loading_message<'a>() -> Element<'a, Message> {
center(text("Loading...").center_x().size(50)).into() center(text("Loading...").width(Fill).align_x(Center).size(50)).into()
} }
fn empty_message(message: &str) -> Element<'_, Message> { fn empty_message(message: &str) -> Element<'_, Message> {
center( center(
text(message) text(message)
.width(Length::Fill) .width(Fill)
.size(25) .size(25)
.center_x() .align_x(Center)
.color([0.7, 0.7, 0.7]), .color([0.7, 0.7, 0.7]),
) )
.height(200) .height(200)
@ -456,7 +454,10 @@ fn empty_message(message: &str) -> Element<'_, Message> {
const ICONS: Font = Font::with_name("Iced-Todos-Icons"); const ICONS: Font = Font::with_name("Iced-Todos-Icons");
fn icon(unicode: char) -> Text<'static> { fn icon(unicode: char) -> Text<'static> {
text(unicode.to_string()).font(ICONS).width(20).center_x() text(unicode.to_string())
.font(ICONS)
.width(20)
.align_x(Center)
} }
fn edit_icon() -> Text<'static> { fn edit_icon() -> Text<'static> {

View file

@ -3,7 +3,7 @@ use iced::widget::{
scrollable, slider, text, text_input, toggler, vertical_space, scrollable, slider, text, text_input, toggler, vertical_space,
}; };
use iced::widget::{Button, Column, Container, Slider}; use iced::widget::{Button, Column, Container, Slider};
use iced::{Color, Element, Font, Length, Pixels}; use iced::{Center, Color, Element, Fill, Font, Pixels};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -172,10 +172,10 @@ impl Tour {
} else { } else {
content content
}) })
.center_x(Length::Fill), .center_x(Fill),
); );
container(scrollable).center_y(Length::Fill).into() container(scrollable).center_y(Fill).into()
} }
fn can_continue(&self) -> bool { fn can_continue(&self) -> bool {
@ -234,7 +234,7 @@ impl Tour {
0 to 100:", 0 to 100:",
) )
.push(slider(0..=100, self.slider, Message::SliderChanged)) .push(slider(0..=100, self.slider, Message::SliderChanged))
.push(text(self.slider.to_string()).width(Length::Fill).center_x()) .push(text(self.slider.to_string()).width(Fill).align_x(Center))
} }
fn rows_and_columns(&self) -> Column<Message> { fn rows_and_columns(&self) -> Column<Message> {
@ -263,7 +263,7 @@ impl Tour {
let spacing_section = column![ let spacing_section = column![
slider(0..=80, self.spacing, Message::SpacingChanged), slider(0..=80, self.spacing, Message::SpacingChanged),
text!("{} px", self.spacing).width(Length::Fill).center_x(), text!("{} px", self.spacing).width(Fill).align_x(Center),
] ]
.spacing(10); .spacing(10);
@ -374,7 +374,7 @@ impl Tour {
.push("An image that tries to keep its aspect ratio.") .push("An image that tries to keep its aspect ratio.")
.push(ferris(width, filter_method)) .push(ferris(width, filter_method))
.push(slider(100..=500, width, Message::ImageWidthChanged)) .push(slider(100..=500, width, Message::ImageWidthChanged))
.push(text!("Width: {width} px").width(Length::Fill).center_x()) .push(text!("Width: {width} px").width(Fill).align_x(Center))
.push( .push(
checkbox( checkbox(
"Use nearest interpolation", "Use nearest interpolation",
@ -382,7 +382,7 @@ impl Tour {
) )
.on_toggle(Message::ImageUseNearestToggled), .on_toggle(Message::ImageUseNearestToggled),
) )
.center_x() .align_x(Center)
} }
fn scrollable(&self) -> Column<Message> { fn scrollable(&self) -> Column<Message> {
@ -398,13 +398,13 @@ impl Tour {
.push(vertical_space().height(4096)) .push(vertical_space().height(4096))
.push( .push(
text("You are halfway there!") text("You are halfway there!")
.width(Length::Fill) .width(Fill)
.size(30) .size(30)
.center_x(), .align_x(Center),
) )
.push(vertical_space().height(4096)) .push(vertical_space().height(4096))
.push(ferris(300, image::FilterMethod::Linear)) .push(ferris(300, image::FilterMethod::Linear))
.push(text("You made it!").width(Length::Fill).size(50).center_x()) .push(text("You made it!").width(Fill).size(50).align_x(Center))
} }
fn text_input(&self) -> Column<Message> { fn text_input(&self) -> Column<Message> {
@ -448,8 +448,8 @@ impl Tour {
} else { } else {
value value
}) })
.width(Length::Fill) .width(Fill)
.center_x(), .align_x(Center),
) )
} }
@ -554,7 +554,7 @@ fn ferris<'a>(
.filter_method(filter_method) .filter_method(filter_method)
.width(width), .width(width),
) )
.center_x(Length::Fill) .center_x(Fill)
} }
fn padded_button<Message: Clone>(label: &str) -> Button<'_, Message> { fn padded_button<Message: Clone>(label: &str) -> Button<'_, Message> {

View file

@ -3,7 +3,7 @@ use iced::mouse;
use iced::widget::{ use iced::widget::{
canvas, checkbox, column, horizontal_space, row, slider, text, canvas, checkbox, column, horizontal_space, row, slider, text,
}; };
use iced::{Element, Length, Point, Rectangle, Renderer, Theme, Vector}; use iced::{Center, Element, Fill, Point, Rectangle, Renderer, Theme, Vector};
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::application( iced::application(
@ -59,7 +59,7 @@ impl VectorialText {
}; };
column![ column![
canvas(&self.state).width(Length::Fill).height(Length::Fill), canvas(&self.state).width(Fill).height(Fill),
column![ column![
checkbox("Use Japanese", self.state.use_japanese,) checkbox("Use Japanese", self.state.use_japanese,)
.on_toggle(Message::ToggleJapanese), .on_toggle(Message::ToggleJapanese),
@ -85,7 +85,7 @@ impl VectorialText {
] ]
.spacing(20), .spacing(20),
] ]
.center_x() .align_x(Center)
.spacing(10) .spacing(10)
] ]
.spacing(10) .spacing(10)

View file

@ -5,7 +5,8 @@ use iced::widget::{
}; };
use iced::window; use iced::window;
use iced::{ use iced::{
Color, Element, Font, Length, Point, Rectangle, Subscription, Task, Theme, Center, Color, Element, Fill, Font, Point, Rectangle, Subscription, Task,
Theme,
}; };
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -69,7 +70,7 @@ impl Example {
.color_maybe(color), .color_maybe(color),
] ]
.height(40) .height(40)
.center_y() .align_y(Center)
}; };
let view_bounds = |label, bounds: Option<Rectangle>| { let view_bounds = |label, bounds: Option<Rectangle>| {
@ -129,13 +130,13 @@ impl Example {
.padding(20) .padding(20)
) )
.on_scroll(|_| Message::Scrolled) .on_scroll(|_| Message::Scrolled)
.width(Length::Fill) .width(Fill)
.height(300), .height(300),
] ]
.padding(20) .padding(20)
) )
.on_scroll(|_| Message::Scrolled) .on_scroll(|_| Message::Scrolled)
.width(Length::Fill) .width(Fill)
.height(300), .height(300),
] ]
.spacing(10) .spacing(10)

View file

@ -3,7 +3,7 @@ mod echo;
use iced::widget::{ use iced::widget::{
self, button, center, column, row, scrollable, text, text_input, self, button, center, column, row, scrollable, text, text_input,
}; };
use iced::{color, Element, Length, Subscription, Task}; use iced::{color, Center, Element, Fill, Subscription, Task};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
@ -103,7 +103,7 @@ impl WebSocket {
.spacing(10), .spacing(10),
) )
.id(MESSAGE_LOG.clone()) .id(MESSAGE_LOG.clone())
.height(Length::Fill) .height(Fill)
.into() .into()
}; };
@ -112,8 +112,8 @@ impl WebSocket {
.on_input(Message::NewMessageChanged) .on_input(Message::NewMessageChanged)
.padding(10); .padding(10);
let mut button = let mut button = button(text("Send").height(40).align_y(Center))
button(text("Send").height(40).center_y()).padding([0, 20]); .padding([0, 20]);
if matches!(self.state, State::Connected(_)) { if matches!(self.state, State::Connected(_)) {
if let Some(message) = echo::Message::new(&self.new_message) { if let Some(message) = echo::Message::new(&self.new_message) {
@ -122,11 +122,11 @@ impl WebSocket {
} }
} }
row![input, button].spacing(10).center_y() row![input, button].spacing(10).align_y(Center)
}; };
column![message_log, new_message_input] column![message_log, new_message_input]
.height(Length::Fill) .height(Fill)
.padding(20) .padding(20)
.spacing(10) .spacing(10)
.into() .into()

View file

@ -205,6 +205,11 @@ pub use crate::core::{
pub use crate::runtime::exit; pub use crate::runtime::exit;
pub use iced_futures::Subscription; pub use iced_futures::Subscription;
pub use alignment::Horizontal::{Left, Right};
pub use alignment::Vertical::{Bottom, Top};
pub use Alignment::Center;
pub use Length::{Fill, FillPortion, Shrink};
pub mod task { pub mod task {
//! Create runtime tasks. //! Create runtime tasks.
pub use crate::runtime::task::{Handle, Task}; pub use crate::runtime::task::{Handle, Task};

View file

@ -104,21 +104,6 @@ where
self self
} }
/// Centers the contents of the [`Column`] horizontally.
pub fn center_x(self) -> Self {
self.align_x(Alignment::Center)
}
/// Aligns the contents of the [`Column`] to the left.
pub fn align_left(self) -> Self {
self.align_x(alignment::left())
}
/// Aligns the contents of the [`Column`] to the right.
pub fn align_right(self) -> Self {
self.align_x(alignment::right())
}
/// Sets the horizontal alignment of the contents of the [`Column`] . /// Sets the horizontal alignment of the contents of the [`Column`] .
pub fn align_x(mut self, align: impl Into<alignment::Horizontal>) -> Self { pub fn align_x(mut self, align: impl Into<alignment::Horizontal>) -> Self {
self.align = Alignment::from(align.into()); self.align = Alignment::from(align.into());

View file

@ -92,37 +92,6 @@ where
self self
} }
/// Sets the [`Container`] to fill the available space in the horizontal axis.
///
/// Calling this method is equivalent to calling [`width`] with a
/// [`Length::Fill`].
///
/// [`width`]: Self::width
pub fn fill_x(self) -> Self {
self.width(Length::Fill)
}
/// Sets the [`Container`] to fill the available space in the vertical axis.
///
/// Calling this method is equivalent to calling [`height`] with a
/// [`Length::Fill`].
///
/// [`height`]: Self::height
pub fn fill_y(self) -> Self {
self.height(Length::Fill)
}
/// Sets the [`Container`] to fill all the available space.
///
/// Calling this method is equivalent to chaining [`fill_x`] and
/// [`fill_y`].
///
/// [`fill_x`]: Self::fill_x
/// [`fill_y`]: Self::fill_y
pub fn fill(self) -> Self {
self.width(Length::Fill).height(Length::Fill)
}
/// Sets the maximum width of the [`Container`]. /// Sets the maximum width of the [`Container`].
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self { pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
self.max_width = max_width.into().0; self.max_width = max_width.into().0;
@ -159,23 +128,23 @@ where
} }
/// Aligns the contents of the [`Container`] to the left. /// Aligns the contents of the [`Container`] to the left.
pub fn align_left(self) -> Self { pub fn align_left(self, width: impl Into<Length>) -> Self {
self.align_x(alignment::left()) self.width(width).align_x(alignment::Horizontal::Left)
} }
/// Aligns the contents of the [`Container`] to the right. /// Aligns the contents of the [`Container`] to the right.
pub fn align_right(self) -> Self { pub fn align_right(self, width: impl Into<Length>) -> Self {
self.align_x(alignment::right()) self.width(width).align_x(alignment::Horizontal::Right)
} }
/// Aligns the contents of the [`Container`] to the top. /// Aligns the contents of the [`Container`] to the top.
pub fn align_top(self) -> Self { pub fn align_top(self, height: Length) -> Self {
self.align_y(alignment::top()) self.height(height).align_y(alignment::Vertical::Top)
} }
/// Aligns the contents of the [`Container`] to the bottom. /// Aligns the contents of the [`Container`] to the bottom.
pub fn align_bottom(self) -> Self { pub fn align_bottom(self, height: Length) -> Self {
self.align_y(alignment::bottom()) self.height(height).align_y(alignment::Vertical::Bottom)
} }
/// Sets the content alignment for the horizontal axis of the [`Container`]. /// Sets the content alignment for the horizontal axis of the [`Container`].

View file

@ -906,7 +906,7 @@ where
+ 'a, + 'a,
Theme: text::Catalog + crate::svg::Catalog + 'a, Theme: text::Catalog + crate::svg::Catalog + 'a,
{ {
use crate::core::Font; use crate::core::{Alignment, Font};
use crate::svg; use crate::svg;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -921,7 +921,7 @@ where
text("iced").size(text_size).font(Font::MONOSPACE) text("iced").size(text_size).font(Font::MONOSPACE)
] ]
.spacing(text_size.0 / 3.0) .spacing(text_size.0 / 3.0)
.center_y() .align_y(Alignment::Center)
.into() .into()
} }

View file

@ -95,21 +95,6 @@ where
self self
} }
/// Centers the contents of the [`Row`] vertically.
pub fn center_y(self) -> Self {
self.align_y(Alignment::Center)
}
/// Aligns the contents of the [`Row`] to the top.
pub fn align_top(self) -> Self {
self.align_y(alignment::top())
}
/// Aligns the contents of the [`Row`] to the bottom.
pub fn align_bottom(self) -> Self {
self.align_y(alignment::bottom())
}
/// Sets the vertical alignment of the contents of the [`Row`] . /// Sets the vertical alignment of the contents of the [`Row`] .
pub fn align_y(mut self, align: impl Into<alignment::Vertical>) -> Self { pub fn align_y(mut self, align: impl Into<alignment::Vertical>) -> Self {
self.align = Alignment::from(align.into()); self.align = Alignment::from(align.into());