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>
impl<'a, Msg: Clone + 'static> Popover<'a, Msg>
Sourcepub fn anchor(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self
pub fn anchor(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self
The widgets the layer belongs to, usually a button that toggles it.
Sourcepub fn content(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self
pub fn content(self, build: impl FnOnce(&mut View<'_, Msg>) + 'a) -> Self
The widgets shown in the layer.
Sourcepub fn placement(self, placement: Placement) -> Self
pub fn placement(self, placement: Placement) -> Self
The preferred side of the anchor; Placement::Below by default.
Sourcepub fn focus_inside(self, focus_inside: bool) -> Self
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.
Sourcepub fn on_dismiss(self, message: Msg) -> Self
pub fn on_dismiss(self, message: Msg) -> Self
Message sent on Esc or a press outside; the application usually closes the popover.
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>
impl<'a, Msg> Unpin for Popover<'a, Msg>
impl<'a, Msg> UnsafeUnpin for Popover<'a, Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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