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},
|
||||
popup_menu::PopupMenuExt,
|
||||
switch::Switch,
|
||||
v_flex, IconName, Sizable,
|
||||
v_flex, ContextModal, IconName, Sizable,
|
||||
};
|
||||
|
||||
#[derive(Clone, PartialEq, Deserialize)]
|
||||
|
|
@ -309,10 +309,32 @@ impl Render for PopupStory {
|
|||
)
|
||||
.child(Divider::horizontal())
|
||||
.child(
|
||||
Button::new("info1", cx)
|
||||
.label("Yes")
|
||||
.w(px(80.))
|
||||
.small(),
|
||||
h_flex()
|
||||
.gap_4()
|
||||
.child(
|
||||
Button::new("info1", cx)
|
||||
.label("Ok")
|
||||
.w(px(80.))
|
||||
.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()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ pub fn init(cx: &mut AppContext) {
|
|||
|
||||
pub struct PopoverContent {
|
||||
focus_handle: FocusHandle,
|
||||
content: Rc<dyn Fn(&mut WindowContext) -> AnyElement>,
|
||||
content: Rc<dyn Fn(&mut ViewContext<Self>) -> AnyElement>,
|
||||
max_width: Option<Pixels>,
|
||||
}
|
||||
|
||||
impl PopoverContent {
|
||||
pub fn new<B>(cx: &mut WindowContext, content: B) -> Self
|
||||
where
|
||||
B: Fn(&mut WindowContext) -> AnyElement + 'static,
|
||||
B: Fn(&mut ViewContext<Self>) -> AnyElement + 'static,
|
||||
{
|
||||
let focus_handle = cx.focus_handle();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue