From 007288487e90b5e79faa445828dfc8a642e72e7e Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 7 Oct 2024 21:47:26 +0800 Subject: [PATCH] table: Fix horzizontal scrollbar size when there have fixed cols. (#317) --- crates/ui/src/table.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/crates/ui/src/table.rs b/crates/ui/src/table.rs index e14a3f5f..09adc1f0 100644 --- a/crates/ui/src/table.rs +++ b/crates/ui/src/table.rs @@ -104,7 +104,9 @@ pub struct Table { delegate: D, /// The bounds of the table container. bounds: Bounds, - /// The bounds of the table content. + /// The bounds of the fixed head cols. + fixed_head_cols_bounds: Bounds, + /// The bounds of the table head content. head_content_bounds: Bounds, col_groups: Vec, @@ -258,6 +260,7 @@ where selected_col: None, resizing_col: None, bounds: Bounds::default(), + fixed_head_cols_bounds: Bounds::default(), head_content_bounds: Bounds::default(), stripe: false, border: true, @@ -539,6 +542,22 @@ where } } + /// Returns the size of the content area. + fn head_content_bounds(&self) -> gpui::Bounds { + let has_fixed_cols = self.fixed_head_cols_bounds.size.width > px(0.0); + Bounds { + origin: if has_fixed_cols { + self.fixed_head_cols_bounds.origin + } else { + self.head_content_bounds.origin + }, + size: gpui::size( + self.fixed_head_cols_bounds.size.width + self.head_content_bounds.size.width, + self.head_content_bounds.size.height, + ), + } + } + fn render_cell(&self, col_ix: usize, _cx: &mut ViewContext) -> Div { let col_width = self.col_groups[col_ix].width; @@ -599,7 +618,7 @@ where cx.view().entity_id(), state, self.horizontal_scroll_handle.clone(), - self.head_content_bounds.size, + self.head_content_bounds().size, )) } @@ -814,6 +833,7 @@ where .border_color(cx.theme().border) .text_color(cx.theme().table_head_foreground) .when(fixed_cols_count > 0, |this| { + let view = view.clone(); // Render left fixed columns this.child( h_flex() @@ -828,6 +848,16 @@ where .filter(|col| col.fixed == Some(ColFixed::Left)) .enumerate() .map(|(col_ix, _)| self.render_th(col_ix, cx)), + ) + .child( + canvas( + move |bounds, cx| { + view.update(cx, |r, _| r.fixed_head_cols_bounds = bounds) + }, + |_, _, _| {}, + ) + .absolute() + .size_full(), ), ) })