Improve scroll example
This commit is contained in:
parent
82c2aa6bfd
commit
e21890168f
1 changed files with 39 additions and 28 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use iced::{
|
use iced::{
|
||||||
button, scrollable, Align, Application, Button, Color, Column, Element,
|
button, scrollable, Align, Application, Button, Column, Element, Image,
|
||||||
Image, Justify, Length, Scrollable, Text,
|
Justify, Length, Scrollable, Text,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
@ -9,7 +9,7 @@ pub fn main() {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Example {
|
struct Example {
|
||||||
paragraph_count: u16,
|
item_count: u16,
|
||||||
|
|
||||||
scroll: scrollable::State,
|
scroll: scrollable::State,
|
||||||
add_button: button::State,
|
add_button: button::State,
|
||||||
|
|
@ -17,7 +17,7 @@ struct Example {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
AddParagraph,
|
AddItem,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for Example {
|
impl Application for Example {
|
||||||
|
|
@ -25,36 +25,47 @@ impl Application for Example {
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::AddParagraph => {
|
Message::AddItem => {
|
||||||
self.paragraph_count += 1;
|
self.item_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
let content = (0..3).fold(
|
//let content = (0..3).fold(
|
||||||
Scrollable::new(&mut self.scroll).spacing(20).padding(20),
|
// Scrollable::new(&mut self.scroll).spacing(20).padding(20),
|
||||||
|content, _| {
|
// |content, _| {
|
||||||
content.push(
|
// content.push(
|
||||||
Image::new(format!(
|
// )
|
||||||
"{}/examples/resources/ferris.png",
|
// },
|
||||||
env!("CARGO_MANIFEST_DIR")
|
//);
|
||||||
))
|
|
||||||
.width(Length::Units(400))
|
|
||||||
.align_self(Align::Center),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
//let content = (0..self.paragraph_count)
|
let content = (0..self.item_count)
|
||||||
// .fold(content, |column, _| column.push(lorem_ipsum()))
|
.fold(
|
||||||
// .push(
|
Scrollable::new(&mut self.scroll)
|
||||||
// Button::new(&mut self.add_button, Text::new("Add paragraph"))
|
.spacing(20)
|
||||||
// .on_press(Message::AddParagraph)
|
.padding(20)
|
||||||
// .padding(20)
|
.align_items(Align::Center),
|
||||||
// .border_radius(5)
|
|column, i| {
|
||||||
// .align_self(Align::Center),
|
if i % 2 == 0 {
|
||||||
// );
|
column.push(lorem_ipsum().width(Length::Units(600)))
|
||||||
|
} else {
|
||||||
|
column.push(
|
||||||
|
Image::new(format!(
|
||||||
|
"{}/examples/resources/ferris.png",
|
||||||
|
env!("CARGO_MANIFEST_DIR")
|
||||||
|
))
|
||||||
|
.width(Length::Units(400)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.push(
|
||||||
|
Button::new(&mut self.add_button, Text::new("Add item"))
|
||||||
|
.on_press(Message::AddItem)
|
||||||
|
.padding(20)
|
||||||
|
.border_radius(5),
|
||||||
|
);
|
||||||
|
|
||||||
Column::new()
|
Column::new()
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue