diff --git a/crates/diagnostics/src/items.rs b/crates/diagnostics/src/items.rs index afbef4427ffe0c7f5712a94e7c1bc01fbcbf5f54..b03b686c996ea85310bd446100255896870549f1 100644 --- a/crates/diagnostics/src/items.rs +++ b/crates/diagnostics/src/items.rs @@ -30,7 +30,7 @@ impl Render for DiagnosticIndicator { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let indicator = h_flex().gap_2(); if !ProjectSettings::get_global(cx).diagnostics.button { - return indicator; + return indicator.hidden(); } let diagnostic_indicator = match (self.summary.error_count, self.summary.warning_count) { diff --git a/crates/edit_prediction_button/src/edit_prediction_button.rs b/crates/edit_prediction_button/src/edit_prediction_button.rs index 6f050fc86c708e2c97f9b34f2fa786516ba0aca9..95ffa2f0e66713170d4fb5d63493daf07a7a555d 100644 --- a/crates/edit_prediction_button/src/edit_prediction_button.rs +++ b/crates/edit_prediction_button/src/edit_prediction_button.rs @@ -72,17 +72,17 @@ impl Render for EditPredictionButton { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { // Return empty div if AI is disabled if DisableAiSettings::get_global(cx).disable_ai { - return div(); + return div().hidden(); } let all_language_settings = all_language_settings(None, cx); match all_language_settings.edit_predictions.provider { - EditPredictionProvider::None => div(), + EditPredictionProvider::None => div().hidden(), EditPredictionProvider::Copilot => { let Some(copilot) = Copilot::global(cx) else { - return div(); + return div().hidden(); }; let status = copilot.read(cx).status(); diff --git a/crates/go_to_line/src/cursor_position.rs b/crates/go_to_line/src/cursor_position.rs index 0d17e746701759aef4a0521f1fb0afcb578eb02a..151f8be77fb3649d1feaf09cfe73323ae7dc56e3 100644 --- a/crates/go_to_line/src/cursor_position.rs +++ b/crates/go_to_line/src/cursor_position.rs @@ -1,5 +1,5 @@ use editor::{Editor, MultiBufferSnapshot}; -use gpui::{App, Entity, FocusHandle, Focusable, Subscription, Task, WeakEntity}; +use gpui::{App, Entity, FocusHandle, Focusable, Styled, Subscription, Task, WeakEntity}; use settings::Settings; use std::{fmt::Write, num::NonZeroU32, time::Duration}; use text::{Point, Selection}; @@ -208,7 +208,7 @@ impl CursorPosition { impl Render for CursorPosition { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { if !StatusBarSettings::get_global(cx).cursor_position_button { - return div(); + return div().hidden(); } div().when_some(self.position, |el, position| { diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 06fe5902bf6eca527f5f16d84e88c9c847e3e08a..4d4e176919784f7d7fba68f68cc00b8e7ff92922 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -17,12 +17,13 @@ use crate::{ AbsoluteLength, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, Bounds, ClickEvent, - DispatchPhase, Element, ElementId, Entity, FocusHandle, Global, GlobalElementId, Hitbox, - HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent, - KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, ModifiersChangedEvent, MouseButton, - MouseClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Overflow, ParentElement, Pixels, - Point, Render, ScrollWheelEvent, SharedString, Size, Style, StyleRefinement, Styled, Task, - TooltipId, Visibility, Window, WindowControlArea, point, px, size, + DispatchPhase, Display, Element, ElementId, Entity, FocusHandle, Global, GlobalElementId, + Hitbox, HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, + KeyDownEvent, KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, ModifiersChangedEvent, + MouseButton, MouseClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Overflow, + ParentElement, Pixels, Point, Render, ScrollWheelEvent, SharedString, Size, Style, + StyleRefinement, Styled, Task, TooltipId, Visibility, Window, WindowControlArea, point, px, + size, }; use collections::HashMap; use refineable::Refineable; @@ -1403,7 +1404,12 @@ impl Element for Div { content_size, window, cx, - |_style, scroll_offset, hitbox, window, cx| { + |style, scroll_offset, hitbox, window, cx| { + // skip children + if style.display == Display::None { + return hitbox; + } + window.with_element_offset(scroll_offset, |window| { for child in &mut self.children { child.prepaint(window, cx); @@ -1443,7 +1449,12 @@ impl Element for Div { hitbox.as_ref(), window, cx, - |_style, window, cx| { + |style, window, cx| { + // skip children + if style.display == Display::None { + return; + } + for child in &mut self.children { child.paint(window, cx); } diff --git a/crates/gpui/src/styled.rs b/crates/gpui/src/styled.rs index c714cac14fe894410a05d40c4c5b30d6fbf61e2d..4475718675b7feee4abcfcded814ae3cc38d5fdb 100644 --- a/crates/gpui/src/styled.rs +++ b/crates/gpui/src/styled.rs @@ -53,6 +53,13 @@ pub trait Styled: Sized { self } + /// Sets the display type of the element to `none`. + /// [Docs](https://tailwindcss.com/docs/display) + fn hidden(mut self) -> Self { + self.style().display = Some(Display::None); + self + } + /// Sets the whitespace of the element to `normal`. /// [Docs](https://tailwindcss.com/docs/whitespace#normal) fn whitespace_normal(mut self) -> Self { diff --git a/crates/image_viewer/src/image_info.rs b/crates/image_viewer/src/image_info.rs index 70a92736aa3d8715a3974ddc5709743e001d9fe8..6e8956abc67868457f071e04f3c2a1957ff6c19c 100644 --- a/crates/image_viewer/src/image_info.rs +++ b/crates/image_viewer/src/image_info.rs @@ -47,7 +47,7 @@ impl Render for ImageInfo { let settings = ImageViewerSettings::get_global(cx); let Some(metadata) = self.metadata.as_ref() else { - return div(); + return div().hidden(); }; let mut components = Vec::new(); diff --git a/crates/language_selector/src/active_buffer_language.rs b/crates/language_selector/src/active_buffer_language.rs index 38d010e33bc89012b0dc1a35d1638a6a443f9075..b86fa36657499a1c0bd1e8b3f600f387b6675ede 100644 --- a/crates/language_selector/src/active_buffer_language.rs +++ b/crates/language_selector/src/active_buffer_language.rs @@ -1,6 +1,7 @@ use editor::Editor; use gpui::{ - Context, Entity, IntoElement, ParentElement, Render, Subscription, WeakEntity, Window, div, + Context, Entity, IntoElement, ParentElement, Render, Styled, Subscription, WeakEntity, Window, + div, }; use language::LanguageName; use settings::Settings as _; @@ -41,7 +42,7 @@ impl ActiveBufferLanguage { impl Render for ActiveBufferLanguage { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { if !StatusBarSettings::get_global(cx).active_language_button { - return div(); + return div().hidden(); } div().when_some(self.active_language.as_ref(), |el, active_language| { diff --git a/crates/language_tools/src/lsp_button.rs b/crates/language_tools/src/lsp_button.rs index 614eaa4f05a0c4cac2572b9d014a04a8de5c4554..9b3ac04467569c9feabe7e3a0431bbfd2c0b7484 100644 --- a/crates/language_tools/src/lsp_button.rs +++ b/crates/language_tools/src/lsp_button.rs @@ -1011,7 +1011,7 @@ impl StatusItemView for LspButton { impl Render for LspButton { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl ui::IntoElement { if self.server_state.read(cx).language_servers.is_empty() || self.lsp_menu.is_none() { - return div(); + return div().hidden(); } let mut has_errors = false; diff --git a/crates/search/src/search_status_button.rs b/crates/search/src/search_status_button.rs index fcf36e86fa84a96117fa9b1f257d422d0bc50978..544a15155c0be789fe239f039e9d0b94b99dabdd 100644 --- a/crates/search/src/search_status_button.rs +++ b/crates/search/src/search_status_button.rs @@ -18,7 +18,7 @@ impl Render for SearchButton { let button = div(); if !EditorSettings::get_global(cx).search.button { - return button.w_0().invisible(); + return button.hidden(); } button.child( diff --git a/crates/toolchain_selector/src/active_toolchain.rs b/crates/toolchain_selector/src/active_toolchain.rs index 1c6cbe5235e22a15ffb5a6a7e1f6a3f3e15deb43..122aa9f22b74c33dd8f148f2bf3b65f04da478a9 100644 --- a/crates/toolchain_selector/src/active_toolchain.rs +++ b/crates/toolchain_selector/src/active_toolchain.rs @@ -2,12 +2,12 @@ use std::sync::Arc; use editor::Editor; use gpui::{ - AsyncWindowContext, Context, Entity, IntoElement, ParentElement, Render, Subscription, Task, - WeakEntity, Window, div, + AsyncWindowContext, Context, Entity, IntoElement, ParentElement, Render, Styled, Subscription, + Task, WeakEntity, Window, div, }; use language::{Buffer, BufferEvent, LanguageName, Toolchain, ToolchainScope}; use project::{Project, ProjectPath, Toolchains, WorktreeId, toolchain_store::ToolchainStoreEvent}; -use ui::{Button, ButtonCommon, Clickable, FluentBuilder, LabelSize, SharedString, Tooltip}; +use ui::{Button, ButtonCommon, Clickable, LabelSize, SharedString, Tooltip}; use util::{maybe, rel_path::RelPath}; use workspace::{StatusItemView, Workspace, item::ItemHandle}; @@ -230,21 +230,22 @@ impl ActiveToolchain { impl Render for ActiveToolchain { fn render(&mut self, _window: &mut Window, cx: &mut Context) -> impl IntoElement { - div().when_some(self.active_toolchain.as_ref(), |el, active_toolchain| { - let term = self.term.clone(); - el.child( - Button::new("change-toolchain", active_toolchain.name.clone()) - .label_size(LabelSize::Small) - .on_click(cx.listener(|this, _, window, cx| { - if let Some(workspace) = this.workspace.upgrade() { - workspace.update(cx, |workspace, cx| { - ToolchainSelector::toggle(workspace, window, cx) - }); - } - })) - .tooltip(Tooltip::text(format!("Select {}", &term))), - ) - }) + let Some(active_toolchain) = self.active_toolchain.as_ref() else { + return div().hidden(); + }; + + div().child( + Button::new("change-toolchain", active_toolchain.name.clone()) + .label_size(LabelSize::Small) + .on_click(cx.listener(|this, _, window, cx| { + if let Some(workspace) = this.workspace.upgrade() { + workspace.update(cx, |workspace, cx| { + ToolchainSelector::toggle(workspace, window, cx) + }); + } + })) + .tooltip(Tooltip::text(format!("Select {}", &self.term))), + ) } } diff --git a/crates/vim/src/mode_indicator.rs b/crates/vim/src/mode_indicator.rs index da2591934284cb29628d8e0c9d225fa1ff473c7d..ed182eb74d8e01cc9b8f543cbbc928f6864391e3 100644 --- a/crates/vim/src/mode_indicator.rs +++ b/crates/vim/src/mode_indicator.rs @@ -1,4 +1,4 @@ -use gpui::{Context, Element, Entity, Render, Subscription, WeakEntity, Window, div}; +use gpui::{Context, Entity, Render, Subscription, WeakEntity, Window, div}; use ui::text_for_keystrokes; use workspace::{StatusItemView, item::ItemHandle, ui::prelude::*}; @@ -89,7 +89,7 @@ impl Render for ModeIndicator { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let vim = self.vim(); let Some(vim) = vim else { - return div().into_any(); + return div().hidden().into_any_element(); }; let vim_readable = vim.read(cx);