TableDelegate methods return ViewContext<Table<Self>> (#101)

This commit is contained in:
Floyd Wang 2024-08-02 16:38:48 +08:00 committed by GitHub
parent 48efdecdef
commit e784f98a38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 6 deletions

View file

@ -161,7 +161,12 @@ impl TableDelegate for CustomerTableDelegate {
return self.col_resize && col_ix > 1;
}
fn render_td(&self, row_ix: usize, col_ix: usize, cx: &mut WindowContext) -> impl IntoElement {
fn render_td(
&self,
row_ix: usize,
col_ix: usize,
cx: &mut ViewContext<Table<Self>>,
) -> impl IntoElement {
let customer = self.customers.get(row_ix).unwrap();
let col = self.columns.get(col_ix).unwrap();
@ -224,7 +229,7 @@ impl TableDelegate for CustomerTableDelegate {
self.columns.get(col_ix).and_then(|c| c.sort)
}
fn perform_sort(&mut self, col_ix: usize, sort: ColSort, _: &mut WindowContext) {
fn perform_sort(&mut self, col_ix: usize, sort: ColSort, _: &mut ViewContext<Table<Self>>) {
if let Some(col) = self.columns.get_mut(col_ix) {
col.sort = Some(sort);
let asc = matches!(sort, ColSort::Ascending);

View file

@ -144,20 +144,25 @@ pub trait TableDelegate: Sized + 'static {
}
/// Perform sort on the column at the given index.
fn perform_sort(&mut self, col_ix: usize, sort: ColSort, cx: &mut WindowContext) {}
fn perform_sort(&mut self, col_ix: usize, sort: ColSort, cx: &mut ViewContext<Table<Self>>) {}
/// Render the header cell at the given column index, default to the column name.
fn render_th(&self, col_ix: usize, cx: &mut WindowContext) -> impl IntoElement {
fn render_th(&self, col_ix: usize, cx: &mut ViewContext<Table<Self>>) -> impl IntoElement {
div().size_full().child(self.col_name(col_ix))
}
/// Render the row at the given row and column.
fn render_tr(&self, row_ix: usize, cx: &mut WindowContext) -> Div {
fn render_tr(&self, row_ix: usize, cx: &mut ViewContext<Table<Self>>) -> Div {
h_flex()
}
/// Render cell at the given row and column.
fn render_td(&self, row_ix: usize, col_ix: usize, cx: &mut WindowContext) -> impl IntoElement;
fn render_td(
&self,
row_ix: usize,
col_ix: usize,
cx: &mut ViewContext<Table<Self>>,
) -> impl IntoElement;
/// Return true to enable loop selection on the table.
///