Introduce helper methods for alignment for all widgets

This commit is contained in:
Héctor Ramón Jiménez 2024-07-12 15:11:30 +02:00
parent be06060117
commit f9dd5cbb09
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
45 changed files with 380 additions and 282 deletions

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::{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();