Skip to content

Hide status bar when it is empty #36729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 40 additions & 5 deletions crates/workspace/src/status_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct StatusBar {
left_items: Vec<Box<dyn StatusItemViewHandle>>,
right_items: Vec<Box<dyn StatusItemViewHandle>>,
active_pane: Entity<Pane>,
has_active_left_children: bool,
has_active_right_children: bool,
_observe_active_pane: Subscription,
}

Expand All @@ -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() {
Expand All @@ -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<Self>) -> 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<Self>) -> 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();
}
}
})
}
}

Expand All @@ -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)
}),
Expand Down
Loading