diff --git a/crates/ui-egui/src/tabs.rs b/crates/ui-egui/src/tabs.rs index 6147b2e14..ea11615d0 100644 --- a/crates/ui-egui/src/tabs.rs +++ b/crates/ui-egui/src/tabs.rs @@ -100,6 +100,9 @@ fn tab_split_handle(app: &mut SheetApp, ui: &mut Ui, split: Rect, bar: (f32, f32 /// Draws the worksheet tab strip: navigation, scroll/reveal, rename/drag/move with optional copy, context menu, new-sheet button, split handle and grid scrollbar. pub fn sheet_tabs(app: &mut SheetApp, ui: &mut Ui) { let t = Tokens::get(ui.ctx()); + // Only the controls drawn this frame have a rectangle: a hidden one keeps no stale geometry. + app.grid.hscroll = None; + app.grid.tab_split = None; // File › Options › Advanced › Display options for this workbook (#3101): with neither the // sheet tabs nor the horizontal scroll bar, the bar isn't there at all. let view = app.session.active().map(|d| d.wb.view).unwrap_or_default(); diff --git a/crates/ui-egui/tests/it/tab_split.rs b/crates/ui-egui/tests/it/tab_split.rs index 7189358ac..c2dabc2fe 100644 --- a/crates/ui-egui/tests/it/tab_split.rs +++ b/crates/ui-egui/tests/it/tab_split.rs @@ -197,3 +197,24 @@ fn display_options_hide_the_sheet_tabs_and_the_horizontal_scroll_bar() { h.run_steps(5); assert!(!shows_tab_name(&h) && h.state().grid.hscroll.is_none() && h.state().grid.tab_split.is_none(), "no bar at all"); } + +#[test] +fn hiding_the_controls_clears_their_cached_rectangles() { + // Turned off on a live window, the controls drop the rectangles of the frame that drew them. + let mut h = harness(900.0, 1); + assert!(h.state().grid.tab_split.is_some() && h.state().grid.hscroll.is_some(), "both controls drawn first"); + + h.state_mut().run("view.showSheetTabs", json!({"on": false})).unwrap(); + h.run_steps(5); + assert!(h.state().grid.tab_split.is_none(), "no split handle once the tabs are hidden"); + assert!(h.state().grid.hscroll.is_some(), "the scroll bar stays"); + + h.state_mut().run("view.showSheetTabs", json!({"on": true})).unwrap(); + h.state_mut().run("view.showHorizontalScrollBar", json!({"on": false})).unwrap(); + h.run_steps(5); + assert!(h.state().grid.hscroll.is_none() && h.state().grid.tab_split.is_none(), "no scroll bar and no split handle"); + + h.state_mut().run("view.showSheetTabs", json!({"on": false})).unwrap(); + h.run_steps(5); + assert!(h.state().grid.hscroll.is_none() && h.state().grid.tab_split.is_none(), "no bar at all"); +}