From f0ae9a0c38c2532220a7460916604914db94c078 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 24 Mar 2024 05:03:09 +0100 Subject: Use `Catalog` approach for all widgets --- examples/layout/src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/layout/src/main.rs') diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 713e2b70..66d79091 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -81,10 +81,10 @@ impl Layout { } else { self.example.view() }) - .style(|theme, _status| { + .style(|theme| { let palette = theme.extended_palette(); - container::Appearance::default() + container::Style::default() .with_border(palette.background.strong.color, 4.0) }) .padding(4) @@ -245,10 +245,10 @@ fn application<'a>() -> Element<'a, Message> { .padding(10) .align_items(Alignment::Center), ) - .style(|theme, _status| { + .style(|theme| { let palette = theme.extended_palette(); - container::Appearance::default() + container::Style::default() .with_border(palette.background.strong.color, 1) }); -- cgit From 15057a05c118dafcb8cf90d4119e66caaa6026c5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 3 May 2024 09:11:46 +0200 Subject: Introduce `center` widget helper ... and also make `center_x` and `center_y` set `width` and `height` to `Length::Fill`, respectively. This targets the most common use case when centering things and removes a bunch of boilerplate as a result. --- examples/layout/src/main.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'examples/layout/src/main.rs') diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 66d79091..5f14c03b 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -1,8 +1,8 @@ use iced::keyboard; use iced::mouse; use iced::widget::{ - button, canvas, checkbox, column, container, horizontal_space, pick_list, - row, scrollable, text, + button, canvas, center, checkbox, column, container, horizontal_space, + pick_list, row, scrollable, text, }; use iced::{ color, Alignment, Element, Font, Length, Point, Rectangle, Renderer, @@ -76,7 +76,7 @@ impl Layout { .spacing(20) .align_items(Alignment::Center); - let example = container(if self.explain { + let example = center(if self.explain { self.example.view().explain(color!(0x0000ff)) } else { self.example.view() @@ -87,11 +87,7 @@ impl Layout { container::Style::default() .with_border(palette.background.strong.color, 4.0) }) - .padding(4) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y(); + .padding(4); let controls = row([ (!self.example.is_first()).then_some( @@ -195,12 +191,7 @@ impl Default for Example { } fn centered<'a>() -> Element<'a, Message> { - container(text("I am centered!").size(50)) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y() - .into() + center(text("I am centered!").size(50)).into() } fn column_<'a>() -> Element<'a, Message> { @@ -260,7 +251,6 @@ fn application<'a>() -> Element<'a, Message> { .align_items(Alignment::Center), ) .style(container::rounded_box) - .height(Length::Fill) .center_y(); let content = container( -- cgit From 05f69f495e9b52e9a7d7bada420558d4c4f6730c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 13 May 2024 17:56:02 +0200 Subject: Ask for explicit `Length` in `center_*` methods --- examples/layout/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/layout/src/main.rs') diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs index 5f14c03b..c40ac820 100644 --- a/examples/layout/src/main.rs +++ b/examples/layout/src/main.rs @@ -251,7 +251,7 @@ fn application<'a>() -> Element<'a, Message> { .align_items(Alignment::Center), ) .style(container::rounded_box) - .center_y(); + .center_y(Length::Fill); let content = container( scrollable( -- cgit