summaryrefslogtreecommitdiffstats
path: root/examples/scrollable/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scrollable/src/main.rs')
-rw-r--r--examples/scrollable/src/main.rs105
1 files changed, 52 insertions, 53 deletions
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index f2a853e1..de4f2f9a 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -1,9 +1,8 @@
-use iced::widget::scrollable::Properties;
use iced::widget::{
button, column, container, horizontal_space, progress_bar, radio, row,
- scrollable, slider, text, vertical_space, Scrollable,
+ scrollable, slider, text, vertical_space,
};
-use iced::{Alignment, Border, Color, Element, Length, Task, Theme};
+use iced::{Border, Center, Color, Element, Fill, Task, Theme};
use once_cell::sync::Lazy;
@@ -25,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)]
@@ -38,7 +37,7 @@ enum Direction {
#[derive(Debug, Clone)]
enum Message {
SwitchDirection(Direction),
- AlignmentChanged(scrollable::Alignment),
+ AlignmentChanged(scrollable::Anchor),
ScrollbarWidthChanged(u16),
ScrollbarMarginChanged(u16),
ScrollerWidthChanged(u16),
@@ -55,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,
}
}
@@ -72,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(),
@@ -169,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,
)
]
@@ -203,7 +202,7 @@ impl ScrollableDemo {
let scrollable_content: Element<Message> =
Element::from(match self.scrollable_direction {
- Direction::Vertical => Scrollable::with_direction(
+ Direction::Vertical => scrollable(
column![
scroll_to_end_button(),
text("Beginning!"),
@@ -213,22 +212,22 @@ impl ScrollableDemo {
text("End!"),
scroll_to_beginning_button(),
]
- .align_items(Alignment::Center)
- .padding([40, 0, 40, 0])
+ .align_x(Center)
+ .padding([40, 0])
.spacing(40),
- scrollable::Direction::Vertical(
- Properties::new()
- .width(self.scrollbar_width)
- .margin(self.scrollbar_margin)
- .scroller_width(self.scroller_width)
- .alignment(self.alignment),
- ),
)
- .width(Length::Fill)
- .height(Length::Fill)
+ .direction(scrollable::Direction::Vertical(
+ scrollable::Scrollbar::new()
+ .width(self.scrollbar_width)
+ .margin(self.scrollbar_margin)
+ .scroller_width(self.scroller_width)
+ .anchor(self.anchor),
+ ))
+ .width(Fill)
+ .height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
- Direction::Horizontal => Scrollable::with_direction(
+ Direction::Horizontal => scrollable(
row![
scroll_to_end_button(),
text("Beginning!"),
@@ -239,22 +238,22 @@ impl ScrollableDemo {
scroll_to_beginning_button(),
]
.height(450)
- .align_items(Alignment::Center)
- .padding([0, 40, 0, 40])
+ .align_y(Center)
+ .padding([0, 40])
.spacing(40),
- scrollable::Direction::Horizontal(
- Properties::new()
- .width(self.scrollbar_width)
- .margin(self.scrollbar_margin)
- .scroller_width(self.scroller_width)
- .alignment(self.alignment),
- ),
)
- .width(Length::Fill)
- .height(Length::Fill)
+ .direction(scrollable::Direction::Horizontal(
+ scrollable::Scrollbar::new()
+ .width(self.scrollbar_width)
+ .margin(self.scrollbar_margin)
+ .scroller_width(self.scroller_width)
+ .anchor(self.anchor),
+ ))
+ .width(Fill)
+ .height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
- Direction::Multi => Scrollable::with_direction(
+ Direction::Multi => scrollable(
//horizontal content
row![
column![
@@ -281,24 +280,24 @@ impl ScrollableDemo {
text("Horizontal - End!"),
scroll_to_beginning_button(),
]
- .align_items(Alignment::Center)
- .padding([0, 40, 0, 40])
+ .align_y(Center)
+ .padding([0, 40])
.spacing(40),
- {
- let properties = Properties::new()
- .width(self.scrollbar_width)
- .margin(self.scrollbar_margin)
- .scroller_width(self.scroller_width)
- .alignment(self.alignment);
-
- scrollable::Direction::Both {
- horizontal: properties,
- vertical: properties,
- }
- },
)
- .width(Length::Fill)
- .height(Length::Fill)
+ .direction({
+ let scrollbar = scrollable::Scrollbar::new()
+ .width(self.scrollbar_width)
+ .margin(self.scrollbar_margin)
+ .scroller_width(self.scroller_width)
+ .anchor(self.anchor);
+
+ scrollable::Direction::Both {
+ horizontal: scrollbar,
+ vertical: scrollbar,
+ }
+ })
+ .width(Fill)
+ .height(Fill)
.id(SCROLLABLE_ID.clone())
.on_scroll(Message::Scrolled),
});
@@ -323,7 +322,7 @@ impl ScrollableDemo {
let content: Element<Message> =
column![scroll_controls, scrollable_content, progress_bars]
- .align_items(Alignment::Center)
+ .align_x(Center)
.spacing(10)
.into();