From 2182cb26563f40034676f6fd4d24653ca7138fc5 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 16 Nov 2023 22:16:29 -0700 Subject: [PATCH] Ooh generics --- crates/storybook3/src/storybook3.rs | 2 +- crates/ui2/src/components/context_menu.rs | 26 +++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/storybook3/src/storybook3.rs b/crates/storybook3/src/storybook3.rs index aa27edb1f9..291f8ce2ac 100644 --- a/crates/storybook3/src/storybook3.rs +++ b/crates/storybook3/src/storybook3.rs @@ -1,7 +1,7 @@ use anyhow::Result; use gpui::AssetSource; use gpui::{ - div, hsla, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds, + div, px, size, AnyView, Bounds, Div, Render, ViewContext, VisualContext, WindowBounds, WindowOptions, }; use settings::{default_settings, Settings, SettingsStore}; diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index dadf27d89e..789523d526 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -23,6 +23,7 @@ impl FocusableView for ContextMenu { self.focus_handle.clone() } } +impl Menu for ContextMenu {} impl ContextMenu { pub fn new(cx: &mut WindowContext) -> Self { @@ -81,25 +82,24 @@ impl Render for ContextMenu { } } -pub struct MenuHandle { +pub trait Menu: Render + EventEmitter + FocusableView {} + +pub struct MenuHandle { id: Option, child_builder: Option AnyElement + 'static>>, - menu_builder: Option) -> View + 'static>>, + menu_builder: Option) -> View + 'static>>, anchor: Option, attach: Option, } -impl MenuHandle { +impl MenuHandle { pub fn id(mut self, id: impl Into) -> Self { self.id = Some(id.into()); self } - pub fn menu( - mut self, - f: impl Fn(&mut V, &mut ViewContext) -> View + 'static, - ) -> Self { + pub fn menu(mut self, f: impl Fn(&mut V, &mut ViewContext) -> View + 'static) -> Self { self.menu_builder = Some(Rc::new(f)); self } @@ -123,7 +123,7 @@ impl MenuHandle { } } -pub fn menu_handle() -> MenuHandle { +pub fn menu_handle() -> MenuHandle { MenuHandle { id: None, child_builder: None, @@ -133,15 +133,15 @@ pub fn menu_handle() -> MenuHandle { } } -pub struct MenuHandleState { - menu: Rc>>>, +pub struct MenuHandleState { + menu: Rc>>>, position: Rc>>, child_layout_id: Option, child_element: Option>, menu_element: Option>, } -impl Element for MenuHandle { - type ElementState = MenuHandleState; +impl Element for MenuHandle { + type ElementState = MenuHandleState; fn element_id(&self) -> Option { Some(self.id.clone().expect("menu_handle must have an id()")) @@ -255,7 +255,7 @@ impl Element for MenuHandle { } } -impl Component for MenuHandle { +impl Component for MenuHandle { fn render(self) -> AnyElement { AnyElement::new(self) }