summaryrefslogtreecommitdiffstats
path: root/examples/scroll.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-25 03:47:34 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-25 03:47:34 +0200
commit719c073fc67c87d6b2da1bc01b74751d3f5e59f0 (patch)
tree660613d215cafc01a30911c22a5ba107fb61b12c /examples/scroll.rs
parent4769272122e8cd0a4d666bb06c00cb27f8cad3c4 (diff)
downloadiced-719c073fc67c87d6b2da1bc01b74751d3f5e59f0.tar.gz
iced-719c073fc67c87d6b2da1bc01b74751d3f5e59f0.tar.bz2
iced-719c073fc67c87d6b2da1bc01b74751d3f5e59f0.zip
Draft `Scrollable` widget (no clipping yet!)
Diffstat (limited to 'examples/scroll.rs')
-rw-r--r--examples/scroll.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/scroll.rs b/examples/scroll.rs
new file mode 100644
index 00000000..648b1d8f
--- /dev/null
+++ b/examples/scroll.rs
@@ -0,0 +1,69 @@
+use iced::{
+ button, scrollable, Align, Application, Button, Color, Element, Image,
+ Length, Scrollable, Text,
+};
+
+pub fn main() {
+ Example::default().run()
+}
+
+#[derive(Default)]
+struct Example {
+ paragraph_count: u16,
+
+ scroll: scrollable::State,
+ add_button: button::State,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub enum Message {
+ AddParagraph,
+}
+
+impl Application for Example {
+ type Message = Message;
+
+ fn update(&mut self, message: Message) {
+ match message {
+ Message::AddParagraph => {
+ self.paragraph_count += 1;
+ }
+ }
+ }
+
+ fn view(&mut self) -> Element<Message> {
+ let content = Scrollable::new(&mut self.scroll)
+ .width(Length::Fill)
+ .max_width(Length::Units(600))
+ .spacing(20)
+ .padding(20)
+ .align_self(Align::Center);
+
+ //let content = (0..self.paragraph_count)
+ // .fold(content, |column, _| column.push(lorem_ipsum()))
+ // .push(
+ // Button::new(&mut self.add_button, Text::new("Add paragraph"))
+ // .on_press(Message::AddParagraph)
+ // .padding(20)
+ // .border_radius(5)
+ // .align_self(Align::Center),
+ // );
+
+ (0..10)
+ .fold(content, |content, _| {
+ content.push(
+ Image::new(format!(
+ "{}/examples/resources/ferris.png",
+ env!("CARGO_MANIFEST_DIR")
+ ))
+ .width(Length::Units(400))
+ .align_self(Align::Center),
+ )
+ })
+ .into()
+ }
+}
+
+fn lorem_ipsum() -> Text {
+ Text::new("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi in dui vel massa blandit interdum. Quisque placerat, odio ut vulputate sagittis, augue est facilisis ex, eget euismod felis magna in sapien. Nullam luctus consequat massa, ac interdum mauris blandit pellentesque. Nullam in est urna. Aliquam tristique lectus ac luctus feugiat. Aenean libero diam, euismod facilisis consequat quis, pellentesque luctus erat. Praesent vel tincidunt elit.")
+}