Introduce helper methods for alignment for all widgets
This commit is contained in:
parent
be06060117
commit
f9dd5cbb09
45 changed files with 380 additions and 282 deletions
|
|
@ -1,5 +1,4 @@
|
|||
//! This example showcases an interactive `Canvas` for drawing Bézier curves.
|
||||
use iced::alignment;
|
||||
use iced::widget::{button, container, horizontal_space, hover};
|
||||
use iced::{Element, Length, Theme};
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ impl Example {
|
|||
)
|
||||
.padding(10)
|
||||
.width(Length::Fill)
|
||||
.align_x(alignment::Horizontal::Right)
|
||||
.align_right()
|
||||
},
|
||||
))
|
||||
.padding(20)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use iced::alignment::{self, Alignment};
|
||||
use iced::alignment;
|
||||
use iced::mouse;
|
||||
use iced::widget::canvas::{self, Canvas, Frame, Geometry, Path};
|
||||
use iced::widget::{column, row, text, Slider};
|
||||
|
|
@ -320,7 +320,7 @@ impl<C: ColorSpace + Copy> ColorPicker<C> {
|
|||
text(color.to_string()).width(185).size(12),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use iced::widget::{
|
||||
center, column, combo_box, scrollable, text, vertical_space,
|
||||
};
|
||||
use iced::{Alignment, Element, Length};
|
||||
use iced::{Element, Length};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::run("Combo Box - Iced", Example::update, Example::view)
|
||||
|
|
@ -65,7 +65,7 @@ impl Example {
|
|||
vertical_space().height(150),
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(10);
|
||||
|
||||
center(scrollable(content)).into()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ impl Component {
|
|||
}
|
||||
|
||||
mod numeric_input {
|
||||
use iced::alignment::{self, Alignment};
|
||||
use iced::widget::{button, component, row, text, text_input, Component};
|
||||
use iced::{Element, Length, Size};
|
||||
|
||||
|
|
@ -108,8 +107,7 @@ mod numeric_input {
|
|||
text(label)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.vertical_alignment(alignment::Vertical::Center),
|
||||
.center(),
|
||||
)
|
||||
.width(40)
|
||||
.height(40)
|
||||
|
|
@ -130,7 +128,7 @@ mod numeric_input {
|
|||
.padding(10),
|
||||
button("+", Event::IncrementPressed),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use iced::widget::{button, column, text, Column};
|
||||
use iced::Alignment;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::run("A cool counter", Counter::update, Counter::view)
|
||||
|
|
@ -35,6 +34,6 @@ impl Counter {
|
|||
button("Decrement").on_press(Message::Decrement)
|
||||
]
|
||||
.padding(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ mod quad {
|
|||
}
|
||||
|
||||
use iced::widget::{center, column, slider, text};
|
||||
use iced::{Alignment, Color, Element, Shadow, Vector};
|
||||
use iced::{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)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
center(content).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::{Alignment, Color, Element, Length, Subscription};
|
||||
use iced::{Color, Element, Length, Subscription};
|
||||
|
||||
fn main() -> iced::Result {
|
||||
iced::application(
|
||||
|
|
@ -122,12 +122,12 @@ impl IcedCubes {
|
|||
let controls = column![top_controls, bottom_controls,]
|
||||
.spacing(10)
|
||||
.padding(20)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
let shader =
|
||||
shader(&self.scene).width(Length::Fill).height(Length::Fill);
|
||||
|
||||
center(column![shader, controls].align_items(Alignment::Center)).into()
|
||||
center(column![shader, controls].center_x()).into()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ mod circle {
|
|||
|
||||
use circle::circle;
|
||||
use iced::widget::{center, column, slider, text};
|
||||
use iced::{Alignment, Element};
|
||||
use iced::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)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
center(content).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
mod download;
|
||||
|
||||
use iced::widget::{button, center, column, progress_bar, text, Column};
|
||||
use iced::{Alignment, Element, Subscription};
|
||||
use iced::{Element, Subscription};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application(
|
||||
|
|
@ -69,7 +69,7 @@ impl Example {
|
|||
.padding(10),
|
||||
)
|
||||
.spacing(20)
|
||||
.align_items(Alignment::End);
|
||||
.align_right();
|
||||
|
||||
center(downloads).padding(20).into()
|
||||
}
|
||||
|
|
@ -160,7 +160,7 @@ impl Download {
|
|||
State::Finished => {
|
||||
column!["Download finished!", button("Start again")]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.into()
|
||||
}
|
||||
State::Downloading { .. } => {
|
||||
|
|
@ -171,14 +171,14 @@ impl Download {
|
|||
button("Try again").on_press(Message::Download(self.id)),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.into(),
|
||||
};
|
||||
|
||||
Column::new()
|
||||
.spacing(10)
|
||||
.padding(10)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.push(progress_bar)
|
||||
.push(control)
|
||||
.into()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use iced::widget::{
|
|||
button, column, container, horizontal_space, pick_list, row, text,
|
||||
text_editor, tooltip,
|
||||
};
|
||||
use iced::{Alignment, Element, Font, Length, Subscription, Task, Theme};
|
||||
use iced::{Element, Font, Length, Subscription, Task, Theme};
|
||||
|
||||
use std::ffi;
|
||||
use std::io;
|
||||
|
|
@ -158,7 +158,7 @@ impl Editor {
|
|||
.padding([5, 10])
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
let status = row![
|
||||
text(if let Some(path) = &self.file {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use iced::alignment;
|
||||
use iced::event::{self, Event};
|
||||
use iced::widget::{button, center, checkbox, text, Column};
|
||||
use iced::window;
|
||||
use iced::{Alignment, Element, Length, Subscription, Task};
|
||||
use iced::{Element, Length, Subscription, Task};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application("Events - Iced", Events::update, Events::view)
|
||||
|
|
@ -67,17 +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)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.width(100)
|
||||
.padding(10)
|
||||
.on_press(Message::Exit);
|
||||
let exit = button(text("Exit").width(Length::Fill).center_x())
|
||||
.width(100)
|
||||
.padding(10)
|
||||
.on_press(Message::Exit);
|
||||
|
||||
let content = Column::new()
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(20)
|
||||
.push(events)
|
||||
.push(toggle)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use iced::widget::{button, center, column};
|
||||
use iced::window;
|
||||
use iced::{Alignment, Element, Task};
|
||||
use iced::{Element, Task};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application("Exit - Iced", Exit::update, Exit::view).run()
|
||||
|
|
@ -44,7 +44,7 @@ impl Exit {
|
|||
]
|
||||
}
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
center(content).padding(20).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use iced::widget::{
|
|||
};
|
||||
use iced::window;
|
||||
use iced::{
|
||||
Alignment, Color, ContentFit, Degrees, Element, Length, Radians, Rotation,
|
||||
Color, ContentFit, Degrees, Element, Length, Radians, Rotation,
|
||||
Subscription, Theme,
|
||||
};
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ impl Image {
|
|||
"I am Ferris!"
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
let fit = row![
|
||||
pick_list(
|
||||
|
|
@ -134,7 +134,7 @@ impl Image {
|
|||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::End);
|
||||
.align_bottom();
|
||||
|
||||
let properties = row![
|
||||
with_value(
|
||||
|
|
@ -159,12 +159,12 @@ impl Image {
|
|||
.size(12)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center),
|
||||
.center_y(),
|
||||
format!("Rotation: {:.0}°", f32::from(self.rotation.degrees()))
|
||||
)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::End);
|
||||
.align_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)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use iced::time;
|
|||
use iced::widget::{
|
||||
button, checkbox, column, container, pick_list, row, slider, text,
|
||||
};
|
||||
use iced::{Alignment, Element, Length, Subscription, Task, Theme};
|
||||
use iced::{Element, Length, Subscription, Task, Theme};
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
|
|
@ -169,7 +169,7 @@ fn view_controls<'a>(
|
|||
slider(1.0..=1000.0, speed as f32, Message::SpeedChanged),
|
||||
text!("x{speed}").size(16),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.spacing(10);
|
||||
|
||||
row![
|
||||
|
|
@ -186,7 +186,7 @@ fn view_controls<'a>(
|
|||
]
|
||||
.padding(10)
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use iced::gradient;
|
|||
use iced::widget::{
|
||||
checkbox, column, container, horizontal_space, row, slider, text,
|
||||
};
|
||||
use iced::{Alignment, Color, Element, Length, Radians, Theme};
|
||||
use iced::{Color, Element, Length, Radians, Theme};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
|
@ -77,7 +77,7 @@ impl Gradient {
|
|||
]
|
||||
.spacing(8)
|
||||
.padding(8)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
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)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use iced_wgpu::Renderer;
|
||||
use iced_widget::{column, container, row, slider, text, text_input};
|
||||
use iced_winit::core::alignment;
|
||||
use iced_winit::core::{Color, Element, Length, Theme};
|
||||
use iced_winit::runtime::{Program, Task};
|
||||
|
||||
|
|
@ -87,7 +86,7 @@ impl Program for Controls {
|
|||
)
|
||||
.padding(10)
|
||||
.height(Length::Fill)
|
||||
.align_y(alignment::Vertical::Bottom)
|
||||
.align_bottom()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ use iced::widget::{
|
|||
pick_list, row, scrollable, text,
|
||||
};
|
||||
use iced::{
|
||||
color, Alignment, Element, Font, Length, Point, Rectangle, Renderer,
|
||||
Subscription, Theme,
|
||||
color, Element, 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)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
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)
|
||||
.align_items(Alignment::Center),
|
||||
.center_y(),
|
||||
)
|
||||
.style(|theme| {
|
||||
let palette = theme.extended_palette();
|
||||
|
|
@ -248,7 +248,7 @@ fn application<'a>() -> Element<'a, Message> {
|
|||
.spacing(40)
|
||||
.padding(10)
|
||||
.width(200)
|
||||
.align_items(Alignment::Center),
|
||||
.center_x(),
|
||||
)
|
||||
.style(container::rounded_box)
|
||||
.center_y(Length::Fill);
|
||||
|
|
@ -263,7 +263,7 @@ fn application<'a>() -> Element<'a, Message> {
|
|||
"The end"
|
||||
]
|
||||
.spacing(40)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.width(Length::Fill),
|
||||
)
|
||||
.height(Length::Fill),
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl LoadingSpinners {
|
|||
Duration::from_secs_f32(self.cycle_duration)
|
||||
)
|
||||
]
|
||||
.align_items(iced::Alignment::Center)
|
||||
.center_y()
|
||||
.spacing(20.0),
|
||||
)
|
||||
})
|
||||
|
|
@ -83,7 +83,7 @@ impl LoadingSpinners {
|
|||
.width(200.0),
|
||||
text!("{:.2}s", self.cycle_duration),
|
||||
]
|
||||
.align_items(iced::Alignment::Center)
|
||||
.center_y()
|
||||
.spacing(20.0),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use iced::widget::{button, center, column, text};
|
||||
use iced::{Alignment, Element};
|
||||
use iced::Element;
|
||||
|
||||
use loupe::loupe;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ impl Loupe {
|
|||
button("Decrement").on_press(Message::Decrement)
|
||||
]
|
||||
.padding(20)
|
||||
.align_items(Alignment::Center),
|
||||
.center_x(),
|
||||
))
|
||||
.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::{Alignment, Color, Element, Length, Subscription, Task};
|
||||
use iced::{Color, Element, Length, Subscription, Task};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
|
@ -96,7 +96,6 @@ impl App {
|
|||
let content = container(
|
||||
column![
|
||||
row![text("Top Left"), horizontal_space(), text("Top Right")]
|
||||
.align_items(Alignment::Start)
|
||||
.height(Length::Fill),
|
||||
center(button(text("Show Modal")).on_press(Message::ShowModal)),
|
||||
row![
|
||||
|
|
@ -104,7 +103,7 @@ impl App {
|
|||
horizontal_space(),
|
||||
text("Bottom Right")
|
||||
]
|
||||
.align_items(Alignment::End)
|
||||
.align_bottom()
|
||||
.height(Length::Fill),
|
||||
]
|
||||
.height(Length::Fill),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use iced::widget::{
|
|||
text_input,
|
||||
};
|
||||
use iced::window;
|
||||
use iced::{Alignment, Element, Length, Subscription, Task, Theme, Vector};
|
||||
use iced::{Element, Length, Subscription, Task, Theme, Vector};
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ impl Window {
|
|||
column![scale_input, title_input, new_window_button]
|
||||
.spacing(50)
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center),
|
||||
.center_x(),
|
||||
);
|
||||
|
||||
container(content).center_x(200).into()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use iced::alignment::{self, Alignment};
|
||||
use iced::keyboard;
|
||||
use iced::widget::pane_grid::{self, PaneGrid};
|
||||
use iced::widget::{
|
||||
|
|
@ -255,15 +254,10 @@ fn view_content<'a>(
|
|||
size: Size,
|
||||
) -> Element<'a, Message> {
|
||||
let button = |label, message| {
|
||||
button(
|
||||
text(label)
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.size(16),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.padding(8)
|
||||
.on_press(message)
|
||||
button(text(label).width(Length::Fill).center_x().size(16))
|
||||
.width(Length::Fill)
|
||||
.padding(8)
|
||||
.on_press(message)
|
||||
};
|
||||
|
||||
let controls = column![
|
||||
|
|
@ -287,7 +281,7 @@ fn view_content<'a>(
|
|||
let content =
|
||||
column![text!("{}x{}", size.width, size.height).size(24), controls,]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
container(scrollable(content))
|
||||
.center_y(Length::Fill)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use iced::widget::{column, pick_list, scrollable, vertical_space};
|
||||
use iced::{Alignment, Element, Length};
|
||||
use iced::{Element, Length};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::run("Pick List - Iced", Example::update, Example::view)
|
||||
|
|
@ -39,7 +39,7 @@ impl Example {
|
|||
vertical_space().height(600),
|
||||
]
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(10);
|
||||
|
||||
scrollable(content).into()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use iced::futures;
|
||||
use iced::widget::{self, center, column, image, row, text};
|
||||
use iced::{Alignment, Element, Length, Task};
|
||||
use iced::{Element, Length, Task};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application(Pokedex::title, Pokedex::update, Pokedex::view)
|
||||
|
|
@ -74,13 +74,13 @@ impl Pokedex {
|
|||
]
|
||||
.max_width(500)
|
||||
.spacing(20)
|
||||
.align_items(Alignment::End),
|
||||
.align_right(),
|
||||
Pokedex::Errored => column![
|
||||
text("Whoops! Something went wrong...").size(40),
|
||||
button("Try again").on_press(Message::Search)
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::End),
|
||||
.align_right(),
|
||||
};
|
||||
|
||||
center(content).into()
|
||||
|
|
@ -106,14 +106,14 @@ impl Pokemon {
|
|||
text(&self.name).size(30).width(Length::Fill),
|
||||
text!("#{}", self.number).size(20).color([0.5, 0.5, 0.5]),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.spacing(20),
|
||||
self.description.as_ref(),
|
||||
]
|
||||
.spacing(20),
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use iced::widget::{center, column, pick_list, qr_code, row, text, text_input};
|
||||
use iced::{Alignment, Element, Theme};
|
||||
use iced::{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)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
let content = column![title, input, choose_theme]
|
||||
.push_maybe(
|
||||
|
|
@ -68,7 +68,7 @@ impl QRGenerator {
|
|||
)
|
||||
.width(700)
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
center(content).padding(20).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
use iced::alignment;
|
||||
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::{
|
||||
Alignment, ContentFit, Element, Length, Rectangle, Subscription, Task,
|
||||
};
|
||||
use iced::{ContentFit, Element, Length, Rectangle, Subscription, Task};
|
||||
|
||||
use ::image as img;
|
||||
use ::image::ColorType;
|
||||
|
|
@ -127,32 +124,24 @@ impl Example {
|
|||
.style(container::rounded_box);
|
||||
|
||||
let crop_origin_controls = row![
|
||||
text("X:")
|
||||
.vertical_alignment(alignment::Vertical::Center)
|
||||
.width(30),
|
||||
text("X:").width(30),
|
||||
numeric_input("0", self.x_input_value).map(Message::XInputChanged),
|
||||
text("Y:")
|
||||
.vertical_alignment(alignment::Vertical::Center)
|
||||
.width(30),
|
||||
text("Y:").width(30),
|
||||
numeric_input("0", self.y_input_value).map(Message::YInputChanged)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
let crop_dimension_controls = row![
|
||||
text("W:")
|
||||
.vertical_alignment(alignment::Vertical::Center)
|
||||
.width(30),
|
||||
text("W:").width(30),
|
||||
numeric_input("0", self.width_input_value)
|
||||
.map(Message::WidthInputChanged),
|
||||
text("H:")
|
||||
.vertical_alignment(alignment::Vertical::Center)
|
||||
.width(30),
|
||||
text("H:").width(30),
|
||||
numeric_input("0", self.height_input_value)
|
||||
.map(Message::HeightInputChanged)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
let crop_controls =
|
||||
column![crop_origin_controls, crop_dimension_controls]
|
||||
|
|
@ -162,7 +151,7 @@ impl Example {
|
|||
.map(|error| text!("Crop error! \n{error}")),
|
||||
)
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
.center_x();
|
||||
|
||||
let controls = {
|
||||
let save_result =
|
||||
|
|
@ -203,7 +192,7 @@ impl Example {
|
|||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center),
|
||||
.center_x(),
|
||||
]
|
||||
.push_maybe(save_result.map(text))
|
||||
.spacing(40)
|
||||
|
|
@ -215,7 +204,7 @@ impl Example {
|
|||
.spacing(10)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.align_items(Alignment::Center);
|
||||
.center_y();
|
||||
|
||||
container(content).padding(10).into()
|
||||
}
|
||||
|
|
@ -276,8 +265,5 @@ fn numeric_input(
|
|||
}
|
||||
|
||||
fn centered_text(content: &str) -> Element<'_, Message> {
|
||||
text(content)
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.into()
|
||||
text(content).width(Length::Fill).center_x().into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use iced::widget::{
|
|||
button, column, container, horizontal_space, progress_bar, radio, row,
|
||||
scrollable, slider, text, vertical_space,
|
||||
};
|
||||
use iced::{Alignment, Border, Color, Element, Length, Task, Theme};
|
||||
use iced::{Border, Color, Element, Length, Task, Theme};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ struct ScrollableDemo {
|
|||
scrollbar_margin: u16,
|
||||
scroller_width: u16,
|
||||
current_scroll_offset: scrollable::RelativeOffset,
|
||||
alignment: scrollable::Alignment,
|
||||
anchor: scrollable::Anchor,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Copy)]
|
||||
|
|
@ -37,7 +37,7 @@ enum Direction {
|
|||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
SwitchDirection(Direction),
|
||||
AlignmentChanged(scrollable::Alignment),
|
||||
AlignmentChanged(scrollable::Anchor),
|
||||
ScrollbarWidthChanged(u16),
|
||||
ScrollbarMarginChanged(u16),
|
||||
ScrollerWidthChanged(u16),
|
||||
|
|
@ -54,7 +54,7 @@ impl ScrollableDemo {
|
|||
scrollbar_margin: 0,
|
||||
scroller_width: 10,
|
||||
current_scroll_offset: scrollable::RelativeOffset::START,
|
||||
alignment: scrollable::Alignment::Start,
|
||||
anchor: scrollable::Anchor::Start,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ impl ScrollableDemo {
|
|||
}
|
||||
Message::AlignmentChanged(alignment) => {
|
||||
self.current_scroll_offset = scrollable::RelativeOffset::START;
|
||||
self.alignment = alignment;
|
||||
self.anchor = alignment;
|
||||
|
||||
scrollable::snap_to(
|
||||
SCROLLABLE_ID.clone(),
|
||||
|
|
@ -168,14 +168,14 @@ impl ScrollableDemo {
|
|||
text("Scrollable alignment:"),
|
||||
radio(
|
||||
"Start",
|
||||
scrollable::Alignment::Start,
|
||||
Some(self.alignment),
|
||||
scrollable::Anchor::Start,
|
||||
Some(self.anchor),
|
||||
Message::AlignmentChanged,
|
||||
),
|
||||
radio(
|
||||
"End",
|
||||
scrollable::Alignment::End,
|
||||
Some(self.alignment),
|
||||
scrollable::Anchor::End,
|
||||
Some(self.anchor),
|
||||
Message::AlignmentChanged,
|
||||
)
|
||||
]
|
||||
|
|
@ -212,7 +212,7 @@ impl ScrollableDemo {
|
|||
text("End!"),
|
||||
scroll_to_beginning_button(),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.padding([40, 0, 40, 0])
|
||||
.spacing(40),
|
||||
)
|
||||
|
|
@ -221,7 +221,7 @@ impl ScrollableDemo {
|
|||
.width(self.scrollbar_width)
|
||||
.margin(self.scrollbar_margin)
|
||||
.scroller_width(self.scroller_width)
|
||||
.alignment(self.alignment),
|
||||
.anchor(self.anchor),
|
||||
))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
@ -238,7 +238,7 @@ impl ScrollableDemo {
|
|||
scroll_to_beginning_button(),
|
||||
]
|
||||
.height(450)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.padding([0, 40, 0, 40])
|
||||
.spacing(40),
|
||||
)
|
||||
|
|
@ -247,7 +247,7 @@ impl ScrollableDemo {
|
|||
.width(self.scrollbar_width)
|
||||
.margin(self.scrollbar_margin)
|
||||
.scroller_width(self.scroller_width)
|
||||
.alignment(self.alignment),
|
||||
.anchor(self.anchor),
|
||||
))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
@ -280,7 +280,7 @@ impl ScrollableDemo {
|
|||
text("Horizontal - End!"),
|
||||
scroll_to_beginning_button(),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.padding([0, 40, 0, 40])
|
||||
.spacing(40),
|
||||
)
|
||||
|
|
@ -289,7 +289,7 @@ impl ScrollableDemo {
|
|||
.width(self.scrollbar_width)
|
||||
.margin(self.scrollbar_margin)
|
||||
.scroller_width(self.scroller_width)
|
||||
.alignment(self.alignment);
|
||||
.anchor(self.anchor);
|
||||
|
||||
scrollable::Direction::Both {
|
||||
horizontal: scrollbar,
|
||||
|
|
@ -322,7 +322,7 @@ impl ScrollableDemo {
|
|||
|
||||
let content: Element<Message> =
|
||||
column![scroll_controls, scrollable_content, progress_bars]
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(10)
|
||||
.into();
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ impl SierpinskiEmulator {
|
|||
.padding(10)
|
||||
.spacing(20),
|
||||
]
|
||||
.align_items(iced::Alignment::Center)
|
||||
.center_x()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use iced::widget::{column, container, iced, slider, text, vertical_slider};
|
||||
use iced::{Alignment, Element, Length};
|
||||
use iced::{Element, Length};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::run("Slider - Iced", Slider::update, Slider::view)
|
||||
|
|
@ -46,7 +46,7 @@ impl Slider {
|
|||
|
||||
column![v_slider, h_slider, text, iced(self.value as f32),]
|
||||
.width(Length::Fill)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(20)
|
||||
.padding(20)
|
||||
.into()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use iced::alignment;
|
||||
use iced::keyboard;
|
||||
use iced::time;
|
||||
use iced::widget::{button, center, column, row, text};
|
||||
use iced::{Alignment, Element, Subscription, Theme};
|
||||
use iced::{Element, Subscription, Theme};
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
|
@ -101,13 +100,8 @@ impl Stopwatch {
|
|||
)
|
||||
.size(40);
|
||||
|
||||
let button = |label| {
|
||||
button(
|
||||
text(label).horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.padding(10)
|
||||
.width(80)
|
||||
};
|
||||
let button =
|
||||
|label| button(text(label).center_x()).padding(10).width(80);
|
||||
|
||||
let toggle_button = {
|
||||
let label = match self.state {
|
||||
|
|
@ -124,9 +118,7 @@ impl Stopwatch {
|
|||
|
||||
let controls = row![toggle_button, reset_button].spacing(20);
|
||||
|
||||
let content = column![duration, controls]
|
||||
.align_items(Alignment::Center)
|
||||
.spacing(20);
|
||||
let content = column![duration, controls].center_x().spacing(20);
|
||||
|
||||
center(content).into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use iced::widget::{
|
|||
row, scrollable, slider, text, text_input, toggler, vertical_rule,
|
||||
vertical_space,
|
||||
};
|
||||
use iced::{Alignment, Element, Length, Theme};
|
||||
use iced::{Element, Length, Theme};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application("Styling - Iced", Styling::update, Styling::view)
|
||||
|
|
@ -88,9 +88,7 @@ impl Styling {
|
|||
let content = column![
|
||||
choose_theme,
|
||||
horizontal_rule(38),
|
||||
row![text_input, button]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center),
|
||||
row![text_input, button].spacing(10).center_y(),
|
||||
slider,
|
||||
progress_bar,
|
||||
row![
|
||||
|
|
@ -100,7 +98,7 @@ impl Styling {
|
|||
]
|
||||
.spacing(10)
|
||||
.height(100)
|
||||
.align_items(Alignment::Center),
|
||||
.center_y(),
|
||||
]
|
||||
.spacing(20)
|
||||
.padding(20)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use iced::keyboard::key;
|
|||
use iced::widget::{
|
||||
self, button, center, column, pick_list, row, slider, text, text_input,
|
||||
};
|
||||
use iced::{Alignment, Element, Length, Subscription, Task};
|
||||
use iced::{Element, Length, Subscription, Task};
|
||||
|
||||
use toast::{Status, Toast};
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ impl App {
|
|||
.spacing(5)
|
||||
.into()
|
||||
),
|
||||
column![add_toast].align_items(Alignment::End)
|
||||
column![add_toast].center_x()
|
||||
]
|
||||
.spacing(10)
|
||||
.max_width(200),
|
||||
|
|
@ -245,7 +245,7 @@ mod toast {
|
|||
.on_press((on_close)(index))
|
||||
.padding(3),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.padding(5)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use iced::alignment::{self, Alignment};
|
||||
use iced::keyboard;
|
||||
use iced::widget::{
|
||||
self, button, center, checkbox, column, container, keyed_column, row,
|
||||
|
|
@ -196,7 +195,7 @@ impl Todos {
|
|||
.width(Length::Fill)
|
||||
.size(100)
|
||||
.color([0.5, 0.5, 0.5])
|
||||
.horizontal_alignment(alignment::Horizontal::Center);
|
||||
.center_x();
|
||||
|
||||
let input = text_input("What needs to be done?", input_value)
|
||||
.id(INPUT_ID.clone())
|
||||
|
|
@ -355,7 +354,7 @@ impl Task {
|
|||
.style(button::text),
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
TaskState::Editing => {
|
||||
|
|
@ -369,16 +368,14 @@ impl Task {
|
|||
row![
|
||||
text_input,
|
||||
button(
|
||||
row![delete_icon(), "Delete"]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
row![delete_icon(), "Delete"].spacing(10).center_y()
|
||||
)
|
||||
.on_press(TaskMessage::Delete)
|
||||
.padding(10)
|
||||
.style(button::danger)
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
@ -415,7 +412,7 @@ fn view_controls(tasks: &[Task], current_filter: Filter) -> Element<Message> {
|
|||
.spacing(10)
|
||||
]
|
||||
.spacing(20)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
.into()
|
||||
}
|
||||
|
||||
|
|
@ -440,12 +437,7 @@ impl Filter {
|
|||
}
|
||||
|
||||
fn loading_message<'a>() -> Element<'a, Message> {
|
||||
center(
|
||||
text("Loading...")
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.size(50),
|
||||
)
|
||||
.into()
|
||||
center(text("Loading...").center_x().size(50)).into()
|
||||
}
|
||||
|
||||
fn empty_message(message: &str) -> Element<'_, Message> {
|
||||
|
|
@ -453,7 +445,7 @@ fn empty_message(message: &str) -> Element<'_, Message> {
|
|||
text(message)
|
||||
.width(Length::Fill)
|
||||
.size(25)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
.center_x()
|
||||
.color([0.7, 0.7, 0.7]),
|
||||
)
|
||||
.height(200)
|
||||
|
|
@ -464,10 +456,7 @@ 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)
|
||||
.horizontal_alignment(alignment::Horizontal::Center)
|
||||
text(unicode.to_string()).font(ICONS).width(20).center_x()
|
||||
}
|
||||
|
||||
fn edit_icon() -> Text<'static> {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use iced::alignment::{self, Alignment};
|
||||
use iced::widget::{
|
||||
button, checkbox, column, container, horizontal_space, image, radio, row,
|
||||
scrollable, slider, text, text_input, toggler, vertical_space,
|
||||
|
|
@ -235,11 +234,7 @@ impl Tour {
|
|||
0 to 100:",
|
||||
)
|
||||
.push(slider(0..=100, self.slider, Message::SliderChanged))
|
||||
.push(
|
||||
text(self.slider.to_string())
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.push(text(self.slider.to_string()).width(Length::Fill).center_x())
|
||||
}
|
||||
|
||||
fn rows_and_columns(&self) -> Column<Message> {
|
||||
|
|
@ -268,9 +263,7 @@ impl Tour {
|
|||
|
||||
let spacing_section = column![
|
||||
slider(0..=80, self.spacing, Message::SpacingChanged),
|
||||
text!("{} px", self.spacing)
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
text!("{} px", self.spacing).width(Length::Fill).center_x(),
|
||||
]
|
||||
.spacing(10);
|
||||
|
||||
|
|
@ -381,11 +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)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.push(text!("Width: {width} px").width(Length::Fill).center_x())
|
||||
.push(
|
||||
checkbox(
|
||||
"Use nearest interpolation",
|
||||
|
|
@ -393,7 +382,7 @@ impl Tour {
|
|||
)
|
||||
.on_toggle(Message::ImageUseNearestToggled),
|
||||
)
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
}
|
||||
|
||||
fn scrollable(&self) -> Column<Message> {
|
||||
|
|
@ -411,16 +400,11 @@ impl Tour {
|
|||
text("You are halfway there!")
|
||||
.width(Length::Fill)
|
||||
.size(30)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
.center_x(),
|
||||
)
|
||||
.push(vertical_space().height(4096))
|
||||
.push(ferris(300, image::FilterMethod::Linear))
|
||||
.push(
|
||||
text("You made it!")
|
||||
.width(Length::Fill)
|
||||
.size(50)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.push(text("You made it!").width(Length::Fill).size(50).center_x())
|
||||
}
|
||||
|
||||
fn text_input(&self) -> Column<Message> {
|
||||
|
|
@ -465,7 +449,7 @@ impl Tour {
|
|||
value
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
.center_x(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use iced::alignment::{self, Alignment};
|
||||
use iced::alignment;
|
||||
use iced::mouse;
|
||||
use iced::widget::{
|
||||
canvas, checkbox, column, horizontal_space, row, slider, text,
|
||||
|
|
@ -85,7 +85,7 @@ impl VectorialText {
|
|||
]
|
||||
.spacing(20),
|
||||
]
|
||||
.align_items(Alignment::Center)
|
||||
.center_x()
|
||||
.spacing(10)
|
||||
]
|
||||
.spacing(10)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ use iced::widget::{
|
|||
};
|
||||
use iced::window;
|
||||
use iced::{
|
||||
Alignment, Color, Element, Font, Length, Point, Rectangle, Subscription,
|
||||
Task, Theme,
|
||||
Color, Element, Font, Length, Point, Rectangle, Subscription, Task, Theme,
|
||||
};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
|
|
@ -70,7 +69,7 @@ impl Example {
|
|||
.color_maybe(color),
|
||||
]
|
||||
.height(40)
|
||||
.align_items(Alignment::Center)
|
||||
.center_y()
|
||||
};
|
||||
|
||||
let view_bounds = |label, bounds: Option<Rectangle>| {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
mod echo;
|
||||
|
||||
use iced::alignment::{self, Alignment};
|
||||
use iced::widget::{
|
||||
self, button, center, column, row, scrollable, text, text_input,
|
||||
};
|
||||
|
|
@ -113,12 +112,8 @@ impl WebSocket {
|
|||
.on_input(Message::NewMessageChanged)
|
||||
.padding(10);
|
||||
|
||||
let mut button = button(
|
||||
text("Send")
|
||||
.height(40)
|
||||
.vertical_alignment(alignment::Vertical::Center),
|
||||
)
|
||||
.padding([0, 20]);
|
||||
let mut button =
|
||||
button(text("Send").height(40).center_y()).padding([0, 20]);
|
||||
|
||||
if matches!(self.state, State::Connected(_)) {
|
||||
if let Some(message) = echo::Message::new(&self.new_message) {
|
||||
|
|
@ -127,9 +122,7 @@ impl WebSocket {
|
|||
}
|
||||
}
|
||||
|
||||
row![input, button]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center)
|
||||
row![input, button].spacing(10).center_y()
|
||||
};
|
||||
|
||||
column![message_log, new_message_input]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue