Skip to main content

popover

Function popover 

pub fn popover<W, V, Message>(
    content: W,
    popover: Option<V>,
) -> Popover<W, Opaque<V>, Message>
Expand description

Creates a new Popover for the provided content with the given Widget.

Popovers display a floating piece of content over some element. The popover argument is an Option: Some displays the overlay (open), and None hides it (closed). The base is always present. By default, the popover is positioned crate::popover::Position::Auto; use the Popover::position method to set a specific position. When the user clicks outside of its bounds, the popover notifies the application through its on_close handler.

ยงExample

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

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

struct State {
    is_open: bool,
}

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)
}