From 3a72f2122a221348a7796dda1c982a4ea7f50c0d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 11:12:16 -0700 Subject: [PATCH 1/6] Implement Editor::single_line --- crates/editor2/src/editor.rs | 25 ++++++++++--------------- crates/editor2/src/element.rs | 17 +++++++++++------ crates/gpui2/src/style.rs | 4 ++++ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 13afe8aebac141f9d202ab363cdae0ed0cb62f79..99de3733a16f96fbbad5510c181071b5753c4c7c 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -36,10 +36,10 @@ pub use element::{ use futures::FutureExt; use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{ - actions, div, px, AnyElement, AppContext, BackgroundExecutor, Context, DispatchContext, Div, - Element, Entity, EventEmitter, FocusHandle, FontStyle, FontWeight, Hsla, Model, Pixels, Render, - Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, WeakView, - WindowContext, + actions, div, px, relative, AnyElement, AppContext, BackgroundExecutor, Context, + DispatchContext, Div, Element, Entity, EventEmitter, FocusHandle, FontStyle, FontWeight, Hsla, + Model, Pixels, Render, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext, + WeakView, WindowContext, }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; @@ -593,7 +593,6 @@ pub struct EditorStyle { pub background: Hsla, pub local_player: PlayerColor, pub text: TextStyle, - pub line_height_scalar: f32, pub scrollbar_width: Pixels, pub syntax: Arc, pub diagnostic_style: DiagnosticStyle, @@ -1795,14 +1794,11 @@ impl InlayHintRefreshReason { } impl Editor { - // pub fn single_line( - // field_editor_style: Option>, - // cx: &mut ViewContext, - // ) -> Self { - // let buffer = cx.build_model(|cx| Buffer::new(0, cx.model_id() as u64, String::new())); - // let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); - // Self::new(EditorMode::SingleLine, buffer, None, field_editor_style, cx) - // } + pub fn single_line(cx: &mut ViewContext) -> Self { + let buffer = cx.build_model(|cx| Buffer::new(0, cx.entity_id().as_u64(), String::new())); + let buffer = cx.build_model(|cx| MultiBuffer::singleton(buffer, cx)); + Self::new(EditorMode::SingleLine, buffer, None, cx) + } // pub fn multi_line( // field_editor_style: Option>, @@ -9372,14 +9368,13 @@ impl Render for Editor { font_size: settings.buffer_font_size.into(), font_weight: FontWeight::NORMAL, font_style: FontStyle::Normal, - line_height: Default::default(), + line_height: relative(settings.buffer_line_height.value()), underline: None, }; EditorElement::new(EditorStyle { background: cx.theme().colors().editor_background, local_player: cx.theme().players().local(), text: text_style, - line_height_scalar: settings.buffer_line_height.value(), scrollbar_width: px(12.), syntax: cx.theme().syntax().clone(), diagnostic_style: cx.theme().diagnostic_style(), diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 09f9ef1a59972e78d3a9977d46bba6d2717f1c59..2236f8aeaf596caf87678e1962d460ea773ebf35 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -8,10 +8,11 @@ use crate::{ use anyhow::Result; use collections::{BTreeMap, HashMap}; use gpui::{ - black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, BorrowWindow, - Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, Edges, Element, ElementId, - Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, ScrollWheelEvent, ShapedGlyph, - Size, StatefulInteraction, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext, + black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, + BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, + Edges, Element, ElementId, Entity, Hsla, KeyDownEvent, KeyListener, KeyMatch, Line, Pixels, + ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle, + TextSystem, ViewContext, WindowContext, }; use itertools::Itertools; use language::language_settings::ShowWhitespaceSetting; @@ -1605,7 +1606,7 @@ impl EditorElement { let style = self.style.clone(); let font_id = cx.text_system().font_id(&style.text.font()).unwrap(); let font_size = style.text.font_size.to_pixels(cx.rem_size()); - let line_height = (font_size * style.line_height_scalar).round(); + let line_height = style.text.line_height_in_pixels(cx.rem_size()); let em_width = cx .text_system() .typographic_bounds(font_id, font_size, 'm') @@ -2593,7 +2594,11 @@ impl Element for EditorElement { let rem_size = cx.rem_size(); let mut style = Style::default(); style.size.width = relative(1.).into(); - style.size.height = relative(1.).into(); + style.size.height = match editor.mode { + EditorMode::SingleLine => self.style.text.line_height_in_pixels(cx.rem_size()).into(), + EditorMode::AutoHeight { .. } => todo!(), + EditorMode::Full => relative(1.).into(), + }; cx.request_layout(&style, None) } diff --git a/crates/gpui2/src/style.rs b/crates/gpui2/src/style.rs index 551a87624cad716e1073f3bf16366d5a6c705027..5de173c2d4f729e90f9ba691bccb02bab664214a 100644 --- a/crates/gpui2/src/style.rs +++ b/crates/gpui2/src/style.rs @@ -189,6 +189,10 @@ impl TextStyle { } } + pub fn line_height_in_pixels(&self, rem_size: Pixels) -> Pixels { + self.line_height.to_pixels(self.font_size, rem_size) + } + pub fn to_run(&self, len: usize) -> TextRun { TextRun { len, From 91f356a2f163adbc4781e864751477ac0cb629f3 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Tue, 7 Nov 2023 13:36:01 -0500 Subject: [PATCH 2/6] Begin documenting theme colors --- crates/theme2/src/colors.rs | 96 +++++++++++++++++++++- crates/theme2/src/default_colors.rs | 8 +- crates/theme_importer/src/theme_printer.rs | 4 +- crates/ui2/src/components/tab.rs | 2 +- 4 files changed, 101 insertions(+), 9 deletions(-) diff --git a/crates/theme2/src/colors.rs b/crates/theme2/src/colors.rs index e1df841c24b8cce7c43296dbb569d82b9fb5277f..86373eb27a651669f02bfa133ea2120612a24969 100644 --- a/crates/theme2/src/colors.rs +++ b/crates/theme2/src/colors.rs @@ -69,25 +69,77 @@ pub struct GitStatusColors { #[refineable(debug, deserialize)] pub struct ThemeColors { pub border: Hsla, + /// Border color used for deemphasized borders, like a visual divider between two sections pub border_variant: Hsla, + /// Border color used for focused elements, like keyboard focused list item. pub border_focused: Hsla, + /// Border color used for selected elements, like an active search filter or selected checkbox. pub border_selected: Hsla, + /// Border color used for transparent borders. Used for placeholder borders when an element gains a border on state change. pub border_transparent: Hsla, + /// Border color used for disabled elements, like a disabled input or button. pub border_disabled: Hsla, + /// Used for elevated surfaces, like a context menu, popup, or dialog. pub elevated_surface_background: Hsla, + /// Used for grounded surfaces like a panel or tab. pub surface_background: Hsla, + /// Used the app background and blank panels or windows. pub background: Hsla, + /// Used for the background of an element that should have a different background than the surface it's on. + /// + /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons... + /// + /// For an element that should have the same background as the surface it's on, use `ghost_element_background`. pub element_background: Hsla, + /// Used for the hover state of an element that should have a different background than the surface it's on. + /// + /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. pub element_hover: Hsla, + /// Used for the active state of an element that should have a different background than the surface it's on. + /// + /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd. pub element_active: Hsla, + /// Used for the selected state of an element that should have a different background than the surface it's on. + /// + /// Selected states are triggered by the element being selected (or "activated") by the user. + /// + /// This could include a selected checkbox, a toggleable button that is toggled on, etc. pub element_selected: Hsla, + /// Used for the disabled state of an element that should have a different background than the surface it's on. + /// + /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. pub element_disabled: Hsla, - pub element_placeholder: Hsla, - pub element_drop_target: Hsla, + /// Used for the text color of an element that should have a different background than the surface it's on. + /// + /// Example: A input with some default placeholder text. + pub element_placeholder_text: Hsla, + /// Background color of the area that shows where a dragged element will be dropped. + pub drop_target_background: Hsla, + /// Border color of the area that shows where a dragged element will be dropped. + // pub drop_target_border: Hsla, + /// Used for the background of a ghost element that should have the same background as the surface it's on. + /// + /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons... + /// + /// For an element that should have a different background than the surface it's on, use `element_background`. pub ghost_element_background: Hsla, + /// Used for the hover state of a ghost element that should have the same background as the surface it's on. + /// + /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. pub ghost_element_hover: Hsla, + /// Used for the active state of a ghost element that should have the same background as the surface it's on. + /// + /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd. pub ghost_element_active: Hsla, + /// Used for the selected state of a ghost element that should have the same background as the surface it's on. + /// + /// Selected states are triggered by the element being selected (or "activated") by the user. + /// + /// This could include a selected checkbox, a toggleable button that is toggled on, etc. pub ghost_element_selected: Hsla, + /// Used for the disabled state of a ghost element that should have the same background as the surface it's on. + /// + /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. pub ghost_element_disabled: Hsla, pub text: Hsla, pub text_muted: Hsla, @@ -134,6 +186,46 @@ pub struct ThemeColors { pub terminal_ansi_magenta: Hsla, pub terminal_ansi_cyan: Hsla, pub terminal_ansi_white: Hsla, + // new colors + + // == elevation == + // elevatation_0_shadow + // elevatation_0_shadow_color + // elevatation_1_shadow + // elevatation_1_shadow_color + // elevatation_2_shadow + // elevatation_2_shadow_color + // elevatation_3_shadow + // elevatation_3_shadow_color + // elevatation_4_shadow + // elevatation_4_shadow_color + // elevatation_5_shadow + // elevatation_5_shadow_color + + // == rich text == + // headline + // paragraph + // link + // link_hover + // code_block_background + // code_block_border + + // == misc == + // inverted_element_* + // foreground: Overall foreground color. This color is only used if not overridden by a component. + // disabledForeground: Overall foreground for disabled elements. This color is only used if not overridden by a component. + // widget.border: Border color of widgets such as Find/Replace inside the editor. + // widget.shadow: Shadow color of widgets such as Find/Replace inside the editor. + // selection - foreground, background + // active_element_border + // inactive_element_border + // element_seperator + // scrollbar_thumb_background + // scrollbar_thumb_hover_background + // scrollbar_thumb_border + // scrollbar_track_background + // scrollbar_track_border + // scrollbar_status_opacity } #[derive(Refineable, Clone)] diff --git a/crates/theme2/src/default_colors.rs b/crates/theme2/src/default_colors.rs index f79518e7696894bc31f9149201446d4c64d53c08..93773ffab1e3c814c6922bd9deec0707fb6a3af0 100644 --- a/crates/theme2/src/default_colors.rs +++ b/crates/theme2/src/default_colors.rs @@ -216,8 +216,8 @@ impl ThemeColors { element_active: neutral().light().step_5(), element_selected: neutral().light().step_5(), element_disabled: neutral().light_alpha().step_3(), - element_placeholder: neutral().light().step_11(), - element_drop_target: blue().light_alpha().step_2(), + element_placeholder_text: neutral().light().step_11(), + drop_target_background: blue().light_alpha().step_2(), ghost_element_background: system.transparent, ghost_element_hover: neutral().light().step_4(), ghost_element_active: neutral().light().step_5(), @@ -289,8 +289,8 @@ impl ThemeColors { element_active: neutral().dark().step_5(), element_selected: neutral().dark().step_5(), element_disabled: neutral().dark_alpha().step_3(), - element_placeholder: neutral().dark().step_11(), - element_drop_target: blue().dark_alpha().step_2(), + element_placeholder_text: neutral().dark().step_11(), + drop_target_background: blue().dark_alpha().step_2(), ghost_element_background: system.transparent, ghost_element_hover: neutral().dark().step_4(), ghost_element_active: neutral().dark().step_5(), diff --git a/crates/theme_importer/src/theme_printer.rs b/crates/theme_importer/src/theme_printer.rs index aa74692164d016f6247a41a41dd354b256d70332..1857567604db27de95a6ff2267ca8b71857a7f97 100644 --- a/crates/theme_importer/src/theme_printer.rs +++ b/crates/theme_importer/src/theme_printer.rs @@ -140,8 +140,8 @@ impl<'a> Debug for ThemeColorsRefinementPrinter<'a> { ("element_active", self.0.element_active), ("element_selected", self.0.element_selected), ("element_disabled", self.0.element_disabled), - ("element_placeholder", self.0.element_placeholder), - ("element_drop_target", self.0.element_drop_target), + ("element_placeholder_text", self.0.element_placeholder_text), + ("drop_target_background", self.0.drop_target_background), ("ghost_element_background", self.0.ghost_element_background), ("ghost_element_hover", self.0.ghost_element_hover), ("ghost_element_active", self.0.ghost_element_active), diff --git a/crates/ui2/src/components/tab.rs b/crates/ui2/src/components/tab.rs index 416db2d17294d5c62e654f136b3f82c714f43b85..e936dc924a5fcba43e7d0905d5fac455d9ebd5c8 100644 --- a/crates/ui2/src/components/tab.rs +++ b/crates/ui2/src/components/tab.rs @@ -127,7 +127,7 @@ impl Tab { div() .id(self.id.clone()) .on_drag(move |_view, cx| cx.build_view(|cx| drag_state.clone())) - .drag_over::(|d| d.bg(cx.theme().colors().element_drop_target)) + .drag_over::(|d| d.bg(cx.theme().colors().drop_target_background)) .on_drop(|_view, state: View, cx| { eprintln!("{:?}", state.read(cx)); }) From df84ba422273c0cccda1118bb0cca9c01d325a3c Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Tue, 7 Nov 2023 14:04:09 -0500 Subject: [PATCH 3/6] Continue documenting theme colors --- crates/theme2/src/colors.rs | 172 +++++++++++++-------- crates/theme2/src/default_colors.rs | 2 - crates/theme_importer/src/theme_printer.rs | 1 - 3 files changed, 111 insertions(+), 64 deletions(-) diff --git a/crates/theme2/src/colors.rs b/crates/theme2/src/colors.rs index 72eba6b76d4065241c71ec8600fa9a3a7d6dd3dc..8ee4b5fd47830d062105c85959827cb37c2d7bc1 100644 --- a/crates/theme2/src/colors.rs +++ b/crates/theme2/src/colors.rs @@ -71,53 +71,49 @@ pub struct GitStatusColors { #[refineable(debug, deserialize)] pub struct ThemeColors { pub border: Hsla, - /// Border color used for deemphasized borders, like a visual divider between two sections + /// Border color. Used for deemphasized borders, like a visual divider between two sections pub border_variant: Hsla, - /// Border color used for focused elements, like keyboard focused list item. + /// Border color. Used for focused elements, like keyboard focused list item. pub border_focused: Hsla, - /// Border color used for selected elements, like an active search filter or selected checkbox. + /// Border color. Used for selected elements, like an active search filter or selected checkbox. pub border_selected: Hsla, - /// Border color used for transparent borders. Used for placeholder borders when an element gains a border on state change. + /// Border color. Used for transparent borders. Used for placeholder borders when an element gains a border on state change. pub border_transparent: Hsla, - /// Border color used for disabled elements, like a disabled input or button. + /// Border color. Used for disabled elements, like a disabled input or button. pub border_disabled: Hsla, - /// Used for elevated surfaces, like a context menu, popup, or dialog. + /// Border color. Used for elevated surfaces, like a context menu, popup, or dialog. pub elevated_surface_background: Hsla, - /// Used for grounded surfaces like a panel or tab. + /// Background Color. Used for grounded surfaces like a panel or tab. pub surface_background: Hsla, - /// Used the app background and blank panels or windows. + /// Background Color. Used for the app background and blank panels or windows. pub background: Hsla, - /// Used for the background of an element that should have a different background than the surface it's on. + /// Background Color. Used for the background of an element that should have a different background than the surface it's on. /// /// Elements might include: Buttons, Inputs, Checkboxes, Radio Buttons... /// /// For an element that should have the same background as the surface it's on, use `ghost_element_background`. pub element_background: Hsla, - /// Used for the hover state of an element that should have a different background than the surface it's on. + /// Background Color. Used for the hover state of an element that should have a different background than the surface it's on. /// /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. pub element_hover: Hsla, - /// Used for the active state of an element that should have a different background than the surface it's on. + /// Background Color. Used for the active state of an element that should have a different background than the surface it's on. /// /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd. pub element_active: Hsla, - /// Used for the selected state of an element that should have a different background than the surface it's on. + /// Background Color. Used for the selected state of an element that should have a different background than the surface it's on. /// /// Selected states are triggered by the element being selected (or "activated") by the user. /// /// This could include a selected checkbox, a toggleable button that is toggled on, etc. pub element_selected: Hsla, - /// Used for the disabled state of an element that should have a different background than the surface it's on. + /// Background Color. Used for the disabled state of an element that should have a different background than the surface it's on. /// /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. pub element_disabled: Hsla, - /// Used for the text color of an element that should have a different background than the surface it's on. - /// - /// Example: A input with some default placeholder text. - pub element_placeholder_text: Hsla, - /// Background color of the area that shows where a dragged element will be dropped. + /// Background Color. Used for the area that shows where a dragged element will be dropped. pub drop_target_background: Hsla, - /// Border color of the area that shows where a dragged element will be dropped. + /// Border Color. Used to show the area that shows where a dragged element will be dropped. // pub drop_target_border: Hsla, /// Used for the background of a ghost element that should have the same background as the surface it's on. /// @@ -125,109 +121,163 @@ pub struct ThemeColors { /// /// For an element that should have a different background than the surface it's on, use `element_background`. pub ghost_element_background: Hsla, - /// Used for the hover state of a ghost element that should have the same background as the surface it's on. + /// Background Color. Used for the hover state of a ghost element that should have the same background as the surface it's on. /// /// Hover states are triggered by the mouse entering an element, or a finger touching an element on a touch screen. pub ghost_element_hover: Hsla, - /// Used for the active state of a ghost element that should have the same background as the surface it's on. + /// Background Color. Used for the active state of a ghost element that should have the same background as the surface it's on. /// /// Active states are triggered by the mouse button being pressed down on an element, or the Return button or other activator being pressd. pub ghost_element_active: Hsla, - /// Used for the selected state of a ghost element that should have the same background as the surface it's on. + /// Background Color. Used for the selected state of a ghost element that should have the same background as the surface it's on. /// /// Selected states are triggered by the element being selected (or "activated") by the user. /// /// This could include a selected checkbox, a toggleable button that is toggled on, etc. pub ghost_element_selected: Hsla, - /// Used for the disabled state of a ghost element that should have the same background as the surface it's on. + /// Background Color. Used for the disabled state of a ghost element that should have the same background as the surface it's on. /// /// Disabled states are shown when a user cannot interact with an element, like a disabled button or input. pub ghost_element_disabled: Hsla, + /// Text Color. Default text color used for most text. pub text: Hsla, + /// Text Color. Color of muted or deemphasized text. It is a subdued version of the standard text color. pub text_muted: Hsla, + /// Text Color. Color of the placeholder text typically shown in input fields to guide the user to enter valid data. pub text_placeholder: Hsla, + /// Text Color. Color used for text denoting disabled elements. Typically, the color is faded or grayed out to emphasize the disabled state. pub text_disabled: Hsla, + /// Text Color. Color used for emphasis or highlighting certain text, like an active filter or a matched character in a search. pub text_accent: Hsla, + /// Fill Color. Used for the default fill color of an icon. pub icon: Hsla, + /// Fill Color. Used for the muted or deemphasized fill color of an icon. + /// + /// This might be used to show an icon in an inactive pane, or to demphasize a series of icons to give them less visual weight. pub icon_muted: Hsla, + /// Fill Color. Used for the disabled fill color of an icon. + /// + /// Disabled states are shown when a user cannot interact with an element, like a icon button. pub icon_disabled: Hsla, + /// Fill Color. Used for the placeholder fill color of an icon. + /// + /// This might be used to show an icon in an input that disappears when the user enters text. pub icon_placeholder: Hsla, + /// Fill Color. Used for the accent fill color of an icon. + /// + /// This might be used to show when a toggleable icon button is selected. pub icon_accent: Hsla, + + // === + // UI Elements + // === pub status_bar_background: Hsla, pub title_bar_background: Hsla, pub toolbar_background: Hsla, pub tab_bar_background: Hsla, pub tab_inactive_background: Hsla, pub tab_active_background: Hsla, + // pub panel_background: Hsla, + // pub pane_focused_border: Hsla, + // /// The color of the scrollbar thumb. + // pub scrollbar_thumb_background: Hsla, + // /// The color of the scrollbar thumb when hovered over. + // pub scrollbar_thumb_hover_background: Hsla, + // /// The border color of the scrollbar thumb. + // pub scrollbar_thumb_border: Hsla, + // /// The background color of the scrollbar track. + // pub scrollbar_track_background: Hsla, + // /// The border color of the scrollbar track. + // pub scrollbar_track_border: Hsla, + // /// The opacity of the scrollbar status marks, like diagnostic states and git status.. + // pub scrollbar_status_opacity: Hsla, + + // === + // Editor + // === pub editor_background: Hsla, + // pub editor_inactive_background: Hsla, pub editor_gutter_background: Hsla, pub editor_subheader_background: Hsla, pub editor_active_line_background: Hsla, pub editor_highlighted_line_background: Hsla, + /// Text Color. Used for the text of the line number in the editor gutter. pub editor_line_number: Hsla, + /// Text Color. Used for the text of the line number in the editor gutter when the line is highlighted. pub editor_active_line_number: Hsla, + /// Text Color. Used to mark invisible characters in the editor. + /// + /// Example: spaces, tabs, carriage returns, etc. pub editor_invisible: Hsla, pub editor_wrap_guide: Hsla, pub editor_active_wrap_guide: Hsla, pub editor_document_highlight_read_background: Hsla, pub editor_document_highlight_write_background: Hsla, + + // === + // Terminal + // === + /// Terminal Background Color pub terminal_background: Hsla, + /// Bright Black Color for ANSI Terminal pub terminal_ansi_bright_black: Hsla, + /// Bright Red Color for ANSI Terminal pub terminal_ansi_bright_red: Hsla, + /// Bright Green Color for ANSI Terminal pub terminal_ansi_bright_green: Hsla, + /// Bright Yellow Color for ANSI Terminal pub terminal_ansi_bright_yellow: Hsla, + /// Bright Blue Color for ANSI Terminal pub terminal_ansi_bright_blue: Hsla, + /// Bright Magenta Color for ANSI Terminal pub terminal_ansi_bright_magenta: Hsla, + /// Bright Cyan Color for ANSI Terminal pub terminal_ansi_bright_cyan: Hsla, + /// Bright White Color for ANSI Terminal pub terminal_ansi_bright_white: Hsla, + /// Black Color for ANSI Terminal pub terminal_ansi_black: Hsla, + /// Red Color for ANSI Terminal pub terminal_ansi_red: Hsla, + /// Green Color for ANSI Terminal pub terminal_ansi_green: Hsla, + /// Yellow Color for ANSI Terminal pub terminal_ansi_yellow: Hsla, + /// Blue Color for ANSI Terminal pub terminal_ansi_blue: Hsla, + /// Magenta Color for ANSI Terminal pub terminal_ansi_magenta: Hsla, + /// Cyan Color for ANSI Terminal pub terminal_ansi_cyan: Hsla, + /// White Color for ANSI Terminal pub terminal_ansi_white: Hsla, // new colors - // == elevation == - // elevatation_0_shadow - // elevatation_0_shadow_color - // elevatation_1_shadow - // elevatation_1_shadow_color - // elevatation_2_shadow - // elevatation_2_shadow_color - // elevatation_3_shadow - // elevatation_3_shadow_color - // elevatation_4_shadow - // elevatation_4_shadow_color - // elevatation_5_shadow - // elevatation_5_shadow_color - - // == rich text == - // headline - // paragraph - // link - // link_hover - // code_block_background - // code_block_border - - // == misc == - // inverted_element_* - // foreground: Overall foreground color. This color is only used if not overridden by a component. - // disabledForeground: Overall foreground for disabled elements. This color is only used if not overridden by a component. - // widget.border: Border color of widgets such as Find/Replace inside the editor. - // widget.shadow: Shadow color of widgets such as Find/Replace inside the editor. - // selection - foreground, background - // active_element_border - // inactive_element_border - // element_seperator - // scrollbar_thumb_background - // scrollbar_thumb_hover_background - // scrollbar_thumb_border - // scrollbar_track_background - // scrollbar_track_border - // scrollbar_status_opacity + // === + // Elevation + // === + // elevation_0_shadow + // elevation_0_shadow_color + // elevation_1_shadow + // elevation_1_shadow_color + // elevation_2_shadow + // elevation_2_shadow_color + // elevation_3_shadow + // elevation_3_shadow_color + // elevation_4_shadow + // elevation_4_shadow_color + // elevation_5_shadow + // elevation_5_shadow_color + + // === + // UI Text + // === + // pub headline: Hsla, + // pub paragraph: Hsla, + // pub link: Hsla, + // pub link_hover: Hsla, + // pub code_block_background: Hsla, + // pub code_block_border: Hsla, } #[derive(Refineable, Clone)] diff --git a/crates/theme2/src/default_colors.rs b/crates/theme2/src/default_colors.rs index 9804af234a5bd68fb56a960278f3d0506106a598..7252e829723d7dce36bceff4ecd882a46bff97e4 100644 --- a/crates/theme2/src/default_colors.rs +++ b/crates/theme2/src/default_colors.rs @@ -220,7 +220,6 @@ impl ThemeColors { element_active: neutral().light().step_5(), element_selected: neutral().light().step_5(), element_disabled: neutral().light_alpha().step_3(), - element_placeholder_text: neutral().light().step_11(), drop_target_background: blue().light_alpha().step_2(), ghost_element_background: system.transparent, ghost_element_hover: neutral().light().step_4(), @@ -293,7 +292,6 @@ impl ThemeColors { element_active: neutral().dark().step_5(), element_selected: neutral().dark().step_5(), element_disabled: neutral().dark_alpha().step_3(), - element_placeholder_text: neutral().dark().step_11(), drop_target_background: blue().dark_alpha().step_2(), ghost_element_background: system.transparent, ghost_element_hover: neutral().dark().step_4(), diff --git a/crates/theme_importer/src/theme_printer.rs b/crates/theme_importer/src/theme_printer.rs index 1857567604db27de95a6ff2267ca8b71857a7f97..0f20a8d60f93620fc990f815d3248b36452df641 100644 --- a/crates/theme_importer/src/theme_printer.rs +++ b/crates/theme_importer/src/theme_printer.rs @@ -140,7 +140,6 @@ impl<'a> Debug for ThemeColorsRefinementPrinter<'a> { ("element_active", self.0.element_active), ("element_selected", self.0.element_selected), ("element_disabled", self.0.element_disabled), - ("element_placeholder_text", self.0.element_placeholder_text), ("drop_target_background", self.0.drop_target_background), ("ghost_element_background", self.0.ghost_element_background), ("ghost_element_hover", self.0.ghost_element_hover), From b804b25c214547328f091a01e8b8c05b5f403433 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 12:00:05 -0700 Subject: [PATCH 4/6] Fix confusing error message --- crates/gpui2/src/element.rs | 5 ++++- crates/gpui2/src/interactive.rs | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/gpui2/src/element.rs b/crates/gpui2/src/element.rs index 2a0f557272f4899eb21f2bbb3123a08045a56158..8fdc17de07296d95def915f3a605f3988913eb2a 100644 --- a/crates/gpui2/src/element.rs +++ b/crates/gpui2/src/element.rs @@ -134,7 +134,10 @@ where .layout(state, frame_state.as_mut().unwrap(), cx); } } - _ => panic!("must call initialize before layout"), + ElementRenderPhase::Start => panic!("must call initialize before layout"), + ElementRenderPhase::LayoutRequested { .. } | ElementRenderPhase::Painted => { + panic!("element rendered twice") + } }; self.phase = ElementRenderPhase::LayoutRequested { diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 0725a10aca05ef01a39144982146d36167bc366c..84beb56ef8c68c44824e7d00a2a7b218ae689722 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -397,9 +397,10 @@ pub trait ElementInteraction: 'static { None }), )); - let result = stateful.stateless.initialize(cx, f); - stateful.key_listeners.pop(); - result + + cx.with_key_dispatch_context(stateful.dispatch_context.clone(), |cx| { + cx.with_key_listeners(mem::take(&mut stateful.key_listeners), f) + }) }) } else { let stateless = self.as_stateless_mut(); From 0233864e92cf263bcd868e1402395fbed18e8078 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 12:04:37 -0700 Subject: [PATCH 5/6] Fix loading keyfiles --- crates/settings2/src/keymap_file.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/settings2/src/keymap_file.rs b/crates/settings2/src/keymap_file.rs index e51bd76e5e0c9e0d86241a9c3bb816c90d0e1063..93635935cbd746b7e6fc3d96294e5895ee5c01e4 100644 --- a/crates/settings2/src/keymap_file.rs +++ b/crates/settings2/src/keymap_file.rs @@ -1,7 +1,7 @@ use crate::{settings_store::parse_json_with_comments, SettingsAssets}; use anyhow::{anyhow, Context, Result}; use collections::BTreeMap; -use gpui::{AppContext, KeyBinding, SharedString}; +use gpui::{actions, Action, AppContext, KeyBinding, SharedString}; use schemars::{ gen::{SchemaGenerator, SchemaSettings}, schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, @@ -137,8 +137,10 @@ impl KeymapFile { } } +actions!(NoAction); + fn no_action() -> Box { - todo!() + NoAction.boxed_clone() } #[cfg(test)] From 1e6a0f1c7bbcb25389def8232aaef3769246a8de Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 7 Nov 2023 12:07:04 -0700 Subject: [PATCH 6/6] Wire up GoToLine modal --- crates/go_to_line2/src/go_to_line.rs | 8 +++----- crates/workspace2/src/modal_layer.rs | 14 +++----------- crates/workspace2/src/workspace2.rs | 6 +++--- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/crates/go_to_line2/src/go_to_line.rs b/crates/go_to_line2/src/go_to_line.rs index 764602c98603595a350826325efe8a05bd3817f5..13d283ecff245abb11bafd75cabca94ac79e80dc 100644 --- a/crates/go_to_line2/src/go_to_line.rs +++ b/crates/go_to_line2/src/go_to_line.rs @@ -1,12 +1,10 @@ -use gpui::{div, px, red, AppContext, Div, Render, Styled, ViewContext, VisualContext}; -use serde::Deserialize; +use gpui::{actions, div, px, red, AppContext, Div, Render, Styled, ViewContext, VisualContext}; use workspace::ModalRegistry; -// actions!(go_to_line, [Toggle]); -#[derive(Clone, Default, PartialEq, Deserialize)] -struct Toggle; +actions!(Toggle); pub fn init(cx: &mut AppContext) { + cx.register_action_type::(); cx.global_mut::() .register_modal(Toggle, |_, cx| { // if let Some(editor) = workspace diff --git a/crates/workspace2/src/modal_layer.rs b/crates/workspace2/src/modal_layer.rs index e7cee53b2b368ab9cc1e9218b26d378913b7ac4e..01f940273a6cb7f92505b2438f1a7dad2dcc9b43 100644 --- a/crates/workspace2/src/modal_layer.rs +++ b/crates/workspace2/src/modal_layer.rs @@ -1,8 +1,8 @@ use std::{any::TypeId, sync::Arc}; use gpui::{ - div, AnyView, AppContext, Component, DispatchPhase, Div, ParentElement, Render, - StatelessInteractive, View, ViewContext, + div, AnyView, AppContext, DispatchPhase, Div, ParentElement, Render, StatelessInteractive, + View, ViewContext, }; use crate::Workspace; @@ -28,10 +28,6 @@ struct ToggleModal { name: String, } -// complete change of plan? -// on_action(ToggleModal{ name}) -// register_modal(name, |workspace, cx| { ... }) - impl ModalRegistry { pub fn register_modal(&mut self, action: A, build_view: B) where @@ -40,12 +36,10 @@ impl ModalRegistry { { let build_view = Arc::new(build_view); - dbg!("yonder"); self.registered_modals.push(( TypeId::of::(), Box::new(move |mut div| { let build_view = build_view.clone(); - dbg!("this point"); div.on_action( move |workspace: &mut Workspace, @@ -75,9 +69,7 @@ impl ModalLayer { Self { open_modal: None } } - pub fn render(&self, cx: &ViewContext) -> impl Component { - dbg!("rendering ModalLayer"); - + pub fn render(&self, workspace: &Workspace, cx: &ViewContext) -> Div { let mut div = div(); // div, c workspace.toggle_modal()div.on_action()) { diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rs index 6b8077cd38d88e5bb464535d5b138147422225ab..90204f60386e02cb08eb171d381b9e97b6fbea7f 100644 --- a/crates/workspace2/src/workspace2.rs +++ b/crates/workspace2/src/workspace2.rs @@ -3707,7 +3707,9 @@ impl Render for Workspace { .bg(cx.theme().colors().background) .child(self.render_titlebar(cx)) .child( - div() + self.modal_layer + .read(cx) + .render(self, cx) .flex_1() .w_full() .flex() @@ -3840,8 +3842,6 @@ impl Render for Workspace { // .on_click(Arc::new(|workspace, cx| workspace.toggle_debug(cx))), // ), ) - // .child(self.modal_layer.clone()) - .child(self.modal_layer.read(cx).render(cx)) } }