Skip to content

Commit

Permalink
Always provide the table id to the delegate (#15)
Browse files Browse the repository at this point in the history
☝🏻
  • Loading branch information
abey79 authored Sep 12, 2024
1 parent 08bba8f commit 1c5db2c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions egui_table/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub struct CellInfo {
pub col_nr: usize,

pub row_nr: u64,

/// The unique [`Id`] of this table.
pub table_id: Id,
// We could add more stuff here, like a reference to the column
}

Expand All @@ -147,8 +150,11 @@ pub struct HeaderCellInfo {

pub col_range: Range<usize>,

/// Hader row
/// Header row
pub row_nr: usize,

/// The unique [`Id`] of this table.
pub table_id: Id,
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
Expand All @@ -162,6 +168,9 @@ pub struct PrefetchInfo {

/// These rows are currently visible.
pub visible_rows: Range<u64>,

/// The unique [`Id`] of this table.
pub table_id: Id,
}

pub trait TableDelegate {
Expand Down Expand Up @@ -567,6 +576,7 @@ impl<'a> TableSplitScrollDelegate<'a> {
group_index,
col_range,
row_nr,
table_id: self.id,
},
);

Expand Down Expand Up @@ -637,6 +647,7 @@ impl<'a> TableSplitScrollDelegate<'a> {
num_sticky_columns: self.table.num_sticky_cols,
visible_columns: col_range.clone(),
visible_rows: row_range.clone(),
table_id: self.id,
});
self.has_prefetched = true;
} else {
Expand Down Expand Up @@ -673,8 +684,14 @@ impl<'a> TableSplitScrollDelegate<'a> {
let mut cell_ui = ui.new_child(ui_builder);
cell_ui.shrink_clip_rect(clip_rect);

self.table_delegate
.cell_ui(&mut cell_ui, &CellInfo { col_nr, row_nr });
self.table_delegate.cell_ui(
&mut cell_ui,
&CellInfo {
col_nr,
row_nr,
table_id: self.id,
},
);

let width = &mut self.max_column_widths[col_nr];
*width = width.max(cell_ui.min_size().x);
Expand Down

0 comments on commit 1c5db2c

Please sign in to comment.