diff --git a/crates/workspace/src/status_bar.rs b/crates/workspace/src/status_bar.rs index 187e720d9c..bd6d549fe4 100644 --- a/crates/workspace/src/status_bar.rs +++ b/crates/workspace/src/status_bar.rs @@ -32,6 +32,8 @@ pub struct StatusBar { left_items: Vec>, right_items: Vec>, active_pane: Entity, + has_active_left_children: bool, + has_active_right_children: bool, _observe_active_pane: Subscription, } @@ -41,7 +43,10 @@ impl Render for StatusBar { .w_full() .justify_between() .gap(DynamicSpacing::Base08.rems(cx)) - .py(DynamicSpacing::Base04.rems(cx)) + .when( + self.has_active_left_children || self.has_active_right_children, + |this| this.py(DynamicSpacing::Base04.rems(cx)), + ) .px(DynamicSpacing::Base06.rems(cx)) .bg(cx.theme().colors().status_bar_background) .map(|el| match window.window_decorations() { @@ -58,24 +63,52 @@ impl Render for StatusBar { .border_b(px(1.0)) .border_color(cx.theme().colors().status_bar_background), }) - .child(self.render_left_tools()) - .child(self.render_right_tools()) + .child(self.render_left_tools(cx)) + .child(self.render_right_tools(cx)) } } impl StatusBar { - fn render_left_tools(&self) -> impl IntoElement { + fn render_left_tools(&self, parent_cx: &mut Context) -> impl IntoElement { h_flex() .gap_1() .overflow_x_hidden() .children(self.left_items.iter().map(|item| item.to_any())) + .on_children_prepainted({ + let entity = parent_cx.entity().downgrade(); + let old_y_pad = self.has_active_left_children; + move |bounds, _window, cx| { + let new_y_pad = bounds.iter().any(|&b| b.size.height > px(0.0)); + if new_y_pad != old_y_pad { + entity + .update(cx, |this, _| { + this.has_active_left_children = new_y_pad; + }) + .ok(); + } + } + }) } - fn render_right_tools(&self) -> impl IntoElement { + fn render_right_tools(&self, parent_cx: &mut Context) -> impl IntoElement { h_flex() .gap_1() .overflow_x_hidden() .children(self.right_items.iter().rev().map(|item| item.to_any())) + .on_children_prepainted({ + let entity = parent_cx.entity().downgrade(); + let old_y_pad = self.has_active_right_children; + move |bounds, _window, cx| { + let new_y_pad = bounds.iter().any(|&b| b.size.height > px(0.0)); + if new_y_pad != old_y_pad { + entity + .update(cx, |this, _| { + this.has_active_right_children = new_y_pad; + }) + .ok(); + } + } + }) } } @@ -85,6 +118,8 @@ impl StatusBar { left_items: Default::default(), right_items: Default::default(), active_pane: active_pane.clone(), + has_active_left_children: true, + has_active_right_children: true, _observe_active_pane: cx.observe_in(active_pane, window, |this, _, window, cx| { this.update_active_pane_item(window, cx) }),