diff --git a/crates/auto_update2/src/update_notification.rs b/crates/auto_update2/src/update_notification.rs index b77682c9aea527100aa03c49ac5e249f19569b8c..03a71bcabbba6111953a0754ef3455b317f771dd 100644 --- a/crates/auto_update2/src/update_notification.rs +++ b/crates/auto_update2/src/update_notification.rs @@ -1,4 +1,4 @@ -use gpui::{div, Div, EventEmitter, ParentComponent, Render, SemanticVersion, ViewContext}; +use gpui::{div, Div, EventEmitter, ParentElement, Render, SemanticVersion, ViewContext}; use menu::Cancel; use workspace::notifications::NotificationEvent; @@ -8,7 +8,7 @@ pub struct UpdateNotification { impl EventEmitter for UpdateNotification {} -impl Render for UpdateNotification { +impl Render for UpdateNotification { type Element = Div; fn render(&mut self, _cx: &mut gpui::ViewContext) -> Self::Element { diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rs index ef8e4cb5fe3e7de549817cb2c6c930ace6676168..1296f35c55f05424f13045e2688a740b248b1704 100644 --- a/crates/command_palette2/src/command_palette.rs +++ b/crates/command_palette2/src/command_palette.rs @@ -1,9 +1,8 @@ use collections::{CommandPaletteFilter, HashMap}; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ - actions, actions, div, prelude::*, prelude::*, Action, AppContext, Component, Dismiss, Div, - EventEmitter, FocusHandle, FocusableView, Keystroke, ManagedView, Manager, ParentComponent, - ParentElement, Render, Render, Styled, View, ViewContext, VisualContext, WeakView, + actions, div, prelude::*, Action, AppContext, Div, EventEmitter, FocusHandle, FocusableView, + Keystroke, Manager, ParentElement, Render, Styled, View, ViewContext, VisualContext, WeakView, }; use picker::{Picker, PickerDelegate}; use std::{ diff --git a/crates/diagnostics2/src/diagnostics.rs b/crates/diagnostics2/src/diagnostics.rs index 623b63631908dd65b7f4ca633677a6ae8da3136f..cbaa458c5d5f657fd968a8ddaae8b9ff626f368c 100644 --- a/crates/diagnostics2/src/diagnostics.rs +++ b/crates/diagnostics2/src/diagnostics.rs @@ -14,8 +14,8 @@ use editor::{ use futures::future::try_join_all; use gpui::{ actions, div, AnyElement, AnyView, AppContext, Component, Context, Div, EventEmitter, - FocusEvent, FocusHandle, Focusable, FocusableComponent, FocusableView, InteractiveComponent, - Model, ParentComponent, Render, SharedString, Styled, Subscription, Task, View, ViewContext, + FocusEvent, FocusHandle, Focusable, FocusableElement, FocusableView, InteractiveElement, Model, + ParentElement, Render, RenderOnce, SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, }; use language::{ @@ -90,7 +90,7 @@ struct DiagnosticGroupState { impl EventEmitter for ProjectDiagnosticsEditor {} -impl Render for ProjectDiagnosticsEditor { +impl Render for ProjectDiagnosticsEditor { type Element = Focusable>; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { @@ -792,13 +792,15 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock { .when_some(diagnostic.code.as_ref(), |stack, code| { stack.child(Label::new(code.clone())) }) - .render() + .render_into_any() }) } pub(crate) fn render_summary(summary: &DiagnosticSummary) -> AnyElement { if summary.error_count == 0 && summary.warning_count == 0 { - Label::new("No problems").render() + let label = Label::new("No problems"); + label.render_into_any() + //.render() } else { h_stack() .bg(gpui::red()) @@ -806,7 +808,7 @@ pub(crate) fn render_summary(summary: &DiagnosticSummary) -> AnyElem .child(Label::new(summary.error_count.to_string())) .child(IconElement::new(Icon::ExclamationTriangle)) .child(Label::new(summary.warning_count.to_string())) - .render() + .render_into_any() } } diff --git a/crates/diagnostics2/src/items.rs b/crates/diagnostics2/src/items.rs index dd1b7d98cf627c95d904a9483d56b6dcd55df35e..1d5183634f06bba5fd094c62cd8dfbfb753b9983 100644 --- a/crates/diagnostics2/src/items.rs +++ b/crates/diagnostics2/src/items.rs @@ -1,8 +1,8 @@ use collections::HashSet; use editor::{Editor, GoToDiagnostic}; use gpui::{ - rems, Div, EventEmitter, InteractiveComponent, ParentComponent, Render, Stateful, - StatefulInteractiveComponent, Styled, Subscription, View, ViewContext, WeakView, + rems, Div, EventEmitter, InteractiveElement, ParentElement, Render, Stateful, + StatefulInteractiveElement, Styled, Subscription, View, ViewContext, WeakView, }; use language::Diagnostic; use lsp::LanguageServerId; @@ -21,7 +21,7 @@ pub struct DiagnosticIndicator { _observe_active_editor: Option, } -impl Render for DiagnosticIndicator { +impl Render for DiagnosticIndicator { type Element = Stateful>; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { diff --git a/crates/diagnostics2/src/toolbar_controls.rs b/crates/diagnostics2/src/toolbar_controls.rs index 8d4efe00c33bec599aa9af791505d9c5d0c428c9..a22217f0a1cbdb4ff45faa1bcb340f111ff4ee36 100644 --- a/crates/diagnostics2/src/toolbar_controls.rs +++ b/crates/diagnostics2/src/toolbar_controls.rs @@ -1,5 +1,5 @@ use crate::ProjectDiagnosticsEditor; -use gpui::{div, Div, EventEmitter, ParentComponent, Render, ViewContext, WeakView}; +use gpui::{div, Div, EventEmitter, ParentElement, Render, ViewContext, WeakView}; use ui::{Icon, IconButton, Tooltip}; use workspace::{item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView}; @@ -7,7 +7,7 @@ pub struct ToolbarControls { editor: Option>, } -impl Render for ToolbarControls { +impl Render for ToolbarControls { type Element = Div; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index dad44f212db200885e45071cec202f731cd0f4f0..5e40f5368ede0af07626e8baf6ef68887be66019 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -4403,7 +4403,6 @@ impl Editor { } }) .color(ui::TextColor::Muted) - .render() }) }) .flatten() diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs index 60ebc9138bca3a5b3dc50b9b9af1babe185a53ba..2e7655298a4ddd151bc89222f4e34cb1722c6c1d 100644 --- a/crates/file_finder2/src/file_finder.rs +++ b/crates/file_finder2/src/file_finder.rs @@ -2,10 +2,9 @@ use collections::HashMap; use editor::{scroll::autoscroll::Autoscroll, Bias, Editor}; use fuzzy::{CharBag, PathMatch, PathMatchCandidate}; use gpui::{ - actions, div, AppContext, Component, Dismiss, Div, EventEmitter, FocusHandle, FocusableView, - InteractiveComponent, InteractiveElement, ManagedView, Manager, Model, ParentComponent, - ParentElement, Render, RenderOnce, Styled, Styled, Task, View, ViewContext, VisualContext, - WeakView, + actions, div, AppContext, Div, EventEmitter, FocusHandle, FocusableView, InteractiveElement, + Manager, Model, ParentElement, Render, RenderOnce, Styled, Task, View, ViewContext, + VisualContext, WeakView, }; use picker::{Picker, PickerDelegate}; use project::{PathMatchCandidateSet, Project, ProjectPath, WorktreeId}; diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rs index 8c260ca717d12a699575b655f026a56d8bb292e7..9b3666ea5c02df827b0d575a8c0c2dee9395e9f6 100644 --- a/crates/go_to_line2/src/go_to_line.rs +++ b/crates/go_to_line2/src/go_to_line.rs @@ -1,8 +1,7 @@ use editor::{display_map::ToDisplayPoint, scroll::autoscroll::Autoscroll, Editor}; use gpui::{ actions, div, prelude::*, AppContext, Div, EventEmitter, FocusHandle, FocusableView, Manager, - ParentComponent, Render, SharedString, Styled, Subscription, View, ViewContext, VisualContext, - WindowContext, + Render, SharedString, Styled, Subscription, View, ViewContext, VisualContext, WindowContext, }; use text::{Bias, Point}; use theme::ActiveTheme; diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rs index b5fd6e8774db2220d33a92e45f97ce31b0d3676b..c68684c8d39dc676294a62cfdd98da8e81bb27b3 100644 --- a/crates/gpui2/src/elements/text.rs +++ b/crates/gpui2/src/elements/text.rs @@ -256,19 +256,35 @@ impl TextState { let layout_id = cx.request_measured_layout(Default::default(), rem_size, { let element_state = self.clone(); - move |known_dimensions, _| { + + move |known_dimensions, available_space| { + let wrap_width = known_dimensions.width.or(match available_space.width { + crate::AvailableSpace::Definite(x) => Some(x), + _ => None, + }); + + if let Some(text_state) = element_state.0.lock().as_ref() { + if text_state.size.is_some() + && (wrap_width.is_none() || wrap_width == text_state.wrap_width) + { + return text_state.size.unwrap(); + } + } + let Some(lines) = text_system .shape_text( &text, font_size, &runs[..], - known_dimensions.width, // Wrap if we know the width. + wrap_width, // Wrap if we know the width. ) .log_err() else { element_state.lock().replace(TextStateInner { lines: Default::default(), line_height, + wrap_width, + size: Some(Size::default()), }); return Size::default(); }; @@ -280,9 +296,12 @@ impl TextState { size.width = size.width.max(line_size.width); } - element_state - .lock() - .replace(TextStateInner { lines, line_height }); + element_state.lock().replace(TextStateInner { + lines, + line_height, + wrap_width, + size: Some(size), + }); size } diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index cfd30eb5b61b0796fa0578e3e39bfa3b11ceb4db..c17e7e06f4cf103f7ec23e621ea6f47a57885b9c 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -2,14 +2,14 @@ use crate::{ key_dispatch::DispatchActionListener, px, size, Action, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, CursorStyle, DevicePixels, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect, Entity, EntityId, - EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId, Hsla, ImageData, - InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, LayoutId, Model, ModelContext, - Modifiers, MonochromeSprite, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, - Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, - PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, RenderImageParams, - RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, SubscriberSet, - Subscription, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, - WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS, + EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId, GlyphId, Hsla, + ImageData, InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, LayoutId, Model, + ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseDownEvent, MouseMoveEvent, + MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, + PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, + RenderImageParams, RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, + Style, SubscriberSet, Subscription, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, + VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS, }; use anyhow::{anyhow, Context as _, Result}; use collections::HashMap; diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index f56ac6d533016b4aa0bf584e210750e8bcf6a8f5..da3ada4c10936a626f143f0392544724787b7217 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -247,7 +247,6 @@ impl ProjectPanel { let mut old_dock_position = this.position(cx); ProjectPanelSettings::register(cx); cx.observe_global::(move |this, cx| { - dbg!("OLA!"); let new_dock_position = this.position(cx); if new_dock_position != old_dock_position { old_dock_position = new_dock_position; diff --git a/crates/terminal_view2/src/terminal_view.rs b/crates/terminal_view2/src/terminal_view.rs index 0c099de76d50e3ebc2c6446d416e1f4ee57c9165..1bc7ad02a4e24ce3bda2f76d478850d215a42842 100644 --- a/crates/terminal_view2/src/terminal_view.rs +++ b/crates/terminal_view2/src/terminal_view.rs @@ -755,7 +755,7 @@ impl Item for TerminalView { div() .child(IconElement::new(Icon::Terminal)) - .child(title) + .child(Label::new(title)) .into_any() } diff --git a/crates/ui2/src/components/button.rs b/crates/ui2/src/components/button.rs index f22727ae644b327d811a4e6cfef2f5ab6282ed24..efbb4c9e72e3fc5ff5a7f4a37873cee4bf2e167d 100644 --- a/crates/ui2/src/components/button.rs +++ b/crates/ui2/src/components/button.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use gpui::{ - div, DefiniteLength, Div, Hsla, MouseButton, RenderOnce, Stateful, StatefulInteractiveElement, + DefiniteLength, Div, Hsla, MouseButton, RenderOnce, Stateful, StatefulInteractiveElement, WindowContext, }; diff --git a/crates/ui2/src/components/context_menu.rs b/crates/ui2/src/components/context_menu.rs index bbb82e7f1bd2577eec9da43673fc16256c988d69..81a73e5f778b220785ee7c796963ddc86b19e509 100644 --- a/crates/ui2/src/components/context_menu.rs +++ b/crates/ui2/src/components/context_menu.rs @@ -1,18 +1,12 @@ use std::cell::RefCell; use std::rc::Rc; -use crate::prelude::*; -use crate::{v_stack, Label, List, ListEntry, ListItem, ListSeparator, ListSubHeader}; +use crate::{prelude::*, v_stack, List, ListItem}; +use crate::{ListEntry, ListSeparator, ListSubHeader}; use gpui::{ -<<<<<<< HEAD - overlay, px, Action, AnchorCorner, AnyElement, Bounds, Dismiss, DispatchPhase, Div, - FocusHandle, LayoutId, ManagedView, MouseButton, MouseDownEvent, Pixels, Point, Render, - RenderOnce, View, -======= overlay, px, Action, AnchorCorner, AnyElement, AppContext, Bounds, DispatchPhase, Div, EventEmitter, FocusHandle, FocusableView, LayoutId, ManagedView, Manager, MouseButton, - MouseDownEvent, Pixels, Point, Render, View, VisualContext, WeakView, ->>>>>>> main + MouseDownEvent, Pixels, Point, Render, RenderOnce, View, VisualContext, WeakView, }; pub enum ContextMenuItem { @@ -30,15 +24,15 @@ pub struct ContextMenu { handle: WeakView, } -impl FocusableView for ContextMenu { +impl FocusableView for ContextMenu { fn focus_handle(&self, _cx: &AppContext) -> FocusHandle { self.focus_handle.clone() } } -impl EventEmitter for ContextMenu {} +impl EventEmitter for ContextMenu {} -impl ContextMenu { +impl ContextMenu { pub fn build( cx: &mut ViewContext, f: impl FnOnce(Self, &mut ViewContext) -> Self, @@ -92,11 +86,7 @@ impl ContextMenu { } } -<<<<<<< HEAD -impl Render for ContextMenu { -======= -impl Render for ContextMenu { ->>>>>>> main +impl Render for ContextMenu { type Element = Div; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { @@ -324,7 +314,7 @@ mod stories { actions!(PrintCurrentDate, PrintBestFood); - fn build_menu( + fn build_menu>( cx: &mut ViewContext, header: impl Into, ) -> View> { diff --git a/crates/ui2/src/components/icon_button.rs b/crates/ui2/src/components/icon_button.rs index ea015e95a6889b9a0b9acf14d08ff1f0e4fd99ec..416c14fe2df2cce8a9a076c16c547388aa270482 100644 --- a/crates/ui2/src/components/icon_button.rs +++ b/crates/ui2/src/components/icon_button.rs @@ -58,7 +58,10 @@ impl Component for IconButton { .p_1() .bg(bg_color) .cursor_pointer() - .hover(|style| style.bg(bg_hover_color)) + // Nate: Trying to figure out the right places we want to show a + // hover state here. I think it is a bit heavy to have it on every + // place we use an icon button. + // .hover(|style| style.bg(bg_hover_color)) .active(|style| style.bg(bg_active_color)) .child(IconElement::new(self.icon).color(icon_color)); diff --git a/crates/ui2/src/components/keybinding.rs b/crates/ui2/src/components/keybinding.rs index fa5898d0cacc8775f86914aca5ababc272759451..7056dcce56fbe20b3057e3b83fc3d21d3fbbfcc0 100644 --- a/crates/ui2/src/components/keybinding.rs +++ b/crates/ui2/src/components/keybinding.rs @@ -1,6 +1,5 @@ use crate::prelude::*; use gpui::{Action, Div, RenderOnce}; -use strum::EnumIter; #[derive(RenderOnce, Clone)] pub struct KeyBinding { @@ -72,22 +71,6 @@ impl Key { } } -// NOTE: The order the modifier keys appear in this enum impacts the order in -// which they are rendered in the UI. -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] -pub enum ModifierKey { - Control, - Alt, - Command, - Shift, -} - -actions!(NoAction); - -pub fn binding(key: &str) -> gpui::KeyBinding { - gpui::KeyBinding::new(key, NoAction {}, None) -} - #[cfg(feature = "stories")] pub use stories::*; @@ -95,7 +78,7 @@ pub use stories::*; mod stories { use super::*; pub use crate::KeyBinding; - use crate::{binding, Story}; + use crate::Story; use gpui::{actions, Div, Render}; use itertools::Itertools; pub struct KeybindingStory; @@ -106,7 +89,7 @@ mod stories { gpui::KeyBinding::new(key, NoAction {}, None) } - impl Render for KeybindingStory { + impl Render for KeybindingStory { type Element = Div; fn render(&mut self, cx: &mut ViewContext) -> Self::Element { diff --git a/crates/ui2/src/components/list.rs b/crates/ui2/src/components/list.rs index 29510f873f95bbdfa224d60d56ba24dae3dd1fd3..485253d4dfc2db6918be7133518e3e9ce0bda77f 100644 --- a/crates/ui2/src/components/list.rs +++ b/crates/ui2/src/components/list.rs @@ -1,4 +1,4 @@ -use gpui::{div, Action, Div, RenderOnce}; +use gpui::{div, Div, RenderOnce, Stateful, StatefulInteractiveElement}; use std::rc::Rc; use crate::settings::user_settings; @@ -232,7 +232,7 @@ pub enum ListEntrySize { Medium, } -#[derive(RenderOnce, Clone)] +#[derive(Clone)] pub enum ListItem { Entry(ListEntry), Separator(ListSeparator), @@ -257,19 +257,7 @@ impl From for ListItem { } } -impl Component for ListItem { - type Rendered = Div; - - fn render(self, view: &mut V, cx: &mut ViewContext) -> Self::Rendered { - match self { - ListItem::Entry(entry) => div().child(entry.render(ix, cx)), - ListItem::Separator(separator) => div().child(separator.render(view, cx)), - ListItem::Header(header) => div().child(header.render(view, cx)), - } - } -} - -impl ListItem { +impl ListItem { pub fn new(label: Label) -> Self { Self::Entry(ListEntry::new(label)) } @@ -281,6 +269,14 @@ impl ListItem { None } } + + fn render(self, view: &mut V, ix: usize, cx: &mut ViewContext) -> Div { + match self { + ListItem::Entry(entry) => div().child(entry.render(ix, cx)), + ListItem::Separator(separator) => div().child(separator.render(view, cx)), + ListItem::Header(header) => div().child(header.render(view, cx)), + } + } } // #[derive(RenderOnce)] @@ -458,7 +454,7 @@ impl Component for ListSeparator { #[derive(RenderOnce)] pub struct List { - items: Vec, + items: Vec>, /// Message to display when the list is empty /// Defaults to "No items" empty_message: SharedString, @@ -471,7 +467,12 @@ impl Component for List { fn render(self, view: &mut V, cx: &mut ViewContext) -> Self::Rendered { let list_content = match (self.items.is_empty(), self.toggle) { - (false, _) => div().children(self.items), + (false, _) => div().children( + self.items + .into_iter() + .enumerate() + .map(|(ix, item)| item.render(view, ix, cx)), + ), (true, Toggle::Toggled(false)) => div(), (true, _) => { div().child(Label::new(self.empty_message.clone()).color(TextColor::Muted)) @@ -487,7 +488,7 @@ impl Component for List { } impl List { - pub fn new(items: Vec) -> Self { + pub fn new(items: Vec>) -> Self { Self { items, empty_message: "No items".into(), @@ -511,7 +512,7 @@ impl List { self } - fn render(self, _view: &mut V, cx: &mut ViewContext) -> impl Element { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl Element { let list_content = match (self.items.is_empty(), self.toggle) { (false, _) => div().children( self.items diff --git a/crates/workspace2/src/notifications.rs b/crates/workspace2/src/notifications.rs index df5bbfdd1231656a62a946d816dbe4d78b4093e4..e132d821ef97db447a777b7d6d0b696c0a03b735 100644 --- a/crates/workspace2/src/notifications.rs +++ b/crates/workspace2/src/notifications.rs @@ -15,7 +15,7 @@ pub enum NotificationEvent { pub trait Notification: EventEmitter + Render {} -impl + Render> Notification for V {} +impl + Render> Notification for V {} pub trait NotificationHandle: Send { fn id(&self) -> EntityId;