BlueGit

ict rusty-teams

Merge remote-tracking branch 'origin/main' into fix/hover-bar-flip

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
06e9696a0a313ef8c614bca54bb672214f58899d
2 files changed +116 −14
crates/app/src/views/shell.rs +9 −5
@@ -893,11 +893,15 @@ impl Render for AppShell {
893 893 let title_bar = render_title_bar(
894 894 crate::active_appearance::current(cx).app_icon,
895 895 mode_label(state.mode),
896 update_button(
897 &self.update,
898 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
899 ),
900 own_status_button(&self.state, state),
896 [
897 update_button(
898 &self.update,
899 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
900 ),
901 own_status_button(&self.state, state),
902 ]
903 .into_iter()
904 .flatten(),
901 905 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
902 906 );
903 907 div()
@@ -893,11 +893,15 @@ impl Render for AppShell {
893 let title_bar = render_title_bar(
893 let title_bar = render_title_bar(
894 crate::active_appearance::current(cx).app_icon,
894 crate::active_appearance::current(cx).app_icon,
895 mode_label(state.mode),
895 mode_label(state.mode),
896 update_button(
896 [
897 &self.update,
897 update_button(
898 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
898 &self.update,
899 ),
899 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
900 own_status_button(&self.state, state),
900 ),
901 own_status_button(&self.state, state),
902 ]
903 .into_iter()
904 .flatten(),
901 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
905 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
902 );
906 );
903 div()
907 div()
crates/app/src/views/title_bar.rs +107 −9
@@ -129,27 +129,29 @@ struct Reserved {
129 129 struct TitleBarRow {
130 130 app_icon: AppIcon,
131 131 mode_label: Option<&'static str>,
132 update: Option<AnyElement>,
133 own: Option<AnyElement>,
132 controls: Vec<AnyElement>,
134 133 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
135 134 }
136 135
137 136 pub fn render_title_bar(
138 137 app_icon: AppIcon,
139 138 mode_label: Option<&'static str>,
140 update: Option<AnyElement>,
141 own: Option<AnyElement>,
139 controls: impl IntoIterator<Item = AnyElement>,
142 140 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
143 141 ) -> impl IntoElement {
144 142 TitleBarRow {
145 143 app_icon,
146 144 mode_label,
147 update,
148 own,
145 controls: controls.into_iter().collect(),
149 146 on_search: Box::new(on_search),
150 147 }
151 148 }
152 149
150 // The Windows caption hit-test takes every point the Drag area reaches, so a control without occlusion never gets its click.
151 fn outside_caption(control: AnyElement) -> Div {
152 div().flex_none().occlude().child(control)
153 }
154
153 155 fn search_box(
154 156 span: SearchSpan,
155 157 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
@@ -229,8 +231,7 @@ impl RenderOnce for TitleBarRow {
229 231 .h_full()
230 232 .gap(px(12.))
231 233 .items_center()
232 .children(self.update)
233 .children(self.own)
234 .children(self.controls.into_iter().map(outside_caption))
234 235 .child(div().w(px(4.)));
235 236 let row = h_flex()
236 237 .flex_1()
@@ -278,7 +279,104 @@ impl RenderOnce for TitleBarRow {
278 279
279 280 #[cfg(test)]
280 281 mod tests {
281 use super::{SEARCH_MIN_WIDTH, SEARCH_WIDTH, search_span};
282 use std::cell::{Cell, RefCell};
283 use std::rc::Rc;
284
285 use gpui_kit::component::button::{Button, ButtonVariants as _};
286 use gpui_kit::{
287 Context, Hitbox, HitboxBehavior, InteractiveElement as _, IntoElement, Modifiers,
288 ParentElement, Render, Styled, TestAppContext, Window, canvas, div, px, size,
289 };
290
291 use super::{
292 AppIcon, SEARCH_MIN_WIDTH, SEARCH_WIDTH, UpdateStatus, render_title_bar, search_span,
293 update_button,
294 };
295
296 struct CaptionHarness {
297 caption: Rc<RefCell<Option<Hitbox>>>,
298 restarts: Rc<Cell<usize>>,
299 }
300
301 impl Render for CaptionHarness {
302 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
303 let caption = self.caption.clone();
304 let restarts = self.restarts.clone();
305 let own = div()
306 .debug_selector(|| "shell/title-bar/own-status".into())
307 .child(Button::new("own").ghost().size(px(32.)).child("O"))
308 .into_any_element();
309 div()
310 .relative()
311 .size_full()
312 .child(
313 canvas(
314 |bounds, window, _| window.insert_hitbox(bounds, HitboxBehavior::Normal),
315 move |_, hitbox, _, _| *caption.borrow_mut() = Some(hitbox),
316 )
317 .absolute()
318 .size_full(),
319 )
320 .child(render_title_bar(
321 AppIcon::ALL[0],
322 Some("Demo"),
323 [
324 update_button(&UpdateStatus::Ready, move |_, _, _| {
325 restarts.set(restarts.get() + 1)
326 }),
327 Some(own),
328 ]
329 .into_iter()
330 .flatten(),
331 |_, _, _| {},
332 ))
333 }
334 }
335
336 #[gpui_kit::test]
337 fn title_bar_controls_stay_out_of_the_caption(cx: &mut TestAppContext) {
338 cx.update(gpui_kit::init);
339 cx.update(crate::theme::apply);
340 let caption = Rc::new(RefCell::new(None));
341 let restarts = Rc::new(Cell::new(0));
342 let (_, window_cx) = cx.add_window_view({
343 let caption = caption.clone();
344 let restarts = restarts.clone();
345 move |_, _| CaptionHarness { caption, restarts }
346 });
347 window_cx.simulate_resize(size(px(1280.), px(800.)));
348 for _ in 0..2 {
349 window_cx.update(|window, cx| window.draw(cx).clear(cx));
350 }
351 let mut found = Vec::new();
352 for (selector, caption_expected) in [
353 ("shell/title-bar/update", false),
354 ("shell/title-bar/own-status", false),
355 ("shell/title-bar/search", false),
356 ("shell/title-bar/leading", true),
357 ] {
358 let Some(bounds) = window_cx.debug_bounds(selector) else {
359 found.push(format!("{selector} was not rendered"));
360 continue;
361 };
362 let center = bounds.center();
363 let in_caption = window_cx.update(|window, _| {
364 caption
365 .borrow()
366 .as_ref()
367 .is_some_and(|hitbox| hitbox.is_hovered_at(center, window))
368 });
369 if in_caption != caption_expected {
370 found.push(format!("{selector} in caption: {in_caption}"));
371 }
372 }
373 assert!(found.is_empty(), "{}", found.join("\n"));
374 let update = window_cx
375 .debug_bounds("shell/title-bar/update")
376 .expect("update button rendered");
377 window_cx.simulate_click(update.center(), Modifiers::default());
378 assert_eq!(restarts.get(), 1);
379 }
282 380
283 381 #[test]
284 382 fn search_stays_centered_while_it_fits() {
@@ -129,27 +129,29 @@ struct Reserved {
129struct TitleBarRow {
129struct TitleBarRow {
130 app_icon: AppIcon,
130 app_icon: AppIcon,
131 mode_label: Option<&'static str>,
131 mode_label: Option<&'static str>,
132 update: Option<AnyElement>,
132 controls: Vec<AnyElement>,
133 own: Option<AnyElement>,
134 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
133 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
135}
134}
136
135
137pub fn render_title_bar(
136pub fn render_title_bar(
138 app_icon: AppIcon,
137 app_icon: AppIcon,
139 mode_label: Option<&'static str>,
138 mode_label: Option<&'static str>,
140 update: Option<AnyElement>,
139 controls: impl IntoIterator<Item = AnyElement>,
141 own: Option<AnyElement>,
142 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
140 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
143) -> impl IntoElement {
141) -> impl IntoElement {
144 TitleBarRow {
142 TitleBarRow {
145 app_icon,
143 app_icon,
146 mode_label,
144 mode_label,
147 update,
145 controls: controls.into_iter().collect(),
148 own,
149 on_search: Box::new(on_search),
146 on_search: Box::new(on_search),
150 }
147 }
151}
148}
152
149
150// The Windows caption hit-test takes every point the Drag area reaches, so a control without occlusion never gets its click.
151fn outside_caption(control: AnyElement) -> Div {
152 div().flex_none().occlude().child(control)
153}
154
153fn search_box(
155fn search_box(
154 span: SearchSpan,
156 span: SearchSpan,
155 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
157 on_search: Box<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
@@ -229,8 +231,7 @@ impl RenderOnce for TitleBarRow {
229 .h_full()
231 .h_full()
230 .gap(px(12.))
232 .gap(px(12.))
231 .items_center()
233 .items_center()
232 .children(self.update)
234 .children(self.controls.into_iter().map(outside_caption))
233 .children(self.own)
234 .child(div().w(px(4.)));
235 .child(div().w(px(4.)));
235 let row = h_flex()
236 let row = h_flex()
236 .flex_1()
237 .flex_1()
@@ -278,7 +279,104 @@ impl RenderOnce for TitleBarRow {
278
279
279#[cfg(test)]
280#[cfg(test)]
280mod tests {
281mod tests {
281 use super::{SEARCH_MIN_WIDTH, SEARCH_WIDTH, search_span};
282 use std::cell::{Cell, RefCell};
283 use std::rc::Rc;
284
285 use gpui_kit::component::button::{Button, ButtonVariants as _};
286 use gpui_kit::{
287 Context, Hitbox, HitboxBehavior, InteractiveElement as _, IntoElement, Modifiers,
288 ParentElement, Render, Styled, TestAppContext, Window, canvas, div, px, size,
289 };
290
291 use super::{
292 AppIcon, SEARCH_MIN_WIDTH, SEARCH_WIDTH, UpdateStatus, render_title_bar, search_span,
293 update_button,
294 };
295
296 struct CaptionHarness {
297 caption: Rc<RefCell<Option<Hitbox>>>,
298 restarts: Rc<Cell<usize>>,
299 }
300
301 impl Render for CaptionHarness {
302 fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
303 let caption = self.caption.clone();
304 let restarts = self.restarts.clone();
305 let own = div()
306 .debug_selector(|| "shell/title-bar/own-status".into())
307 .child(Button::new("own").ghost().size(px(32.)).child("O"))
308 .into_any_element();
309 div()
310 .relative()
311 .size_full()
312 .child(
313 canvas(
314 |bounds, window, _| window.insert_hitbox(bounds, HitboxBehavior::Normal),
315 move |_, hitbox, _, _| *caption.borrow_mut() = Some(hitbox),
316 )
317 .absolute()
318 .size_full(),
319 )
320 .child(render_title_bar(
321 AppIcon::ALL[0],
322 Some("Demo"),
323 [
324 update_button(&UpdateStatus::Ready, move |_, _, _| {
325 restarts.set(restarts.get() + 1)
326 }),
327 Some(own),
328 ]
329 .into_iter()
330 .flatten(),
331 |_, _, _| {},
332 ))
333 }
334 }
335
336 #[gpui_kit::test]
337 fn title_bar_controls_stay_out_of_the_caption(cx: &mut TestAppContext) {
338 cx.update(gpui_kit::init);
339 cx.update(crate::theme::apply);
340 let caption = Rc::new(RefCell::new(None));
341 let restarts = Rc::new(Cell::new(0));
342 let (_, window_cx) = cx.add_window_view({
343 let caption = caption.clone();
344 let restarts = restarts.clone();
345 move |_, _| CaptionHarness { caption, restarts }
346 });
347 window_cx.simulate_resize(size(px(1280.), px(800.)));
348 for _ in 0..2 {
349 window_cx.update(|window, cx| window.draw(cx).clear(cx));
350 }
351 let mut found = Vec::new();
352 for (selector, caption_expected) in [
353 ("shell/title-bar/update", false),
354 ("shell/title-bar/own-status", false),
355 ("shell/title-bar/search", false),
356 ("shell/title-bar/leading", true),
357 ] {
358 let Some(bounds) = window_cx.debug_bounds(selector) else {
359 found.push(format!("{selector} was not rendered"));
360 continue;
361 };
362 let center = bounds.center();
363 let in_caption = window_cx.update(|window, _| {
364 caption
365 .borrow()
366 .as_ref()
367 .is_some_and(|hitbox| hitbox.is_hovered_at(center, window))
368 });
369 if in_caption != caption_expected {
370 found.push(format!("{selector} in caption: {in_caption}"));
371 }
372 }
373 assert!(found.is_empty(), "{}", found.join("\n"));
374 let update = window_cx
375 .debug_bounds("shell/title-bar/update")
376 .expect("update button rendered");
377 window_cx.simulate_click(update.center(), Modifiers::default());
378 assert_eq!(restarts.get(), 1);
379 }
282
380
283 #[test]
381 #[test]
284 fn search_stays_centered_while_it_fits() {
382 fn search_stays_centered_while_it_fits() {