From d4ee273bf58bd6cfb452b5167050dadcb80ee32c Mon Sep 17 00:00:00 2001 From: Ylin Date: Thu, 7 Nov 2024 17:53:21 +0800 Subject: [PATCH] table: Add render_last_empty_col to table delegate (#399) Co-authored-by: linxin --- crates/ui/src/table.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/ui/src/table.rs b/crates/ui/src/table.rs index 15bad261..5097652b 100644 --- a/crates/ui/src/table.rs +++ b/crates/ui/src/table.rs @@ -256,6 +256,11 @@ pub trait TableDelegate: Sized + 'static { /// This is always called when the table is near the bottom, /// so you must check if there is more data to load or lock the loading state. fn load_more(&mut self, cx: &mut ViewContext>) {} + + /// Render the last empty column, default to empty. + fn render_last_empty_col(&mut self, cx: &mut ViewContext>) -> Div { + h_flex().w(px(100.)).h_full().flex_shrink_0() + } } impl Table @@ -920,7 +925,7 @@ where table.render_th(left_cols_count + col_ix, cx) }), ) - .child(Self::render_last_empty_col(cx)) + .child(table.delegate.render_last_empty_col(cx)) .child( canvas( move |bounds, cx| { @@ -1010,7 +1015,7 @@ where .child(self.delegate.render_td(row_ix, col_ix, cx)), ) })) - .child(Self::render_last_empty_col(cx)), + .child(self.delegate.render_last_empty_col(cx)), ) // Row selected style .when_some(self.selected_row, |this, _| { @@ -1070,13 +1075,9 @@ where .left(horizontal_scroll_handle.offset().x) .child(self.render_cell(col_ix, cx)) })) - .child(Self::render_last_empty_col(cx)) + .child(self.delegate.render_last_empty_col(cx)) } } - - fn render_last_empty_col(_: &mut WindowContext) -> Div { - h_flex().w(px(100.)).h_full().flex_shrink_0() - } } impl Sizable for Table