Skip to main content

Module popover

Module popover 

Expand description

A popover is a floating piece of content that appears over some element.

Unlike a tooltip, a popover is not shown on hover, and it does not control its own visibility. Instead, the popover argument is an Option: Some displays the overlay (open), and None hides it (closed). The base is always present.

When the user clicks outside of the popover’s bounds, the popover notifies the application through its on_close handler, which is typically how the application decides to set the popover argument to None (i.e. to close it).

The popover() helper wraps the popup in opaque(), so mouse button presses inside the popup’s bounds are captured and do not pass through to the elements below. Use Popover::passthrough to let them fall through to the base layer, and Popover::capture_scroll to also capture scroll wheel events over the popup.

§Example

use iced::widget::{button, container, popover, text};

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

fn view(state: &State) -> impl Widget<Message> {
    // The base is always present. The `popover` argument is `Some` when the
    // popover is open and `None` when it is closed.
    popover(
        button(text("Click me!")).on_press(Message::Close),
        state.is_open.then(|| {
            container(text("This is the popover contents!")).padding(10)
        }),
    )
    .position(popover::Position::Bottom)
    .on_close(Message::Close)
}

Structs§

Popover
A floating piece of content that appears over another element.

Enums§

Position
The position of the popover.