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

Only first overlay element is being rendered #1591

Closed
2 tasks done
ThisIsRex opened this issue Dec 9, 2022 · 4 comments · Fixed by #1655
Closed
2 tasks done

Only first overlay element is being rendered #1591

ThisIsRex opened this issue Dec 9, 2022 · 4 comments · Fixed by #1655
Labels
Milestone

Comments

@ThisIsRex
Copy link
Contributor

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?

When trying to add multiple overlay elements, it renders the only first. I took a Floating Button example and got this bug. I also tried to implement my own overlay container but got the same result. For the second overlay even doesn't call an overlay function and the layout isn't being calculated.

Iced version is 0.5, but it can't be chosen from the version dropdown list.

Screenshot:
image

The code:

use iced::widget::Row;
use iced::{
    widget::{Button, Column, Container},
    Element, Length, Sandbox, Settings,
};

use iced_aw::floating_element::{Anchor, FloatingElement};
use iced_aw::Badge;

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

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

struct FloatingElementExample {
    lines: Vec<String>,
}

impl Sandbox for FloatingElementExample {
    type Message = Message;

    fn new() -> Self {
        FloatingElementExample { lines: Vec::new() }
    }

    fn title(&self) -> String {
        String::from("FloatingButton example")
    }

    fn update(&mut self, message: Message) {
        match message {
            Message::ButtonPressed => self.lines.push("This is a newly added line.".into()),
        }
    }

    fn view(&self) -> Element<Message> {
        let row = Row::new()
            .spacing(8)
            .push(
                FloatingElement::new(
                    Button::new("Underlay1").on_press(Message::ButtonPressed),
                    || Badge::new("Ovr1").into(),
                )
                .anchor(Anchor::NorthEast),
            )
            .push(
                FloatingElement::new(
                    Button::new("Underlay2").on_press(Message::ButtonPressed),
                    || Badge::new("Ovr2").into(),
                )
                .anchor(Anchor::NorthEast),
            );

        Container::new(Column::new().push(row))
            .width(Length::Fill)
            .height(Length::Fill)
            .padding(10)
            .center_x()
            .center_y()
            .into()
    }
}

What is the expected behavior?

I expect the all overlay elements to be rendered

Version

0.4

Operative System

Windows

Do you have any log output?

No response

@ThisIsRex ThisIsRex added the bug Something isn't working label Dec 9, 2022
@ThisIsRex ThisIsRex changed the title Overlay element renders only once Only first overlay element renders Dec 9, 2022
@ThisIsRex ThisIsRex changed the title Only first overlay element renders Only first overlay element is being rendered Dec 9, 2022
@zopu
Copy link

zopu commented Jan 11, 2023

I'm hitting this issue too on iced 0.5.0, iced_native 0.7.0. A quick scan of the iced_native source and I think I can maybe see the problem.

In the implementation of Widget::Overlay for Row there's a call to overlay::from_children, but looking at the source of overlay::from_children, that function's description is "Obtains the first overlay [Element] found in the given children."

This is my first time looking at iced source, so I might be missing something. Would someone who knows this area be able to sanity-check that?

@zopu
Copy link

zopu commented Jan 11, 2023

I think @hecrj wrote this code and could probably clue us in.

@13r0ck
Copy link
Member

13r0ck commented Jan 11, 2023

Iced only supports one at the current moment

@zopu
Copy link

zopu commented Jan 14, 2023

In case it helps anyone else, what I was trying to do was draw an image and show its filename on mouse hover. The way I ended up implementing this was to create a custom widget and use renderer.with_layer in its draw function on hover to show the title.

`

    if layout.bounds().contains(cursor_position) {
        renderer.with_layer(layout.bounds(), |r| {
            self.title_overlay.as_widget().draw(
                &state.children[1],
                r,
                theme,
                style,
                layout_children.next().unwrap(),
                cursor_position,
                viewport,
            );
        });
    }
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants