Skip to content

Instantly share code, notes, and snippets.

@mtkennerly
Created August 3, 2022 00:58
Show Gist options
  • Save mtkennerly/7d9518abde5e1060427ad8fa503fdaf2 to your computer and use it in GitHub Desktop.
Save mtkennerly/7d9518abde5e1060427ad8fa503fdaf2 to your computer and use it in GitHub Desktop.
Iced 0.4.2 issue with container width+max_width
[package]
name = "repro-width-and-max"
version = "0.1.0"
edition = "2021"
[dependencies]
iced = "0.4.2"
# iced = { git = "https://github.com/iced-rs/iced.git", rev = "c44267b85f7aaa2997e3caf1323b837d95818c22" }
use iced::{alignment::Horizontal, Column, Container, Element, Length, Row, Sandbox, Settings, Text};
pub fn main() -> iced::Result {
Demo::run(Settings::default())
}
struct Demo {}
#[derive(Debug, Clone)]
enum Message {}
impl Sandbox for Demo {
type Message = Message;
fn new() -> Self {
Demo {}
}
fn title(&self) -> String {
String::from("Repro - Iced")
}
fn update(&mut self, _message: Message) {}
fn view(&mut self) -> Element<Message> {
Column::new()
.spacing(10)
.push(
Row::new()
.spacing(10)
.width(Length::Fill)
.push(
Container::new(
Text::new("start")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
)
.width(Length::Fill)
.style(style::Container::Outer),
)
.push(
Container::new(
Text::new("without max")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center),
)
.width(Length::Fill)
.style(style::Container::Outer),
)
.push(
Container::new(
Text::new("end")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
)
.width(Length::Fill)
.style(style::Container::Outer),
)
)
.push(
Row::new()
.spacing(10)
.width(Length::Fill)
.push(
Container::new(
Text::new("start")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
)
.width(Length::Fill)
.style(style::Container::Outer),
)
.push(
Container::new(
Text::new("with max")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center),
)
.width(Length::Fill)
.max_width(200)
.style(style::Container::Outer),
)
.push(
Container::new(
Text::new("end")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
)
.width(Length::Fill)
.style(style::Container::Outer),
)
)
.into()
}
}
mod style {
use iced::{container, Background, Color};
pub enum Container {
Outer,
}
impl container::StyleSheet for Container {
fn style(&self) -> container::Style {
container::Style {
background: Some(Background::Color(Color::from_rgb8(230, 230, 230))),
..container::Style::default()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment