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

@ -5,7 +5,7 @@ use crate::prelude::*;
use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader};
use gpui::{
overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, DispatchPhase, Div,
EventEmitter, FocusHandle, FocusableView, LayoutId, Managed, ManagedView, MouseButton,
EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedEvent, ManagedView, MouseButton,
MouseDownEvent, Pixels, Point, Render, View,
};
@ -20,7 +20,7 @@ impl FocusableView for ContextMenu {
}
}
impl EventEmitter<ManagedView> for ContextMenu {}
impl EventEmitter<ManagedEvent> for ContextMenu {}
impl ContextMenu {
pub fn new(cx: &mut WindowContext) -> Self {
@ -47,11 +47,11 @@ impl ContextMenu {
pub fn confirm(&mut self, _: &menu::Confirm, cx: &mut ViewContext<Self>) {
// todo!()
cx.emit(ManagedView::Dismiss);
cx.emit(ManagedEvent::Dismiss);
}
pub fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext<Self>) {
cx.emit(ManagedView::Dismiss);
cx.emit(ManagedEvent::Dismiss);
}
}
@ -79,7 +79,7 @@ impl Render for ContextMenu {
}
}
pub struct MenuHandle<V: 'static, M: Managed> {
pub struct MenuHandle<V: 'static, M: ManagedView> {
id: Option<ElementId>,
child_builder: Option<Box<dyn FnOnce(bool) -> AnyElement<V> + 'static>>,
menu_builder: Option<Rc<dyn Fn(&mut V, &mut ViewContext<V>) -> View<M> + 'static>>,
@ -88,7 +88,7 @@ pub struct MenuHandle<V: 'static, M: Managed> {
attach: Option<AnchorCorner>,
}
impl<V: 'static, M: Managed> MenuHandle<V, M> {
impl<V: 'static, M: ManagedView> MenuHandle<V, M> {
pub fn id(mut self, id: impl Into<ElementId>) -> Self {
self.id = Some(id.into());
self
@ -118,7 +118,7 @@ impl<V: 'static, M: Managed> MenuHandle<V, M> {
}
}
pub fn menu_handle<V: 'static, M: Managed>() -> MenuHandle<V, M> {
pub fn menu_handle<V: 'static, M: ManagedView>() -> MenuHandle<V, M> {
MenuHandle {
id: None,
child_builder: None,
@ -135,7 +135,7 @@ pub struct MenuHandleState<V, M> {
child_element: Option<AnyElement<V>>,
menu_element: Option<AnyElement<V>>,
}
impl<V: 'static, M: Managed> Element<V> for MenuHandle<V, M> {
impl<V: 'static, M: ManagedView> Element<V> for MenuHandle<V, M> {
type ElementState = MenuHandleState<V, M>;
fn element_id(&self) -> Option<gpui::ElementId> {
@ -229,7 +229,7 @@ impl<V: 'static, M: Managed> Element<V> for MenuHandle<V, M> {
let new_menu = (builder)(view_state, cx);
let menu2 = menu.clone();
cx.subscribe(&new_menu, move |this, modal, e, cx| match e {
&ManagedView::Dismiss => {
&ManagedEvent::Dismiss => {
*menu2.borrow_mut() = None;
cx.notify();
}
@ -250,7 +250,7 @@ impl<V: 'static, M: Managed> Element<V> for MenuHandle<V, M> {
}
}
impl<V: 'static, M: Managed> Component<V> for MenuHandle<V, M> {
impl<V: 'static, M: ManagedView> Component<V> for MenuHandle<V, M> {
fn render(self) -> AnyElement<V> {
AnyElement::new(self)
}