From 88ef74ec8f1ac1544e4b97544132df4d87f1f0d8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 15:20:38 +0200 Subject: [PATCH] Checkpoint: Compiling after view type removal --- crates/gpui2_macros/src/derive_component.rs | 2 +- crates/storybook2/src/stories/z_index.rs | 27 ++---- crates/ui2/src/components/assistant_panel.rs | 14 +-- crates/ui2/src/components/breadcrumb.rs | 26 ++---- crates/ui2/src/components/buffer.rs | 28 ++---- crates/ui2/src/components/chat_panel.rs | 34 +++---- crates/ui2/src/components/collab_panel.rs | 27 ++---- crates/ui2/src/components/command_palette.rs | 28 ++---- crates/ui2/src/components/context_menu.rs | 36 +++----- crates/ui2/src/components/copilot.rs | 28 ++---- crates/ui2/src/components/editor_pane.rs | 8 +- crates/ui2/src/components/facepile.rs | 24 ++--- crates/ui2/src/components/icon_button.rs | 16 +--- crates/ui2/src/components/keybinding.rs | 37 +++----- .../ui2/src/components/language_selector.rs | 28 ++---- crates/ui2/src/components/list.rs | 91 +++++++++---------- crates/ui2/src/components/modal.rs | 10 +- crates/ui2/src/components/multi_buffer.rs | 32 +++---- .../ui2/src/components/notification_toast.rs | 10 +- .../ui2/src/components/notifications_panel.rs | 23 ++--- crates/ui2/src/components/palette.rs | 38 +++----- crates/ui2/src/components/panel.rs | 22 ++--- crates/ui2/src/components/panes.rs | 9 +- crates/ui2/src/components/player_stack.rs | 10 +- crates/ui2/src/components/project_panel.rs | 28 ++---- crates/ui2/src/components/recent_projects.rs | 28 ++---- crates/ui2/src/components/tab.rs | 24 ++--- crates/ui2/src/components/tab_bar.rs | 28 ++---- crates/ui2/src/components/terminal.rs | 28 ++---- crates/ui2/src/components/theme_selector.rs | 28 ++---- crates/ui2/src/components/toast.rs | 20 ++-- crates/ui2/src/components/toolbar.rs | 19 ++-- crates/ui2/src/components/traffic_lights.rs | 32 +++---- crates/ui2/src/element_ext.rs | 4 +- crates/ui2/src/elements/avatar.rs | 24 ++--- crates/ui2/src/elements/button.rs | 50 +++++----- crates/ui2/src/elements/details.rs | 24 ++--- crates/ui2/src/elements/icon.rs | 24 ++--- crates/ui2/src/elements/input.rs | 24 ++--- crates/ui2/src/elements/label.rs | 32 +++---- crates/ui2/src/elements/stack.rs | 6 +- crates/ui2/src/elements/tool_divider.rs | 14 +-- crates/ui2/src/static_data.rs | 34 +++---- crates/ui2/src/story.rs | 8 +- 44 files changed, 392 insertions(+), 695 deletions(-) diff --git a/crates/gpui2_macros/src/derive_component.rs b/crates/gpui2_macros/src/derive_component.rs index 97cfac1ae53e747894541fd6f7b222a688bafbf0..f30ff3748fd90fd745a567c54b7727cc6f97d068 100644 --- a/crates/gpui2_macros/src/derive_component.rs +++ b/crates/gpui2_macros/src/derive_component.rs @@ -19,7 +19,7 @@ pub fn derive_component(input: TokenStream) -> TokenStream { }) { quote! { #first_type_param } } else { - trait_generics.params.push(parse_quote! { V: 'static + Send + Sync }); + trait_generics.params.push(parse_quote! { V: 'static }); quote! { V } } }; diff --git a/crates/storybook2/src/stories/z_index.rs b/crates/storybook2/src/stories/z_index.rs index d68b4916c247e6aabd012dac936a899b6dba6a8e..7fa078c4e3fc70b7a3900c958f5df02c854d4390 100644 --- a/crates/storybook2/src/stories/z_index.rs +++ b/crates/storybook2/src/stories/z_index.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use gpui2::{px, rgb, Div, Hsla}; use ui::prelude::*; @@ -8,18 +7,14 @@ use crate::story::Story; /// A reimplementation of the MDN `z-index` example, found here: /// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index). #[derive(Component)] -pub struct ZIndexStory { - state_type: PhantomData, -} +pub struct ZIndexStory; -impl ZIndexStory { +impl ZIndexStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) .child(Story::title(cx, "z-index")) .child( @@ -86,23 +81,19 @@ trait Styles: Styled + Sized { } } -impl Styles for Div {} +impl Styles for Div {} #[derive(Component)] -struct ZIndexExample { - view_type: PhantomData, +struct ZIndexExample { z_index: u32, } -impl ZIndexExample { +impl ZIndexExample { pub fn new(z_index: u32) -> Self { - Self { - view_type: PhantomData, - z_index, - } + Self { z_index } } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { div() .relative() .size_full() diff --git a/crates/ui2/src/components/assistant_panel.rs b/crates/ui2/src/components/assistant_panel.rs index 25f24f14836b00a7c297e2b3faf8af3e41334e64..defd05f500904e1b6a4974300c49df8f35745fe9 100644 --- a/crates/ui2/src/components/assistant_panel.rs +++ b/crates/ui2/src/components/assistant_panel.rs @@ -1,22 +1,18 @@ -use std::marker::PhantomData; - use gpui2::{rems, AbsoluteLength}; use crate::prelude::*; use crate::{Icon, IconButton, Label, Panel, PanelSide}; #[derive(Component)] -pub struct AssistantPanel { +pub struct AssistantPanel { id: ElementId, - state_type: PhantomData, current_side: PanelSide, } -impl AssistantPanel { +impl AssistantPanel { pub fn new(id: impl Into) -> Self { Self { id: id.into(), - state_type: PhantomData, current_side: PanelSide::default(), } } @@ -26,7 +22,7 @@ impl AssistantPanel { self } - fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Component { Panel::new(self.id.clone(), cx) .children(vec![div() .flex() @@ -92,9 +88,9 @@ mod stories { Self {} } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, AssistantPanel>(cx)) + .child(Story::title_for::<_, AssistantPanel>(cx)) .child(Story::label(cx, "Default")) .child(AssistantPanel::new("assistant-panel")) } diff --git a/crates/ui2/src/components/breadcrumb.rs b/crates/ui2/src/components/breadcrumb.rs index 289c0710212fc5aaf2e2703985f26ebc832b6fda..3cba3b7248a668f5499a7da35b739a3c84711422 100644 --- a/crates/ui2/src/components/breadcrumb.rs +++ b/crates/ui2/src/components/breadcrumb.rs @@ -1,8 +1,6 @@ -use std::marker::PhantomData; use std::path::PathBuf; use gpui2::Div; - use crate::prelude::*; use crate::{h_stack, HighlightedText}; @@ -10,28 +8,26 @@ use crate::{h_stack, HighlightedText}; pub struct Symbol(pub Vec); #[derive(Component)] -pub struct Breadcrumb { - state_type: PhantomData, +pub struct Breadcrumb { path: PathBuf, symbols: Vec, } -impl Breadcrumb { +impl Breadcrumb { pub fn new(path: PathBuf, symbols: Vec) -> Self { Self { - state_type: PhantomData, path, symbols, } } - fn render_separator(&self, cx: &WindowContext) -> Div { + fn render_separator(&self, cx: &WindowContext) -> Div { let theme = theme(cx); div().child(" › ").text_color(theme.text_muted) } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view_state: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let symbols_len = self.symbols.len(); @@ -87,22 +83,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct BreadcrumbStory { - state_type: PhantomData, - } + pub struct BreadcrumbStory; - impl BreadcrumbStory { + impl BreadcrumbStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, view_state: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, view_state: &mut V, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) - .child(Story::title_for::<_, Breadcrumb>(cx)) + .child(Story::title_for::<_, Breadcrumb>(cx)) .child(Story::label(cx, "Default")) .child(Breadcrumb::new( PathBuf::from_str("crates/ui/src/components/toolbar.rs").unwrap(), diff --git a/crates/ui2/src/components/buffer.rs b/crates/ui2/src/components/buffer.rs index ffef5c4039e6f391ef423ab8f0014728682563ed..b4ccb89b5c994665a71c35f4a41924288849b97f 100644 --- a/crates/ui2/src/components/buffer.rs +++ b/crates/ui2/src/components/buffer.rs @@ -1,5 +1,3 @@ -use std::marker::PhantomData; - use gpui2::{Hsla, WindowContext}; use crate::prelude::*; @@ -110,9 +108,8 @@ impl BufferRow { } #[derive(Component, Clone)] -pub struct Buffer { +pub struct Buffer { id: ElementId, - state_type: PhantomData, rows: Option, readonly: bool, language: Option, @@ -120,11 +117,10 @@ pub struct Buffer { path: Option, } -impl Buffer { +impl Buffer { pub fn new(id: impl Into) -> Self { Self { id: id.into(), - state_type: PhantomData, rows: Some(BufferRows::default()), readonly: false, language: None, @@ -158,7 +154,7 @@ impl Buffer { self } - fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { + fn render_row(row: BufferRow, cx: &WindowContext) -> impl Component { let theme = theme(cx); let line_background = if row.current { @@ -208,7 +204,7 @@ impl Buffer { })) } - fn render_rows(&self, cx: &WindowContext) -> Vec> { + fn render_rows(&self, cx: &WindowContext) -> Vec> { match &self.rows { Some(rows) => rows .rows @@ -219,7 +215,7 @@ impl Buffer { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let rows = self.render_rows(cx); @@ -247,22 +243,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct BufferStory { - state_type: PhantomData, - } + pub struct BufferStory; - impl BufferStory { + impl BufferStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); Story::container(cx) - .child(Story::title_for::<_, Buffer>(cx)) + .child(Story::title_for::<_, Buffer>(cx)) .child(Story::label(cx, "Default")) .child(div().w(rems(64.)).h_96().child(empty_buffer_example())) .child(Story::label(cx, "Hello World (Rust)")) diff --git a/crates/ui2/src/components/chat_panel.rs b/crates/ui2/src/components/chat_panel.rs index 2800207b3423088c449f7e54d055fc6a78bb0c3c..e4494f461487365187aed31839a455bf38d655a5 100644 --- a/crates/ui2/src/components/chat_panel.rs +++ b/crates/ui2/src/components/chat_panel.rs @@ -1,17 +1,15 @@ -use std::marker::PhantomData; - use chrono::NaiveDateTime; use crate::prelude::*; use crate::{Icon, IconButton, Input, Label, LabelColor}; #[derive(Component)] -pub struct ChatPanel { +pub struct ChatPanel { element_id: ElementId, - messages: Vec>, + messages: Vec, } -impl ChatPanel { +impl ChatPanel { pub fn new(element_id: impl Into) -> Self { Self { element_id: element_id.into(), @@ -19,12 +17,12 @@ impl ChatPanel { } } - pub fn messages(mut self, messages: Vec>) -> Self { + pub fn messages(mut self, messages: Vec) -> Self { self.messages = messages; self } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .id(self.element_id.clone()) .flex() @@ -71,24 +69,22 @@ impl ChatPanel { } #[derive(Component)] -pub struct ChatMessage { - state_type: PhantomData, +pub struct ChatMessage { author: String, text: String, sent_at: NaiveDateTime, } -impl ChatMessage { +impl ChatMessage { pub fn new(author: String, text: String, sent_at: NaiveDateTime) -> Self { Self { - state_type: PhantomData, author, text, sent_at, } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .flex_col() @@ -118,20 +114,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct ChatPanelStory { - state_type: PhantomData, - } + pub struct ChatPanelStory; - impl ChatPanelStory { + impl ChatPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, ChatPanel>(cx)) + .child(Story::title_for::<_, ChatPanel>(cx)) .child(Story::label(cx, "Default")) .child( Panel::new("chat-panel-1-outer", cx) diff --git a/crates/ui2/src/components/collab_panel.rs b/crates/ui2/src/components/collab_panel.rs index 8f30b33da0f1707fb581c7f58e048170b490d091..6d2cbd8e14e402bfd2bc0d1480d4408c4767765d 100644 --- a/crates/ui2/src/components/collab_panel.rs +++ b/crates/ui2/src/components/collab_panel.rs @@ -3,23 +3,18 @@ use crate::{ static_collab_panel_channels, static_collab_panel_current_call, v_stack, Icon, List, ListHeader, ToggleState, }; -use std::marker::PhantomData; #[derive(Component)] -pub struct CollabPanel { +pub struct CollabPanel { id: ElementId, - state_type: PhantomData, } -impl CollabPanel { +impl CollabPanel { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -99,20 +94,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CollabPanelStory { - state_type: PhantomData, - } + pub struct CollabPanelStory; - impl CollabPanelStory { + impl CollabPanelStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CollabPanel>(cx)) + .child(Story::title_for::<_, CollabPanel>(cx)) .child(Story::label(cx, "Default")) .child(CollabPanel::new("collab-panel")) } diff --git a/crates/ui2/src/components/command_palette.rs b/crates/ui2/src/components/command_palette.rs index d00b9b77437ed8c8ca7e68f18540a1148d1fd817..065ee9a052bdbe219cff6b7a4b4fff68f2c81aea 100644 --- a/crates/ui2/src/components/command_palette.rs +++ b/crates/ui2/src/components/command_palette.rs @@ -1,23 +1,17 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; #[derive(Component)] -pub struct CommandPalette { +pub struct CommandPalette { id: ElementId, - state_type: PhantomData, } -impl CommandPalette { +impl CommandPalette { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) @@ -38,20 +32,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CommandPaletteStory { - state_type: PhantomData, - } + pub struct CommandPaletteStory; - impl CommandPaletteStory { + impl CommandPaletteStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CommandPalette>(cx)) + .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) .child(CommandPalette::new("command-palette")) } diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index b52051daa3eed70497d3246698937343488b5cc6..3e0323d9422af69bf5b204ca935d9756a160f5e9 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -1,14 +1,14 @@ use crate::{prelude::*, ListItemVariant}; use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader}; -pub enum ContextMenuItem { +pub enum ContextMenuItem { Header(SharedString), - Entry(Label), + Entry(Label), Separator, } -impl ContextMenuItem { - fn to_list_item(self) -> ListItem { +impl ContextMenuItem { + fn to_list_item(self) -> ListItem { match self { ContextMenuItem::Header(label) => ListSubHeader::new(label).into(), ContextMenuItem::Entry(label) => { @@ -26,23 +26,23 @@ impl ContextMenuItem { Self::Separator } - pub fn entry(label: Label) -> Self { + pub fn entry(label: Label) -> Self { Self::Entry(label) } } #[derive(Component)] -pub struct ContextMenu { - items: Vec>, +pub struct ContextMenu { + items: Vec, } -impl ContextMenu { - pub fn new(items: impl IntoIterator>) -> Self { +impl ContextMenu { + pub fn new(items: impl IntoIterator) -> Self { Self { items: items.into_iter().collect(), } } - fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(mut self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); v_stack() @@ -67,27 +67,21 @@ pub use stories::*; #[cfg(feature = "stories")] mod stories { - use std::marker::PhantomData; - use crate::story::Story; use super::*; #[derive(Component)] - pub struct ContextMenuStory { - state_type: PhantomData, - } + pub struct ContextMenuStory; - impl ContextMenuStory { + impl ContextMenuStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, ContextMenu>(cx)) + .child(Story::title_for::<_, ContextMenu>(cx)) .child(Story::label(cx, "Default")) .child(ContextMenu::new([ ContextMenuItem::header("Section header"), diff --git a/crates/ui2/src/components/copilot.rs b/crates/ui2/src/components/copilot.rs index 9e5454ee8aa39dad8a18616b64c65417886b7176..3c48ef20d085b7d5b0f9b44cb80aebf684d05e5f 100644 --- a/crates/ui2/src/components/copilot.rs +++ b/crates/ui2/src/components/copilot.rs @@ -1,22 +1,16 @@ -use std::marker::PhantomData; - use crate::{prelude::*, Button, Label, LabelColor, Modal}; #[derive(Component)] -pub struct CopilotModal { +pub struct CopilotModal { id: ElementId, - state_type: PhantomData, } -impl CopilotModal { +impl CopilotModal { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Modal::new("some-id") .title("Connect Copilot to Zed") @@ -36,20 +30,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct CopilotModalStory { - state_type: PhantomData, - } + pub struct CopilotModalStory; - impl CopilotModalStory { + impl CopilotModalStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, CopilotModal>(cx)) + .child(Story::title_for::<_, CopilotModal>(cx)) .child(Story::label(cx, "Default")) .child(CopilotModal::new("copilot-modal")) } diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index fb26dad7918cb167eade1dc742987a8b1de8357f..9c9638d0579f89e430353816a96c1cab1b2f1613 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -10,10 +10,10 @@ use crate::{ #[derive(Clone)] pub struct EditorPane { - tabs: Vec>, + tabs: Vec, path: PathBuf, symbols: Vec, - buffer: Buffer, + buffer: Buffer, buffer_search: View, is_buffer_search_open: bool, } @@ -21,10 +21,10 @@ pub struct EditorPane { impl EditorPane { pub fn new( cx: &mut WindowContext, - tabs: Vec>, + tabs: Vec, path: PathBuf, symbols: Vec, - buffer: Buffer, + buffer: Buffer, ) -> Self { Self { tabs, diff --git a/crates/ui2/src/components/facepile.rs b/crates/ui2/src/components/facepile.rs index 565396e7335900f6418c52c18c4b0552b77b04e2..898489f1edb27551880201d1704068a4b0e4913a 100644 --- a/crates/ui2/src/components/facepile.rs +++ b/crates/ui2/src/components/facepile.rs @@ -1,23 +1,19 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{Avatar, Player}; #[derive(Component)] -pub struct Facepile { - state_type: PhantomData, +pub struct Facepile { players: Vec, } -impl Facepile { +impl Facepile { pub fn new>(players: P) -> Self { Self { - state_type: PhantomData, players: players.collect(), } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let player_count = self.players.len(); let player_list = self.players.iter().enumerate().map(|(ix, player)| { let isnt_last = ix < player_count - 1; @@ -40,22 +36,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct FacepileStory { - state_type: PhantomData, - } + pub struct FacepileStory; - impl FacepileStory { + impl FacepileStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let players = static_players(); Story::container(cx) - .child(Story::title_for::<_, Facepile>(cx)) + .child(Story::title_for::<_, Facepile>(cx)) .child(Story::label(cx, "Default")) .child( div() diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index fe41de15a0e085837202122a828c752561a2d62a..2891ce6bd837fd2d63d2194387c449dcc321fa23 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use std::sync::Arc; use gpui2::MouseButton; @@ -6,19 +5,18 @@ use gpui2::MouseButton; use crate::{h_stack, prelude::*}; use crate::{ClickHandler, Icon, IconColor, IconElement}; -struct IconButtonHandlers { +struct IconButtonHandlers { click: Option>, } -impl Default for IconButtonHandlers { +impl Default for IconButtonHandlers { fn default() -> Self { Self { click: None } } } #[derive(Component)] -pub struct IconButton { - state_type: PhantomData, +pub struct IconButton { id: ElementId, icon: Icon, color: IconColor, @@ -27,10 +25,9 @@ pub struct IconButton { handlers: IconButtonHandlers, } -impl IconButton { +impl IconButton { pub fn new(id: impl Into, icon: Icon) -> Self { Self { - state_type: PhantomData, id: id.into(), icon, color: IconColor::default(), @@ -60,10 +57,7 @@ impl IconButton { self } - pub fn on_click( - mut self, - handler: impl Fn(&mut S, &mut ViewContext) + 'static + Send + Sync, - ) -> Self { + pub fn on_click(mut self, handler: impl 'static + Fn(&mut S, &mut ViewContext) + Send + Sync) -> Self { self.handlers.click = Some(Arc::new(handler)); self } diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index d77798ad6c76e6eee84cc21d6ee20d435cc08d0f..2b0eefa4eaa347bf8c6b5b3d05f985921a824298 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -1,14 +1,11 @@ use std::collections::HashSet; -use std::marker::PhantomData; use strum::{EnumIter, IntoEnumIterator}; use crate::prelude::*; #[derive(Component)] -pub struct Keybinding { - state_type: PhantomData, - +pub struct Keybinding { /// A keybinding consists of a key and a set of modifier keys. /// More then one keybinding produces a chord. /// @@ -16,10 +13,9 @@ pub struct Keybinding { keybinding: Vec<(String, ModifierKeys)>, } -impl Keybinding { +impl Keybinding { pub fn new(key: String, modifiers: ModifierKeys) -> Self { Self { - state_type: PhantomData, keybinding: vec![(key, modifiers)], } } @@ -29,12 +25,11 @@ impl Keybinding { second_note: (String, ModifierKeys), ) -> Self { Self { - state_type: PhantomData, keybinding: vec![first_note, second_note], } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div() .flex() .gap_2() @@ -55,20 +50,16 @@ impl Keybinding { } #[derive(Component)] -pub struct Key { - state_type: PhantomData, +pub struct Key { key: SharedString, } -impl Key { +impl Key { pub fn new(key: impl Into) -> Self { - Self { - state_type: PhantomData, - key: key.into(), - } + Self { key: key.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); div() @@ -174,22 +165,18 @@ mod stories { use super::*; #[derive(Component)] - pub struct KeybindingStory { - state_type: PhantomData, - } + pub struct KeybindingStory; - impl KeybindingStory { + impl KeybindingStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Component { let all_modifier_permutations = ModifierKey::iter().permutations(2); Story::container(cx) - .child(Story::title_for::<_, Keybinding>(cx)) + .child(Story::title_for::<_, Keybinding>(cx)) .child(Story::label(cx, "Single Key")) .child(Keybinding::new("Z".to_string(), ModifierKeys::new())) .child(Story::label(cx, "Single Key with Modifier")) diff --git a/crates/ui2/src/components/language_selector.rs b/crates/ui2/src/components/language_selector.rs index ebb8f152f820562bea936070a36d8ad8cb46a1d3..db42b28281171e243a1d8b7c47e6d67ac1c4dd02 100644 --- a/crates/ui2/src/components/language_selector.rs +++ b/crates/ui2/src/components/language_selector.rs @@ -1,23 +1,17 @@ -use std::marker::PhantomData; - use crate::prelude::*; use crate::{OrderMethod, Palette, PaletteItem}; #[derive(Component)] -pub struct LanguageSelector { +pub struct LanguageSelector { id: ElementId, - state_type: PhantomData, } -impl LanguageSelector { +impl LanguageSelector { pub fn new(id: impl Into) -> Self { - Self { - id: id.into(), - state_type: PhantomData, - } + Self { id: id.into() } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { div().id(self.id.clone()).child( Palette::new("palette") .items(vec![ @@ -49,20 +43,16 @@ mod stories { use super::*; #[derive(Component)] - pub struct LanguageSelectorStory { - state_type: PhantomData, - } + pub struct LanguageSelectorStory; - impl LanguageSelectorStory { + impl LanguageSelectorStory { pub fn new() -> Self { - Self { - state_type: PhantomData, - } + Self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { Story::container(cx) - .child(Story::title_for::<_, LanguageSelector>(cx)) + .child(Story::title_for::<_, LanguageSelector>(cx)) .child(Story::label(cx, "Default")) .child(LanguageSelector::new("language-selector")) } diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index b1b3f506eab67aa94ac9a7adfa0db8df03bf2ef3..0bf413e2172654db6b2828cc383928ec05fa6499 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -1,5 +1,3 @@ -use std::marker::PhantomData; - use gpui2::{div, relative, Div}; use crate::settings::user_settings; @@ -18,8 +16,7 @@ pub enum ListItemVariant { } #[derive(Component)] -pub struct ListHeader { - state_type: PhantomData, +pub struct ListHeader { label: SharedString, left_icon: Option, variant: ListItemVariant, @@ -27,10 +24,9 @@ pub struct ListHeader { toggleable: Toggleable, } -impl ListHeader { +impl ListHeader { pub fn new(label: impl Into) -> Self { Self { - state_type: PhantomData, label: label.into(), left_icon: None, variant: ListItemVariant::default(), @@ -59,7 +55,7 @@ impl ListHeader { self } - fn disclosure_control(&self) -> Div { + fn disclosure_control(&self) -> Div { let is_toggleable = self.toggleable != Toggleable::NotToggleable; let is_toggled = Toggleable::is_toggled(&self.toggleable); @@ -92,7 +88,7 @@ impl ListHeader { } } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { let theme = theme(cx); let is_toggleable = self.toggleable != Toggleable::NotToggleable; @@ -135,17 +131,15 @@ impl ListHeader { } #[derive(Component)] -pub struct ListSubHeader { - state_type: PhantomData, +pub struct ListSubHeader { label: SharedString, left_icon: Option, variant: ListItemVariant, } -impl ListSubHeader { +impl ListSubHeader { pub fn new(label: impl Into) -> Self { Self { - state_type: PhantomData, label: label.into(), left_icon: None, variant: ListItemVariant::default(), @@ -157,7 +151,7 @@ impl ListSubHeader { self } - fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { + fn render(self, _view: &mut S, cx: &mut ViewContext) -> impl Component { h_stack().flex_1().w_full().relative().py_1().child( div() .h_6() @@ -198,38 +192,38 @@ pub enum ListEntrySize { } #[derive(Component)] -pub enum ListItem { - Entry(ListEntry), +pub enum ListItem { + Entry(ListEntry), Details(ListDetailsEntry), - Separator(ListSeparator), - Header(ListSubHeader), + Separator(ListSeparator), + Header(ListSubHeader), } -impl From> for ListItem { - fn from(entry: ListEntry) -> Self { +impl From for ListItem { + fn from(entry: ListEntry) -> Self { Self::Entry(entry) } } -impl From> for ListItem { +impl From> for ListItem { fn from(entry: ListDetailsEntry) -> Self { Self::Details(entry) } } -impl From> for ListItem { - fn from(entry: ListSeparator) -> Self { +impl From for ListItem { + fn from(entry: ListSeparator) -> Self { Self::Separator(entry) } } -impl From> for ListItem { - fn from(entry: ListSubHeader) -> Self { +impl From for ListItem { + fn from(entry: ListSubHeader) -> Self { Self::Header(entry) } } -impl ListItem { +impl ListItem { fn render(self, view: &mut S, cx: &mut ViewContext) -> impl Component { match self { ListItem::Entry(entry) => div().child(entry.render(view, cx)), @@ -239,11 +233,11 @@ impl ListItem { } } - pub fn new(label: Label) -> Self { + pub fn new(label: Label) -> Self { Self::Entry(ListEntry::new(label)) } - pub fn as_entry(&mut self) -> Option<&mut ListEntry> { + pub fn as_entry(&mut self) -> Option<&mut ListEntry> { if let Self::Entry(entry) = self { Some(entry) } else { @@ -253,10 +247,10 @@ impl ListItem { } #[derive(Component)] -pub struct ListEntry { +pub struct ListEntry { disclosure_control_style: DisclosureControlVisibility, indent_level: u32, - label: Option>, + label: Option