use std::ops::Range;
use crate::{
App, Context, Div, InteractiveElement as _, IntoElement, ParentElement as _, Pixels,
SharedString, Stateful, Styled as _, Window, div,
};
use crate::{
ActiveTheme as _, ElementSize, Icon, IconName, h_flex,
menu::PopupMenu,
table::{Column, ColumnGroup, ColumnSort, TableState, loading::Loading},
};
pub trait TableDelegate: Sized + 'static {
fn columns_count(&self, cx: &App) -> usize;
fn rows_count(&self, cx: &App) -> usize;
fn column(&self, col_ix: usize, cx: &App) -> Column;
fn perform_sort(
&mut self,
_col_ix: usize,
_sort: ColumnSort,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) {
}
fn render_header(
&mut self,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> Stateful<Div> {
div().id("header")
}
fn group_headers(&self, _cx: &App) -> Option<Vec<Vec<ColumnGroup>>> {
None
}
fn render_group_th(
&mut self,
label: &SharedString,
_col_span: usize,
width: Pixels,
_window: &mut Window,
cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
div()
.w(width)
.h_full()
.flex_shrink_0()
.flex()
.items_center()
.justify_center()
.border_r_1()
.border_color(cx.theme().border)
.child(label.clone())
}
fn render_th(
&mut self,
col_ix: usize,
_window: &mut Window,
cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
div().size_full().child(self.column(col_ix, cx).name)
}
fn render_tr(
&mut self,
row_ix: usize,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> Stateful<Div> {
div().id(("row", row_ix))
}
fn context_menu(
&mut self,
_row_ix: usize,
menu: PopupMenu,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> PopupMenu {
menu
}
fn render_td(
&mut self,
row_ix: usize,
col_ix: usize,
window: &mut Window,
cx: &mut Context<TableState<Self>>,
) -> impl IntoElement;
fn move_column(
&mut self,
_col_ix: usize,
_to_ix: usize,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) {
}
fn render_empty(
&mut self,
_window: &mut Window,
cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
h_flex()
.size_full()
.justify_center()
.text_color(cx.theme().muted_foreground.opacity(0.6))
.child(Icon::new(IconName::Inbox).size_12())
.into_any_element()
}
fn loading(&self, _cx: &App) -> bool {
false
}
fn render_loading(
&mut self,
size: ElementSize,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
Loading::new().size(size)
}
fn has_more(&self, _cx: &App) -> bool {
false
}
fn load_more_threshold(&self) -> usize {
20
}
fn load_more(&mut self, _window: &mut Window, _cx: &mut Context<TableState<Self>>) {}
fn render_last_empty_col(
&mut self,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) -> impl IntoElement {
h_flex().w_3().h_full().flex_shrink_0()
}
fn visible_rows_changed(
&mut self,
_visible_range: Range<usize>,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) {
}
fn visible_columns_changed(
&mut self,
_visible_range: Range<usize>,
_window: &mut Window,
_cx: &mut Context<TableState<Self>>,
) {
}
fn cell_text(&self, _row_ix: usize, _col_ix: usize, _cx: &App) -> String {
String::new()
}
}