From 0aaf14e03c799b2ac2fa6a4e15a46ab5bf578ae4 Mon Sep 17 00:00:00 2001 From: zumbalogy <3770982+zumbalogy@users.noreply.github.com> Date: Thu, 21 Aug 2025 10:39:19 -0400 Subject: [PATCH 1/2] on prepainted working --- crates/workspace/src/status_bar.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/workspace/src/status_bar.rs b/crates/workspace/src/status_bar.rs index edeb382de7..66617c4520 100644 --- a/crates/workspace/src/status_bar.rs +++ b/crates/workspace/src/status_bar.rs @@ -35,13 +35,16 @@ pub struct StatusBar { _observe_active_pane: Subscription, } +use log::{info, warn}; + + impl Render for StatusBar { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { h_flex() .w_full() .justify_between() .gap(DynamicSpacing::Base08.rems(cx)) - .py(DynamicSpacing::Base04.rems(cx)) + // .py(DynamicSpacing::Base04.rems(cx)) .px(DynamicSpacing::Base06.rems(cx)) .bg(cx.theme().colors().status_bar_background) .map(|el| match window.window_decorations() { @@ -60,6 +63,12 @@ impl Render for StatusBar { }) .child(self.render_left_tools()) .child(self.render_right_tools()) + .on_children_prepainted(|bounds, _, _| { + if bounds.iter().any(|&b| b.size.height > px(0.0)) { + warn!("bar, this is hit."); + } + warn!("foo: {bounds:?}"); + }) } } From 74143ce147c520e065c27904c275fc725a87da86 Mon Sep 17 00:00:00 2001 From: zumbalogy <3770982+zumbalogy@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:02:53 -0400 Subject: [PATCH 2/2] dynamic padding working via on_children_prepainted callback on left and right children --- crates/workspace/src/status_bar.rs | 54 ++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/crates/workspace/src/status_bar.rs b/crates/workspace/src/status_bar.rs index 66617c4520..d2ca1ed0f8 100644 --- a/crates/workspace/src/status_bar.rs +++ b/crates/workspace/src/status_bar.rs @@ -32,19 +32,21 @@ 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, } -use log::{info, warn}; - - impl Render for StatusBar { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { h_flex() .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() { @@ -61,30 +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()) - .on_children_prepainted(|bounds, _, _| { - if bounds.iter().any(|&b| b.size.height > px(0.0)) { - warn!("bar, this is hit."); - } - warn!("foo: {bounds:?}"); - }) + .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(); + } + } + }) } } @@ -94,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) }),