diff --git a/crates/storybook2/src/storybook2.rs b/crates/storybook2/src/storybook2.rs index 920209cacf..758fcd9a96 100644 --- a/crates/storybook2/src/storybook2.rs +++ b/crates/storybook2/src/storybook2.rs @@ -12,8 +12,8 @@ use std::sync::Arc; use clap::Parser; use gpui3::{ - div, px, size, view, AnyView, Bounds, Context, Element, ViewContext, WindowBounds, - WindowOptions, + div, px, size, view, AnyView, BorrowAppContext, Bounds, Context, Element, ViewContext, + WindowBounds, WindowOptions, }; use log::LevelFilter; use simplelog::SimpleLogger; @@ -68,7 +68,11 @@ fn main() { }, move |cx| { view( - cx.entity(|cx| StoryWrapper::new(selector.story(cx), theme)), + cx.entity(|cx| { + cx.with_global(theme.clone(), |cx| { + StoryWrapper::new(selector.story(cx), theme) + }) + }), StoryWrapper::render, ) }, diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rs index bbbe9d1c37..cbe5a2daa6 100644 --- a/crates/ui2/src/components.rs +++ b/crates/ui2/src/components.rs @@ -1,6 +1,7 @@ mod assistant_panel; mod breadcrumb; mod buffer; +mod buffer_search; mod chat_panel; mod collab_panel; mod command_palette; @@ -33,6 +34,7 @@ mod workspace; pub use assistant_panel::*; pub use breadcrumb::*; pub use buffer::*; +pub use buffer_search::*; pub use chat_panel::*; pub use collab_panel::*; pub use command_palette::*; diff --git a/crates/ui2/src/components/buffer_search.rs b/crates/ui2/src/components/buffer_search.rs new file mode 100644 index 0000000000..95e328091c --- /dev/null +++ b/crates/ui2/src/components/buffer_search.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; +use crate::EditorPane; + +#[derive(Element)] +#[element(view_state = "EditorPane")] +pub struct BufferSearch {} + +impl BufferSearch { + pub fn new() -> Self { + Self {} + } + + fn render( + &mut self, + _view: &mut EditorPane, + cx: &mut ViewContext, + ) -> impl Element { + div().child("This is where Buffer Search goes.") + } +} diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs index 8465cd9d1d..eb40b373e4 100644 --- a/crates/ui2/src/components/editor_pane.rs +++ b/crates/ui2/src/components/editor_pane.rs @@ -1,43 +1,75 @@ use std::path::PathBuf; +use gpui3::{view, Context, View}; + use crate::prelude::*; -use crate::{v_stack, Breadcrumb, Buffer, Icon, IconButton, Symbol, Tab, TabBar, Toolbar}; +use crate::{ + hello_world_rust_editor_with_status_example, v_stack, Breadcrumb, Buffer, BufferSearch, Icon, + IconButton, IconColor, Symbol, Tab, TabBar, Toolbar, +}; -pub struct Editor { - pub tabs: Vec>, - pub path: PathBuf, - pub symbols: Vec, - pub buffer: Buffer, +#[derive(Clone)] +pub struct EditorPane { + tabs: Vec>, + path: PathBuf, + symbols: Vec, + buffer: Buffer, + is_buffer_search_open: bool, } -#[derive(Element)] -pub struct EditorPane { - editor: Editor, -} - -impl EditorPane { - pub fn new(editor: Editor) -> Self { - Self { editor } +impl EditorPane { + pub fn new( + tabs: Vec>, + path: PathBuf, + symbols: Vec, + buffer: Buffer, + ) -> Self { + Self { + tabs, + path, + symbols, + buffer, + is_buffer_search_open: false, + } } - fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { + pub fn toggle_buffer_search(&mut self, cx: &mut ViewContext) { + self.is_buffer_search_open = !self.is_buffer_search_open; + + cx.notify(); + } + + pub fn view(cx: &mut WindowContext) -> View { + let theme = theme(cx); + + view( + cx.entity(|cx| hello_world_rust_editor_with_status_example(&theme)), + Self::render, + ) + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { v_stack() .w_full() .h_full() .flex_1() - .child(TabBar::new(self.editor.tabs.clone())) + .child(TabBar::new(self.tabs.clone())) .child( Toolbar::new() - .left_item(Breadcrumb::new( - self.editor.path.clone(), - self.editor.symbols.clone(), - )) + .left_item(Breadcrumb::new(self.path.clone(), self.symbols.clone())) .right_items(vec![ - IconButton::new(Icon::InlayHint).into_any(), - IconButton::new(Icon::MagnifyingGlass).into_any(), - IconButton::new(Icon::MagicWand).into_any(), + IconButton::new(Icon::InlayHint), + IconButton::::new(Icon::MagnifyingGlass) + .when(self.is_buffer_search_open, |this| { + this.color(IconColor::Accent) + }) + .on_click(|editor, cx| { + editor.toggle_buffer_search(cx); + }), + IconButton::new(Icon::MagicWand), ]), ) - .child(self.editor.buffer.clone()) + .children(Some(BufferSearch::new()).filter(|_| self.is_buffer_search_open)) + .child(self.buffer.clone()) } } diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index d1b2835536..0df024d453 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -1,17 +1,18 @@ use chrono::DateTime; use gpui3::{px, relative, rems, view, Context, Size, View}; +use crate::prelude::*; use crate::{ - hello_world_rust_editor_with_status_example, theme, v_stack, AssistantPanel, Button, - ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector, Pane, PaneGroup, - Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, - TitleBar, Toast, ToastOrigin, + theme, v_stack, AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, + LanguageSelector, NotificationToast, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, + ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin, }; -use crate::{prelude::*, NotificationToast}; #[derive(Clone)] pub struct Workspace { title_bar: View, + editor_1: View, + editor_2: View, show_project_panel: bool, show_collab_panel: bool, show_chat_panel: bool, @@ -28,6 +29,8 @@ impl Workspace { pub fn new(cx: &mut ViewContext) -> Self { Self { title_bar: TitleBar::view(cx), + editor_1: EditorPane::view(cx), + editor_2: EditorPane::view(cx), show_project_panel: true, show_collab_panel: false, show_chat_panel: true, @@ -127,9 +130,7 @@ impl Workspace { height: temp_size, }, ) - .child(EditorPane::new( - hello_world_rust_editor_with_status_example(&theme), - )), + .child(self.editor_1.clone()), Pane::new( ScrollState::default(), Size { @@ -149,9 +150,7 @@ impl Workspace { height: relative(1.).into(), }, ) - .child(EditorPane::new( - hello_world_rust_editor_with_status_example(&theme), - ))], + .child(self.editor_2.clone())], SplitDirection::Vertical, ), ], diff --git a/crates/ui2/src/static_data.rs b/crates/ui2/src/static_data.rs index 6a43999bf6..3909f3848b 100644 --- a/crates/ui2/src/static_data.rs +++ b/crates/ui2/src/static_data.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use rand::Rng; use crate::{ - Buffer, BufferRow, BufferRows, Editor, FileSystemStatus, GitStatus, HighlightColor, + Buffer, BufferRow, BufferRows, EditorPane, FileSystemStatus, GitStatus, HighlightColor, HighlightedLine, HighlightedText, Icon, Keybinding, Label, LabelColor, ListEntry, ListEntrySize, ListItem, Livestream, MicStatus, ModifierKeys, PaletteItem, Player, PlayerCallStatus, PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, Theme, ToggleState, @@ -597,26 +597,24 @@ pub fn example_editor_actions() -> Vec() -> Editor { - Editor { - tabs: static_tabs_example(), - path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), - symbols: vec![], - buffer: empty_buffer_example(), - } +pub fn empty_editor_example() -> EditorPane { + EditorPane::new( + static_tabs_example(), + PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + vec![], + empty_buffer_example(), + ) } pub fn empty_buffer_example() -> Buffer { Buffer::new().set_rows(Some(BufferRows::default())) } -pub fn hello_world_rust_editor_example( - theme: &Theme, -) -> Editor { - Editor { - tabs: static_tabs_example(), - path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), - symbols: vec![Symbol(vec![ +pub fn hello_world_rust_editor_example(theme: &Theme) -> EditorPane { + EditorPane::new( + static_tabs_example(), + PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + vec![Symbol(vec![ HighlightedText { text: "fn ".to_string(), color: HighlightColor::Keyword.hsla(&theme), @@ -626,8 +624,8 @@ pub fn hello_world_rust_editor_example( color: HighlightColor::Function.hsla(&theme), }, ])], - buffer: hello_world_rust_buffer_example(theme), - } + hello_world_rust_buffer_example(theme), + ) } pub fn hello_world_rust_buffer_example( @@ -750,13 +748,11 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec { ] } -pub fn hello_world_rust_editor_with_status_example( - theme: &Theme, -) -> Editor { - Editor { - tabs: static_tabs_example(), - path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), - symbols: vec![Symbol(vec![ +pub fn hello_world_rust_editor_with_status_example(theme: &Theme) -> EditorPane { + EditorPane::new( + static_tabs_example(), + PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + vec![Symbol(vec![ HighlightedText { text: "fn ".to_string(), color: HighlightColor::Keyword.hsla(&theme), @@ -766,8 +762,8 @@ pub fn hello_world_rust_editor_with_status_example(