wip: refactor
This commit is contained in:
@@ -16,6 +16,7 @@ pub trait ContextModal: Sized {
|
||||
fn open_modal<F>(&mut self, cx: &mut App, build: F)
|
||||
where
|
||||
F: Fn(Modal, &mut Window, &mut App) -> Modal + 'static;
|
||||
|
||||
/// Return true, if there is an active Modal.
|
||||
fn has_active_modal(&mut self, cx: &mut App) -> bool;
|
||||
|
||||
@@ -30,6 +31,8 @@ pub trait ContextModal: Sized {
|
||||
|
||||
/// Pushes a notification to the notification list.
|
||||
fn push_notification(&mut self, note: impl Into<Notification>, cx: &mut App);
|
||||
|
||||
/// Clear all notifications
|
||||
fn clear_notifications(&mut self, cx: &mut App);
|
||||
}
|
||||
|
||||
@@ -52,6 +55,7 @@ impl ContextModal for Window {
|
||||
focus_handle,
|
||||
builder: Rc::new(build),
|
||||
});
|
||||
|
||||
cx.notify();
|
||||
})
|
||||
}
|
||||
@@ -106,62 +110,13 @@ impl ContextModal for Window {
|
||||
}
|
||||
}
|
||||
|
||||
// impl<V> ContextModal for Context<'_, V> {
|
||||
// fn open_drawer<F>(&mut self, cx: &mut App, build: F)
|
||||
// where
|
||||
// F: Fn(Drawer, &mut Window, &mut App) -> Drawer + 'static,
|
||||
// {
|
||||
// self.deref_mut().open_drawer(cx, build)
|
||||
// }
|
||||
type Builder = Rc<dyn Fn(Modal, &mut Window, &mut App) -> Modal + 'static>;
|
||||
|
||||
// fn open_drawer_at<F>(&mut self, cx: &mut App, placement: Placement, build: F)
|
||||
// where
|
||||
// F: Fn(Drawer, &mut Window, &mut App) -> Drawer + 'static,
|
||||
// {
|
||||
// self.deref_mut().open_drawer_at(cx, placement, build)
|
||||
// }
|
||||
|
||||
// fn has_active_modal(&self, cx: &mut App) -> bool {
|
||||
// self.deref().has_active_modal(cx)
|
||||
// }
|
||||
|
||||
// fn close_drawer(&mut self, cx: &mut App) {
|
||||
// self.deref_mut().close_drawer(cx)
|
||||
// }
|
||||
|
||||
// fn open_modal<F>(&mut self, cx: &mut App, build: F)
|
||||
// where
|
||||
// F: Fn(Modal, &mut Window, &mut App) -> Modal + 'static,
|
||||
// {
|
||||
// self.deref_mut().open_modal(cx, build)
|
||||
// }
|
||||
|
||||
// fn has_active_drawer(&self, cx: &mut App) -> bool {
|
||||
// self.deref().has_active_drawer(cx)
|
||||
// }
|
||||
|
||||
// /// Close the last active modal.
|
||||
// fn close_modal(&mut self, cx: &mut App) {
|
||||
// self.deref_mut().close_modal(cx)
|
||||
// }
|
||||
|
||||
// /// Close all modals.
|
||||
// fn close_all_modals(&mut self, cx: &mut App) {
|
||||
// self.deref_mut().close_all_modals(cx)
|
||||
// }
|
||||
|
||||
// fn push_notification(&mut self, cx: &mut App, note: impl Into<Notification>) {
|
||||
// self.deref_mut().push_notification(cx, note)
|
||||
// }
|
||||
|
||||
// fn clear_notifications(&mut self, cx: &mut App) {
|
||||
// self.deref_mut().clear_notifications(cx)
|
||||
// }
|
||||
|
||||
// fn notifications(&self, cx: &mut App) -> Rc<Vec<Entity<Notification>>> {
|
||||
// self.deref().notifications(cx)
|
||||
// }
|
||||
// }
|
||||
#[derive(Clone)]
|
||||
struct ActiveModal {
|
||||
focus_handle: FocusHandle,
|
||||
builder: Builder,
|
||||
}
|
||||
|
||||
/// Root is a view for the App window for as the top level view (Must be the first view in the window).
|
||||
///
|
||||
@@ -175,12 +130,6 @@ pub struct Root {
|
||||
view: AnyView,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct ActiveModal {
|
||||
focus_handle: FocusHandle,
|
||||
builder: Rc<dyn Fn(Modal, &mut Window, &mut App) -> Modal + 'static>,
|
||||
}
|
||||
|
||||
impl Root {
|
||||
pub fn new(view: AnyView, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
@@ -263,6 +212,12 @@ impl Root {
|
||||
pub fn view(&self) -> &AnyView {
|
||||
&self.view
|
||||
}
|
||||
|
||||
/// Set the root view of the Root.
|
||||
pub fn set_view(&mut self, view: AnyView, cx: &mut Context<Self>) {
|
||||
self.view = view;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Root {
|
||||
|
||||
Reference in New Issue
Block a user