popover: Fix PopoverContent content build to use ViewContext<Self>. (#254)
And add popover self dismiss example. ## How to dismiss popover from inside. ```rs cx.emit(DismissEvent); ```
This commit is contained in:
parent
9fc7b29f23
commit
20926b7077
2 changed files with 29 additions and 7 deletions
|
|
@ -14,7 +14,7 @@ use ui::{
|
||||||
popover::{Popover, PopoverContent},
|
popover::{Popover, PopoverContent},
|
||||||
popup_menu::PopupMenuExt,
|
popup_menu::PopupMenuExt,
|
||||||
switch::Switch,
|
switch::Switch,
|
||||||
v_flex, IconName, Sizable,
|
v_flex, ContextModal, IconName, Sizable,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Deserialize)]
|
#[derive(Clone, PartialEq, Deserialize)]
|
||||||
|
|
@ -308,11 +308,33 @@ impl Render for PopupStory {
|
||||||
"Hello, this is a Popover on the Bottom Right.",
|
"Hello, this is a Popover on the Bottom Right.",
|
||||||
)
|
)
|
||||||
.child(Divider::horizontal())
|
.child(Divider::horizontal())
|
||||||
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.gap_4()
|
||||||
.child(
|
.child(
|
||||||
Button::new("info1", cx)
|
Button::new("info1", cx)
|
||||||
.label("Yes")
|
.label("Ok")
|
||||||
.w(px(80.))
|
.w(px(80.))
|
||||||
.small(),
|
.small()
|
||||||
|
.on_click(cx.listener(
|
||||||
|
|_, _, cx| {
|
||||||
|
cx.push_notification(
|
||||||
|
"You have clicked Ok.",
|
||||||
|
);
|
||||||
|
cx.emit(DismissEvent);
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("close", cx)
|
||||||
|
.label("Cancel")
|
||||||
|
.small()
|
||||||
|
.on_click(cx.listener(
|
||||||
|
|_, _, cx| {
|
||||||
|
cx.emit(DismissEvent);
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.into_any()
|
.into_any()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,14 @@ pub fn init(cx: &mut AppContext) {
|
||||||
|
|
||||||
pub struct PopoverContent {
|
pub struct PopoverContent {
|
||||||
focus_handle: FocusHandle,
|
focus_handle: FocusHandle,
|
||||||
content: Rc<dyn Fn(&mut WindowContext) -> AnyElement>,
|
content: Rc<dyn Fn(&mut ViewContext<Self>) -> AnyElement>,
|
||||||
max_width: Option<Pixels>,
|
max_width: Option<Pixels>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PopoverContent {
|
impl PopoverContent {
|
||||||
pub fn new<B>(cx: &mut WindowContext, content: B) -> Self
|
pub fn new<B>(cx: &mut WindowContext, content: B) -> Self
|
||||||
where
|
where
|
||||||
B: Fn(&mut WindowContext) -> AnyElement + 'static,
|
B: Fn(&mut ViewContext<Self>) -> AnyElement + 'static,
|
||||||
{
|
{
|
||||||
let focus_handle = cx.focus_handle();
|
let focus_handle = cx.focus_handle();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue