Skip to content

Instantly share code, notes, and snippets.

@mtkennerly
Created July 19, 2022 06:28
Show Gist options
  • Save mtkennerly/c67a18ffcef3b926926f012f7b6d1512 to your computer and use it in GitHub Desktop.
Save mtkennerly/c67a18ffcef3b926926f012f7b6d1512 to your computer and use it in GitHub Desktop.
Iced cdd3802 scrollable height + max_height
[package]
name = "repro-max-height"
version = "0.1.0"
edition = "2021"
[dependencies]
# iced = "0.3.0"
# iced = "0.4.0"
iced = { git = "https://github.com/iced-rs/iced.git", rev = "cdd3802" }
use iced::{Column, Container, Element, Length, Row, Sandbox, Scrollable, scrollable, Settings, Text};
const LOREM_IPSUM: &'static str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
fn lorem_ipsum() -> String {
LOREM_IPSUM.replace(" ", "\n")
}
pub fn main() -> iced::Result {
Demo::run(Settings::default())
}
struct Demo {
scroll1: scrollable::State,
scroll2: scrollable::State,
scroll3: scrollable::State,
scroll4: scrollable::State,
}
#[derive(Debug, Clone)]
enum Message {}
impl Sandbox for Demo {
type Message = Message;
fn new() -> Self {
Demo {
scroll1: Default::default(),
scroll2: Default::default(),
scroll3: Default::default(),
scroll4: Default::default(),
}
}
fn title(&self) -> String {
String::from("Repro - Iced")
}
fn update(&mut self, _message: Message) {}
fn view(&mut self) -> Element<Message> {
let content = Row::new()
.push(
Column::new()
.spacing(20)
.padding(20)
.push(Text::new("-height, -max"))
.push(Scrollable::new(&mut self.scroll1).push(Text::new(lorem_ipsum())))
.push(Text::new("after")),
)
.push(
Column::new()
.spacing(20)
.padding(20)
.push(Text::new("+height, -max"))
.push(Scrollable::new(&mut self.scroll2).push(Text::new(lorem_ipsum())).height(Length::Fill))
.push(Text::new("after")),
)
.push(
Column::new()
.spacing(20)
.padding(20)
.push(Text::new("-height, +max"))
.push(Scrollable::new(&mut self.scroll3).push(Text::new(lorem_ipsum())).max_height(200))
.push(Text::new("after")),
)
.push(
Column::new()
.spacing(20)
.padding(20)
.push(Text::new("+height, +max"))
.push(
Scrollable::new(&mut self.scroll4).push(Text::new(lorem_ipsum()))
.height(Length::Fill)
.max_height(200),
)
.push(Text::new("after")),
);
Container::new(content).into()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment