Skip to main content

Popover

Struct Popover 

Source
pub struct Popover<'a, Msg> { /* private fields */ }
Expand description

Content shown as a layer next to an anchor, such as a filter panel under a button.

The application owns whether it is open: pass it to Popover::new and close it when the on_dismiss message arrives. The layer sits below the anchor, flips above (or to the other side) when there is no room and never leaves the screen. It unfolds from the anchor over the theme’s motion.enter. Esc or a press outside the anchor and the layer sends the dismiss message, and the press still reaches what it landed on, so one press on another button closes the popover and presses that button. A press on the widget that opened the popover only dismisses it, even when that widget is outside the anchor.

Style keys: popover (bg, padding).

use qframe::prelude::*;
use qframe::widgets::Popover;

struct Filters { open: bool }

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

impl App for Filters {
    type Msg = Msg;
    fn update(&mut self, msg: Msg) -> Command<Msg> {
        self.open = matches!(msg, Msg::Toggle) && !self.open;
        Command::none()
    }
    fn view(&self, ui: &mut View<'_, Msg>) {
        Popover::new(self.open)
            .on_dismiss(Msg::Close)
            .anchor(|ui| {
                ui.add(Button::new("Filters").on_press(Msg::Toggle));
            })
            .content(|ui| {
                ui.add(Text::new("Only running"));
            })
            .show(ui);
    }
}

let mut app = Harness::new(Filters { open: false }, 30, 6);
app.click_text("Filters").advance(std::time::Duration::from_millis(200));
assert!(app.screen().contains("Only running"));
app.press("esc");
assert!(!app.screen().contains("Only running"));

Implementations§

Source§

impl<'a, Msg: Clone + 'static> Popover<'a, Msg>

Source

pub fn new(open: bool) -> Self

A popover that shows its content while open.

Source

pub fn anchor(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self

The widgets the layer belongs to, usually a button that toggles it.

Source

pub fn content(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self

The widgets shown in the layer.

Source

pub fn placement(self, placement: Placement) -> Self

The preferred side of the anchor; Placement::Below by default.

Source

pub fn focus_inside(self, focus_inside: bool) -> Self

Moves keyboard focus to the first focusable widget in the layer when it opens, and back to where it was when it closes.

Source

pub fn on_dismiss(self, message: Msg) -> Self

Message sent on Esc or a press outside; the application usually closes the popover.

Source

pub fn show<'v>(self, ui: &'v mut View<'_, Msg>) -> NodeMut<'v, Msg>

Adds the popover to ui. The returned node sizes the anchor.

Auto Trait Implementations§

§

impl<'a, Msg> !RefUnwindSafe for Popover<'a, Msg>

§

impl<'a, Msg> !Send for Popover<'a, Msg>

§

impl<'a, Msg> !Sync for Popover<'a, Msg>

§

impl<'a, Msg> !UnwindSafe for Popover<'a, Msg>

§

impl<'a, Msg> Freeze for Popover<'a, Msg>
where Option<Msg>: Freeze, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: Freeze,

§

impl<'a, Msg> Unpin for Popover<'a, Msg>
where Option<Msg>: Unpin, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: Unpin,

§

impl<'a, Msg> UnsafeUnpin for Popover<'a, Msg>
where Option<Msg>: UnsafeUnpin, Option<Box<dyn FnOnce(&mut View<'_, Msg>) + 'a>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.