Skip to content

Container widget background leaks out of enclosing Pin widget in case of negative offset #3113

@KiraMichiru

Description

@KiraMichiru

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?

Hi,

I was trying to use the new Pin widget to clip the viewport of a contained Container widget with background, depending on the state of some other widget (which seemed easier than writing a new custom widget to do a translated rendering like in Scrollable).

To achieve that, I gave my Pin widget a negative position, and as a consequence, the background of the contained Container was rendered outside the Pin viewport (here is a minimum example of the behavior):

use iced::{Color, Element};
use iced::widget::{Pin, container, text};

pub fn main() -> iced::Result {
    iced::run(ContainerBug::update, ContainerBug::view)
}

#[derive(Default)]
struct ContainerBug{

}

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

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

    fn view(&self) -> Element<'_, Message> {

        let text_element = text("Container");

        let inner_container = container(text_element)
        .width(100.0)
        .height(20.0)
        .style(|_| container::Style::default().background(Color::from_rgb(0.7, 0.7, 0.7)));
        
        let pinned_inner = Pin::new(inner_container).x(-50.0);
        
        let outer_container = container(pinned_inner)
        .padding(100.0)
        .width(300.0)
        .height(220.0)
        .style(|_| container::Style::default().background(Color::from_rgb(0.5, 0.5, 0.5)));

        outer_container.into()
    }
}

The output looks like this:

Image

What is the expected behavior?

I would expect the output to not leak the inner container background to the left into the surrounding container. Instead, I would expect the inner container to be clipped, similar to when a positive offset is given (example with 50.0 instead of -50.0):

Image

Version

master

Operating System

Linux

Do you have any log output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions