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.
/// 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.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Alignment {

View file

@ -88,37 +88,8 @@ where
/// Centers the [`Text`], both horizontally and vertically.
pub fn center(self) -> Self {
self.center_x().center_y()
}
/// 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())
self.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
}
/// Sets the [`alignment::Horizontal`] of the [`Text`].

View file

@ -4,7 +4,7 @@ use iced::mouse;
use iced::widget::canvas::{
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 {
iced::application("Arc - Iced", Arc::update, Arc::view)
@ -30,10 +30,7 @@ impl Arc {
}
fn view(&self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
.into()
Canvas::new(self).width(Fill).height(Fill).into()
}
fn subscription(&self) -> Subscription<Message> {

View file

@ -1,6 +1,6 @@
//! This example showcases an interactive `Canvas` for drawing Bézier curves.
use iced::widget::{button, container, horizontal_space, hover};
use iced::{Element, Length, Theme};
use iced::{Element, Fill, Theme};
pub fn main() -> iced::Result {
iced::application("Bezier Tool - Iced", Example::update, Example::view)
@ -47,8 +47,7 @@ impl Example {
.on_press(Message::Clear),
)
.padding(10)
.width(Length::Fill)
.align_right()
.align_right(Fill)
},
))
.padding(20)
@ -60,7 +59,7 @@ mod bezier {
use iced::mouse;
use iced::widget::canvas::event::{self, Event};
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)]
pub struct State {
@ -73,8 +72,8 @@ mod bezier {
state: self,
curves,
})
.width(Length::Fill)
.height(Length::Fill)
.width(Fill)
.height(Fill)
.into()
}

View file

@ -4,7 +4,7 @@ use iced::time;
use iced::widget::canvas::{stroke, Cache, Geometry, LineCap, Path, Stroke};
use iced::widget::{canvas, container};
use iced::{
Degrees, Element, Font, Length, Point, Rectangle, Renderer, Subscription,
Degrees, Element, Fill, Font, Point, Rectangle, Renderer, Subscription,
Theme, Vector,
};
@ -43,15 +43,9 @@ impl Clock {
}
fn view(&self) -> Element<Message> {
let canvas = canvas(self as &Self)
.width(Length::Fill)
.height(Length::Fill);
let canvas = canvas(self as &Self).width(Fill).height(Fill);
container(canvas)
.width(Length::Fill)
.height(Length::Fill)
.padding(20)
.into()
container(canvas).padding(20).into()
}
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::{column, row, text, Slider};
use iced::{
Color, Element, Font, Length, Pixels, Point, Rectangle, Renderer, Size,
Vector,
Center, Color, Element, Fill, Font, Pixels, Point, Rectangle, Renderer,
Size, Vector,
};
use palette::{convert::FromColor, rgb::Rgb, Darken, Hsl, Lighten, ShiftHue};
use std::marker::PhantomData;
@ -150,10 +150,7 @@ impl Theme {
}
pub fn view(&self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
.into()
Canvas::new(self).width(Fill).height(Fill).into()
}
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),
]
.spacing(10)
.center_y()
.align_y(Center)
.into()
}
}

View file

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

View file

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

View file

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

View file

@ -82,7 +82,7 @@ mod quad {
}
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 {
iced::run("Custom Quad - Iced", Example::update, Example::view)
@ -185,7 +185,7 @@ impl Example {
.padding(20)
.spacing(20)
.max_width(500)
.center_x();
.align_x(Center);
center(content).into()
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
use iced_wgpu::Renderer;
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};
pub struct Controls {
@ -85,8 +85,7 @@ impl Program for Controls {
.spacing(10),
)
.padding(10)
.height(Length::Fill)
.align_bottom()
.align_bottom(Fill)
.into()
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,7 @@ use iced::widget::{
self, button, center, column, container, horizontal_space, mouse_area,
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;
@ -96,17 +96,17 @@ impl App {
let content = container(
column![
row![text("Top Left"), horizontal_space(), text("Top Right")]
.height(Length::Fill),
.height(Fill),
center(button(text("Show Modal")).on_press(Message::ShowModal)),
row![
text("Bottom Left"),
horizontal_space(),
text("Bottom Right")
]
.align_bottom()
.height(Length::Fill),
.align_y(Bottom)
.height(Fill),
]
.height(Length::Fill),
.height(Fill),
)
.padding(10);

View file

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

View file

@ -6,7 +6,7 @@ use iced::touch;
use iced::widget::canvas::event;
use iced::widget::canvas::stroke::{self, Stroke};
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;
@ -46,10 +46,7 @@ impl Multitouch {
}
fn view(&self) -> Element<Message> {
Canvas::new(self)
.width(Length::Fill)
.height(Length::Fill)
.into()
Canvas::new(self).width(Fill).height(Fill).into()
}
}

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
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 {
iced::application(
@ -58,7 +58,7 @@ impl QRGenerator {
pick_list(Theme::ALL, Some(&self.theme), Message::ThemeChanged,)
]
.spacing(10)
.center_y();
.align_y(Center);
let content = column![title, input, choose_theme]
.push_maybe(
@ -68,7 +68,7 @@ impl QRGenerator {
)
.width(700)
.spacing(20)
.center_x();
.align_x(Center);
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::window;
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::ColorType;
@ -111,15 +114,15 @@ impl Example {
screenshot.clone(),
))
.content_fit(ContentFit::Contain)
.width(Length::Fill)
.height(Length::Fill)
.width(Fill)
.height(Fill)
.into()
} else {
text("Press the button to take a screenshot!").into()
};
let image = container(image)
.center_y(Length::FillPortion(2))
.center_y(FillPortion(2))
.padding(10)
.style(container::rounded_box);
@ -130,7 +133,7 @@ impl Example {
numeric_input("0", self.y_input_value).map(Message::YInputChanged)
]
.spacing(10)
.center_y();
.align_y(Center);
let crop_dimension_controls = row![
text("W:").width(30),
@ -141,7 +144,7 @@ impl Example {
.map(Message::HeightInputChanged)
]
.spacing(10)
.center_y();
.align_y(Center);
let crop_controls =
column![crop_origin_controls, crop_dimension_controls]
@ -151,7 +154,7 @@ impl Example {
.map(|error| text!("Crop error! \n{error}")),
)
.spacing(10)
.center_x();
.align_x(Center);
let controls = {
let save_result =
@ -168,7 +171,7 @@ impl Example {
column![
button(centered_text("Screenshot!"))
.padding([10, 20, 10, 20])
.width(Length::Fill)
.width(Fill)
.on_press(Message::Screenshot),
if !self.png_saving {
button(centered_text("Save as png")).on_press_maybe(
@ -180,7 +183,7 @@ impl Example {
}
.style(button::secondary)
.padding([10, 20, 10, 20])
.width(Length::Fill)
.width(Fill)
]
.spacing(10),
column![
@ -189,22 +192,22 @@ impl Example {
.on_press(Message::Crop)
.style(button::danger)
.padding([10, 20, 10, 20])
.width(Length::Fill),
.width(Fill),
]
.spacing(10)
.center_x(),
.align_x(Center),
]
.push_maybe(save_result.map(text))
.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]
.spacing(10)
.width(Length::Fill)
.height(Length::Fill)
.center_y();
.width(Fill)
.height(Fill)
.align_y(Center);
container(content).padding(10).into()
}
@ -265,5 +268,5 @@ fn numeric_input(
}
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,
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;
@ -212,7 +212,7 @@ impl ScrollableDemo {
text("End!"),
scroll_to_beginning_button(),
]
.center_x()
.align_x(Center)
.padding([40, 0, 40, 0])
.spacing(40),
)
@ -223,8 +223,8 @@ impl ScrollableDemo {
.scroller_width(self.scroller_width)
.anchor(self.anchor),
))
.width(Length::Fill)
.height(Length::Fill)
.width(Fill)
.height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
Direction::Horizontal => scrollable(
@ -238,7 +238,7 @@ impl ScrollableDemo {
scroll_to_beginning_button(),
]
.height(450)
.center_y()
.align_y(Center)
.padding([0, 40, 0, 40])
.spacing(40),
)
@ -249,8 +249,8 @@ impl ScrollableDemo {
.scroller_width(self.scroller_width)
.anchor(self.anchor),
))
.width(Length::Fill)
.height(Length::Fill)
.width(Fill)
.height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
Direction::Multi => scrollable(
@ -280,7 +280,7 @@ impl ScrollableDemo {
text("Horizontal - End!"),
scroll_to_beginning_button(),
]
.center_y()
.align_y(Center)
.padding([0, 40, 0, 40])
.spacing(40),
)
@ -296,8 +296,8 @@ impl ScrollableDemo {
vertical: scrollbar,
}
})
.width(Length::Fill)
.height(Length::Fill)
.width(Fill)
.height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
});
@ -322,7 +322,7 @@ impl ScrollableDemo {
let content: Element<Message> =
column![scroll_controls, scrollable_content, progress_bars]
.center_x()
.align_x(Center)
.spacing(10)
.into();

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
use iced::keyboard;
use iced::time;
use iced::widget::{button, center, column, row, text};
use iced::{Element, Subscription, Theme};
use iced::{Center, Element, Subscription, Theme};
use std::time::{Duration, Instant};
@ -101,7 +101,7 @@ impl Stopwatch {
.size(40);
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 label = match self.state {
@ -118,7 +118,7 @@ impl Stopwatch {
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()
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@ use iced::widget::{
scrollable, slider, text, text_input, toggler, vertical_space,
};
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 {
#[cfg(target_arch = "wasm32")]
@ -172,10 +172,10 @@ impl Tour {
} else {
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 {
@ -234,7 +234,7 @@ impl Tour {
0 to 100:",
)
.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> {
@ -263,7 +263,7 @@ impl Tour {
let spacing_section = column![
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);
@ -374,7 +374,7 @@ impl Tour {
.push("An image that tries to keep its aspect ratio.")
.push(ferris(width, filter_method))
.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(
checkbox(
"Use nearest interpolation",
@ -382,7 +382,7 @@ impl Tour {
)
.on_toggle(Message::ImageUseNearestToggled),
)
.center_x()
.align_x(Center)
}
fn scrollable(&self) -> Column<Message> {
@ -398,13 +398,13 @@ impl Tour {
.push(vertical_space().height(4096))
.push(
text("You are halfway there!")
.width(Length::Fill)
.width(Fill)
.size(30)
.center_x(),
.align_x(Center),
)
.push(vertical_space().height(4096))
.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> {
@ -448,8 +448,8 @@ impl Tour {
} else {
value
})
.width(Length::Fill)
.center_x(),
.width(Fill)
.align_x(Center),
)
}
@ -554,7 +554,7 @@ fn ferris<'a>(
.filter_method(filter_method)
.width(width),
)
.center_x(Length::Fill)
.center_x(Fill)
}
fn padded_button<Message: Clone>(label: &str) -> Button<'_, Message> {

View file

@ -3,7 +3,7 @@ use iced::mouse;
use iced::widget::{
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 {
iced::application(
@ -59,7 +59,7 @@ impl VectorialText {
};
column![
canvas(&self.state).width(Length::Fill).height(Length::Fill),
canvas(&self.state).width(Fill).height(Fill),
column![
checkbox("Use Japanese", self.state.use_japanese,)
.on_toggle(Message::ToggleJapanese),
@ -85,7 +85,7 @@ impl VectorialText {
]
.spacing(20),
]
.center_x()
.align_x(Center)
.spacing(10)
]
.spacing(10)

View file

@ -5,7 +5,8 @@ use iced::widget::{
};
use iced::window;
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 {
@ -69,7 +70,7 @@ impl Example {
.color_maybe(color),
]
.height(40)
.center_y()
.align_y(Center)
};
let view_bounds = |label, bounds: Option<Rectangle>| {
@ -129,13 +130,13 @@ impl Example {
.padding(20)
)
.on_scroll(|_| Message::Scrolled)
.width(Length::Fill)
.width(Fill)
.height(300),
]
.padding(20)
)
.on_scroll(|_| Message::Scrolled)
.width(Length::Fill)
.width(Fill)
.height(300),
]
.spacing(10)

View file

@ -3,7 +3,7 @@ mod echo;
use iced::widget::{
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;
pub fn main() -> iced::Result {
@ -103,7 +103,7 @@ impl WebSocket {
.spacing(10),
)
.id(MESSAGE_LOG.clone())
.height(Length::Fill)
.height(Fill)
.into()
};
@ -112,8 +112,8 @@ impl WebSocket {
.on_input(Message::NewMessageChanged)
.padding(10);
let mut button =
button(text("Send").height(40).center_y()).padding([0, 20]);
let mut button = button(text("Send").height(40).align_y(Center))
.padding([0, 20]);
if matches!(self.state, State::Connected(_)) {
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]
.height(Length::Fill)
.height(Fill)
.padding(20)
.spacing(10)
.into()

View file

@ -205,6 +205,11 @@ pub use crate::core::{
pub use crate::runtime::exit;
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 {
//! Create runtime tasks.
pub use crate::runtime::task::{Handle, Task};

View file

@ -104,21 +104,6 @@ where
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`] .
pub fn align_x(mut self, align: impl Into<alignment::Horizontal>) -> Self {
self.align = Alignment::from(align.into());

View file

@ -92,37 +92,6 @@ where
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`].
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
self.max_width = max_width.into().0;
@ -159,23 +128,23 @@ where
}
/// Aligns the contents of the [`Container`] to the left.
pub fn align_left(self) -> Self {
self.align_x(alignment::left())
pub fn align_left(self, width: impl Into<Length>) -> Self {
self.width(width).align_x(alignment::Horizontal::Left)
}
/// Aligns the contents of the [`Container`] to the right.
pub fn align_right(self) -> Self {
self.align_x(alignment::right())
pub fn align_right(self, width: impl Into<Length>) -> Self {
self.width(width).align_x(alignment::Horizontal::Right)
}
/// Aligns the contents of the [`Container`] to the top.
pub fn align_top(self) -> Self {
self.align_y(alignment::top())
pub fn align_top(self, height: Length) -> Self {
self.height(height).align_y(alignment::Vertical::Top)
}
/// Aligns the contents of the [`Container`] to the bottom.
pub fn align_bottom(self) -> Self {
self.align_y(alignment::bottom())
pub fn align_bottom(self, height: Length) -> Self {
self.height(height).align_y(alignment::Vertical::Bottom)
}
/// Sets the content alignment for the horizontal axis of the [`Container`].

View file

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

View file

@ -95,21 +95,6 @@ where
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`] .
pub fn align_y(mut self, align: impl Into<alignment::Vertical>) -> Self {
self.align = Alignment::from(align.into());