summaryrefslogtreecommitdiffstats
path: root/examples/layout
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 09:11:46 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-03 09:11:46 +0200
commit15057a05c118dafcb8cf90d4119e66caaa6026c5 (patch)
tree59248040104660f87fc4097a9a33408d9d37cd74 /examples/layout
parent1cefe6be210cdae8c6769673e8d23c6781a988f1 (diff)
downloadiced-15057a05c118dafcb8cf90d4119e66caaa6026c5.tar.gz
iced-15057a05c118dafcb8cf90d4119e66caaa6026c5.tar.bz2
iced-15057a05c118dafcb8cf90d4119e66caaa6026c5.zip
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.
Diffstat (limited to 'examples/layout')
-rw-r--r--examples/layout/src/main.rs20
1 files changed, 5 insertions, 15 deletions
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(