Fix spacing around hidden status bar items (#39992)

This is a follow-up PR to
https://github.com/zed-industries/zed/pull/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)

- 203cbd634bfb1489b8afa4952d9594615a956b77 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.

- 249f06e3de63b0ab32814f20e7105d8e2b642f02 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!)

- f37cb75f0519ceea1f3e1cc4f97087a5cb34b0fd (bonus!) Adds a condition to
the vim mode indicator to avoid a leading space when there are no
pending keys.

Release Notes:

- N/A
This commit is contained in:
kitt
2025-10-17 02:26:39 -03:00
committed by GitHub
parent 0cbab311a1
commit 038041cc87
11 changed files with 59 additions and 39 deletions
+19 -8
View File
@@ -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);
}
+7
View File
@@ -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 {