Skip to content

Commit 038041c

Browse files
authored
Fix spacing around hidden status bar items (#39992)
This is a follow-up PR to #39609, and attempts to address hidden status bar items still contributing to the layout and creating extra spacing. ![before using display:none theres extra spaces, afterwords the buttons are always evenly spaced](https://github.com/user-attachments/assets/3bd07837-5f6f-4ca1-8985-9f3cb8b6893d) - 203cbd6 Adds a `.none()` method to the `gpui::Styled` helper trait, so that status items can set their display type to none inside their `render` method. - 249f06e Applies `.none()` to all the status items. - ~~499f564906c88336608c81615b11ebc9ab43d832~~ At first I was adding an `is_visible` method to the `StatusBarView` trait, which would be used to skip status bar items which would just render an empty div anyway, but I felt duplicating the conditions for hiding the buttons between the status items `is_visible` and `render` methods could be an attraction for bugs, so I tried to find another approach. This commit contains those changes, reverted immediately (if the `is_visible` approach is preferred I can bring it back!) - f37cb75 (bonus!) Adds a condition to the vim mode indicator to avoid a leading space when there are no pending keys. Release Notes: - N/A
1 parent 0cbab31 commit 038041c

11 files changed

Lines changed: 59 additions & 39 deletions

File tree

crates/diagnostics/src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl Render for DiagnosticIndicator {
3030
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
3131
let indicator = h_flex().gap_2();
3232
if !ProjectSettings::get_global(cx).diagnostics.button {
33-
return indicator;
33+
return indicator.hidden();
3434
}
3535

3636
let diagnostic_indicator = match (self.summary.error_count, self.summary.warning_count) {

crates/edit_prediction_button/src/edit_prediction_button.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ impl Render for EditPredictionButton {
7272
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
7373
// Return empty div if AI is disabled
7474
if DisableAiSettings::get_global(cx).disable_ai {
75-
return div();
75+
return div().hidden();
7676
}
7777

7878
let all_language_settings = all_language_settings(None, cx);
7979

8080
match all_language_settings.edit_predictions.provider {
81-
EditPredictionProvider::None => div(),
81+
EditPredictionProvider::None => div().hidden(),
8282

8383
EditPredictionProvider::Copilot => {
8484
let Some(copilot) = Copilot::global(cx) else {
85-
return div();
85+
return div().hidden();
8686
};
8787
let status = copilot.read(cx).status();
8888

crates/go_to_line/src/cursor_position.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use editor::{Editor, MultiBufferSnapshot};
2-
use gpui::{App, Entity, FocusHandle, Focusable, Subscription, Task, WeakEntity};
2+
use gpui::{App, Entity, FocusHandle, Focusable, Styled, Subscription, Task, WeakEntity};
33
use settings::Settings;
44
use std::{fmt::Write, num::NonZeroU32, time::Duration};
55
use text::{Point, Selection};
@@ -208,7 +208,7 @@ impl CursorPosition {
208208
impl Render for CursorPosition {
209209
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
210210
if !StatusBarSettings::get_global(cx).cursor_position_button {
211-
return div();
211+
return div().hidden();
212212
}
213213

214214
div().when_some(self.position, |el, position| {

crates/gpui/src/elements/div.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
1818
use crate::{
1919
AbsoluteLength, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, Bounds, ClickEvent,
20-
DispatchPhase, Element, ElementId, Entity, FocusHandle, Global, GlobalElementId, Hitbox,
21-
HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent,
22-
KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, ModifiersChangedEvent, MouseButton,
23-
MouseClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Overflow, ParentElement, Pixels,
24-
Point, Render, ScrollWheelEvent, SharedString, Size, Style, StyleRefinement, Styled, Task,
25-
TooltipId, Visibility, Window, WindowControlArea, point, px, size,
20+
DispatchPhase, Display, Element, ElementId, Entity, FocusHandle, Global, GlobalElementId,
21+
Hitbox, HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext,
22+
KeyDownEvent, KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, ModifiersChangedEvent,
23+
MouseButton, MouseClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Overflow,
24+
ParentElement, Pixels, Point, Render, ScrollWheelEvent, SharedString, Size, Style,
25+
StyleRefinement, Styled, Task, TooltipId, Visibility, Window, WindowControlArea, point, px,
26+
size,
2627
};
2728
use collections::HashMap;
2829
use refineable::Refineable;
@@ -1403,7 +1404,12 @@ impl Element for Div {
14031404
content_size,
14041405
window,
14051406
cx,
1406-
|_style, scroll_offset, hitbox, window, cx| {
1407+
|style, scroll_offset, hitbox, window, cx| {
1408+
// skip children
1409+
if style.display == Display::None {
1410+
return hitbox;
1411+
}
1412+
14071413
window.with_element_offset(scroll_offset, |window| {
14081414
for child in &mut self.children {
14091415
child.prepaint(window, cx);
@@ -1443,7 +1449,12 @@ impl Element for Div {
14431449
hitbox.as_ref(),
14441450
window,
14451451
cx,
1446-
|_style, window, cx| {
1452+
|style, window, cx| {
1453+
// skip children
1454+
if style.display == Display::None {
1455+
return;
1456+
}
1457+
14471458
for child in &mut self.children {
14481459
child.paint(window, cx);
14491460
}

crates/gpui/src/styled.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ pub trait Styled: Sized {
5353
self
5454
}
5555

56+
/// Sets the display type of the element to `none`.
57+
/// [Docs](https://tailwindcss.com/docs/display)
58+
fn hidden(mut self) -> Self {
59+
self.style().display = Some(Display::None);
60+
self
61+
}
62+
5663
/// Sets the whitespace of the element to `normal`.
5764
/// [Docs](https://tailwindcss.com/docs/whitespace#normal)
5865
fn whitespace_normal(mut self) -> Self {

crates/image_viewer/src/image_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Render for ImageInfo {
4747
let settings = ImageViewerSettings::get_global(cx);
4848

4949
let Some(metadata) = self.metadata.as_ref() else {
50-
return div();
50+
return div().hidden();
5151
};
5252

5353
let mut components = Vec::new();

crates/language_selector/src/active_buffer_language.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use editor::Editor;
22
use gpui::{
3-
Context, Entity, IntoElement, ParentElement, Render, Subscription, WeakEntity, Window, div,
3+
Context, Entity, IntoElement, ParentElement, Render, Styled, Subscription, WeakEntity, Window,
4+
div,
45
};
56
use language::LanguageName;
67
use settings::Settings as _;
@@ -41,7 +42,7 @@ impl ActiveBufferLanguage {
4142
impl Render for ActiveBufferLanguage {
4243
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
4344
if !StatusBarSettings::get_global(cx).active_language_button {
44-
return div();
45+
return div().hidden();
4546
}
4647

4748
div().when_some(self.active_language.as_ref(), |el, active_language| {

crates/language_tools/src/lsp_button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ impl StatusItemView for LspButton {
10111011
impl Render for LspButton {
10121012
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
10131013
if self.server_state.read(cx).language_servers.is_empty() || self.lsp_menu.is_none() {
1014-
return div();
1014+
return div().hidden();
10151015
}
10161016

10171017
let mut has_errors = false;

crates/search/src/search_status_button.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Render for SearchButton {
1818
let button = div();
1919

2020
if !EditorSettings::get_global(cx).search.button {
21-
return button.w_0().invisible();
21+
return button.hidden();
2222
}
2323

2424
button.child(

crates/toolchain_selector/src/active_toolchain.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use std::sync::Arc;
22

33
use editor::Editor;
44
use gpui::{
5-
AsyncWindowContext, Context, Entity, IntoElement, ParentElement, Render, Subscription, Task,
6-
WeakEntity, Window, div,
5+
AsyncWindowContext, Context, Entity, IntoElement, ParentElement, Render, Styled, Subscription,
6+
Task, WeakEntity, Window, div,
77
};
88
use language::{Buffer, BufferEvent, LanguageName, Toolchain, ToolchainScope};
99
use project::{Project, ProjectPath, Toolchains, WorktreeId, toolchain_store::ToolchainStoreEvent};
10-
use ui::{Button, ButtonCommon, Clickable, FluentBuilder, LabelSize, SharedString, Tooltip};
10+
use ui::{Button, ButtonCommon, Clickable, LabelSize, SharedString, Tooltip};
1111
use util::{maybe, rel_path::RelPath};
1212
use workspace::{StatusItemView, Workspace, item::ItemHandle};
1313

@@ -230,21 +230,22 @@ impl ActiveToolchain {
230230

231231
impl Render for ActiveToolchain {
232232
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
233-
div().when_some(self.active_toolchain.as_ref(), |el, active_toolchain| {
234-
let term = self.term.clone();
235-
el.child(
236-
Button::new("change-toolchain", active_toolchain.name.clone())
237-
.label_size(LabelSize::Small)
238-
.on_click(cx.listener(|this, _, window, cx| {
239-
if let Some(workspace) = this.workspace.upgrade() {
240-
workspace.update(cx, |workspace, cx| {
241-
ToolchainSelector::toggle(workspace, window, cx)
242-
});
243-
}
244-
}))
245-
.tooltip(Tooltip::text(format!("Select {}", &term))),
246-
)
247-
})
233+
let Some(active_toolchain) = self.active_toolchain.as_ref() else {
234+
return div().hidden();
235+
};
236+
237+
div().child(
238+
Button::new("change-toolchain", active_toolchain.name.clone())
239+
.label_size(LabelSize::Small)
240+
.on_click(cx.listener(|this, _, window, cx| {
241+
if let Some(workspace) = this.workspace.upgrade() {
242+
workspace.update(cx, |workspace, cx| {
243+
ToolchainSelector::toggle(workspace, window, cx)
244+
});
245+
}
246+
}))
247+
.tooltip(Tooltip::text(format!("Select {}", &self.term))),
248+
)
248249
}
249250
}
250251

0 commit comments

Comments
 (0)