iced-rs / iced_web

A web runtime for iced that targets the DOM
93 stars 4 forks source link

`iced_web`: Scrollable not limited by `max_width` #6

Open Kaiden42 opened 3 years ago

Kaiden42 commented 3 years ago

Hello,

I've noticed that the Scrollable widget on iced_web applies max_with to it's content, but not on itself. Which results in having the width of the scrollable DIV to not being limited by the maximum width.

This is a different behavior than iced_native.

Code to reproduce:

use iced::{
    scrollable, Container, Element, Length, Sandbox, Scrollable,
    Settings, Text
};

fn main() -> iced::Result {
    ScrollTest::run(Settings::default())
}

struct ScrollTest {
    state: scrollable::State,
}

#[derive(Clone, Debug)]
enum Message {}

impl Sandbox for ScrollTest {

    type Message = Message;

    fn new() -> Self {
        ScrollTest {
            state: scrollable::State::new(),
        }
    }

    fn title(&self) -> String {
        String::from("Scrollable Test")
    }

    fn update(&mut self, _: Self::Message) { }

    fn view(&mut self) -> Element<'_, Self::Message> {
        Container::new(
            Scrollable::new(&mut self.state)
                .max_width(600)
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
                .push(Text::new("This is a line").width(Length::Fill))
        )
        .center_x()
        .center_y()
        .width(Length::Fill)
        .height(Length::Fill)
        .into()
    }
}

iced_native on Linux: iced_native

iced_web without maximum width: web_without_max

iced_web with maximum width: web_with_max