gpui_table_runtime/
load.rs1use gpui_kit::component::table::{TableDelegate, TableState};
2use gpui_kit::{App, Context, Window};
3
4pub trait LoadMoreDelegate: TableDelegate {
9 fn has_more(&self, app: &App) -> bool;
11
12 fn load_more_threshold(&self) -> usize {
14 10
15 }
16
17 fn load_more(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
19}
20
21pub trait TableDataLoader: TableDelegate {
23 fn load_data(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
25}
26
27pub trait TableLoader: TableDelegate {
29 const THRESHOLD: usize = 10;
31
32 fn load_more(&mut self, window: &mut Window, cx: &mut Context<TableState<Self>>);
34}
35
36#[cfg(test)]
37mod tests {
38 use super::{LoadMoreDelegate, TableLoader};
39 use gpui_kit::component::table::{Column, TableDelegate, TableState};
40 use gpui_kit::{App, Context, IntoElement, Window, div};
41
42 struct Delegate;
43
44 impl TableDelegate for Delegate {
45 fn columns_count(&self, _cx: &App) -> usize {
46 0
47 }
48
49 fn rows_count(&self, _cx: &App) -> usize {
50 0
51 }
52
53 fn column(&self, _col_ix: usize, _cx: &App) -> Column {
54 unreachable!("the threshold contract does not inspect columns")
55 }
56
57 fn render_td(
58 &mut self,
59 _row_ix: usize,
60 _col_ix: usize,
61 _window: &mut Window,
62 _cx: &mut Context<TableState<Self>>,
63 ) -> impl IntoElement {
64 div()
65 }
66 }
67
68 impl LoadMoreDelegate for Delegate {
69 fn has_more(&self, _app: &App) -> bool {
70 true
71 }
72
73 fn load_more(&mut self, _window: &mut Window, _cx: &mut Context<TableState<Self>>) {}
74 }
75
76 impl TableLoader for Delegate {
77 fn load_more(&mut self, _window: &mut Window, _cx: &mut Context<TableState<Self>>) {}
78 }
79
80 #[test]
81 fn loading_traits_share_the_documented_default_threshold() {
82 assert_eq!(
83 <Delegate as LoadMoreDelegate>::load_more_threshold(&Delegate),
84 10
85 );
86 assert_eq!(<Delegate as TableLoader>::THRESHOLD, 10);
87 }
88}