Rename again, add fun cx APIs using new traits

This commit is contained in:
Mikayla 2023-11-17 10:06:41 -08:00
parent 01d9d53f4a
commit 17d53d0e38
No known key found for this signature in database
10 changed files with 77 additions and 35 deletions

View file

@ -193,11 +193,11 @@ pub trait FocusableView: Render {
/// ManagedView is a view (like a Modal, Popover, Menu, etc.)
/// where the lifecycle of the view is handled by another view.
pub trait Managed: FocusableView + EventEmitter<ManagedView> {}
pub trait ManagedView: FocusableView + EventEmitter<ManagedEvent> {}
impl<M: FocusableView + EventEmitter<ManagedView>> Managed for M {}
impl<M: FocusableView + EventEmitter<ManagedEvent>> ManagedView for M {}
pub enum ManagedView {
pub enum ManagedEvent {
Dismiss,
}
@ -1577,6 +1577,13 @@ impl VisualContext for WindowContext<'_> {
view.focus_handle(cx).clone().focus(cx);
})
}
fn dismiss_view<V>(&mut self, view: &View<V>) -> Self::Result<()>
where
V: ManagedView,
{
self.update_view(view, |_, cx| cx.emit(ManagedEvent::Dismiss))
}
}
impl<'a> std::ops::Deref for WindowContext<'a> {
@ -2270,6 +2277,13 @@ impl<'a, V: 'static> ViewContext<'a, V> {
{
self.defer(|view, cx| view.focus_handle(cx).focus(cx))
}
pub fn dismiss_self(&mut self)
where
V: ManagedView,
{
self.defer(|_, cx| cx.emit(ManagedEvent::Dismiss))
}
}
impl<V> Context for ViewContext<'_, V> {
@ -2349,6 +2363,10 @@ impl<V: 'static> VisualContext for ViewContext<'_, V> {
fn focus_view<W: FocusableView>(&mut self, view: &View<W>) -> Self::Result<()> {
self.window_cx.focus_view(view)
}
fn dismiss_view<W: ManagedView>(&mut self, view: &View<W>) -> Self::Result<()> {
self.window_cx.dismiss_view(view)
}
}
impl<'a, V> std::ops::Deref for ViewContext<'a, V> {