Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal scrollable off-by-one error? #2753

Open
3 of 4 tasks
mfreeborn opened this issue Jan 26, 2025 · 0 comments · May be fixed by #2768
Open
3 of 4 tasks

Horizontal scrollable off-by-one error? #2753

mfreeborn opened this issue Jan 26, 2025 · 0 comments · May be fixed by #2768
Labels
bug Something isn't working

Comments

@mfreeborn
Copy link

mfreeborn commented Jan 26, 2025

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

Here are some containers in a scrollable with their borders shown. Note that the scrollable area is fully expanded, but the right-hand border of the right-most container inside the scrollable area has been cut off.

Image

Equally, I can reduce the width of the window to activate the scrollable area, and note how it is scrolled all the way to the right, but again the last column of pixels is cut off.

Image

What is the expected behavior?

In the above screenshots, I would expect to be able to see the right-hand border of the right-most container.

I observed this behaviour in 0.13.1 (installed via the crates.io release), and I have produced this example code by writing it as a new example in a locally cloned copy of the iced repository.

My current workaround for this issue is to wrap the contents of the scrollable with a container and add 1 pixel of padding to the right-hand side.

Code:

// main.rs
use iced::widget::scrollable::{Direction, Scrollbar};
use iced::widget::{center, column, container, row, Container, Scrollable};
use iced::{border, Element, Length, Padding, Theme};

pub fn main() -> iced::Result {
    iced::run(
        "Scrollable Off By One",
        ScrollableOffByOne::update,
        ScrollableOffByOne::view,
    )
}

#[derive(Default)]
struct ScrollableOffByOne;

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

impl ScrollableOffByOne {
    fn update(&mut self, message: Message) {
        match message {}
    }

    fn view(&self) -> Element<Message> {
        let scrollable_content = Scrollable::with_direction(
            row![
                group_box("Inside scrollable"),
                group_box("Inside scrollable"),
                group_box("Inside scrollable"),
                group_box("Inside scrollable"),
                group_box("Inside scrollable"),
                group_box("Inside scrollable"),
            ]
            .spacing(10),
            Direction::Horizontal(Scrollbar::default()),
        )
        .spacing(10);

        center(column![row![
            group_box("Outside scrollable area"),
            scrollable_content
        ]
        .spacing(20)
        .padding(Padding::ZERO.top(50).bottom(50))])
        .padding(12)
        .into()
    }
}

pub fn group_box_style(t: &Theme) -> container::Style {
    let p = t.palette();

    container::Style {
        border: border::rounded(5).width(1).color(p.text),
        ..Default::default()
    }
}

pub fn group_box<'a, Message>(
    content: impl Into<Element<'a, Message>>,
) -> Container<'a, Message>
where
    Theme: container::Catalog + 'a,
{
    container(content)
        .height(Length::Fill)
        .padding(8)
        .style(group_box_style)
}

Version

crates.io release

Operating System

Linux

Do you have any log output?

@mfreeborn mfreeborn added the bug Something isn't working label Jan 26, 2025
@edwloef edwloef linked a pull request Jan 30, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant