use oxiui::table::{Cell, ColumnDef, RowSource, Table};
use oxiui::{theme, UiError};
struct DemoData {
columns: Vec<ColumnDef>,
}
impl DemoData {
fn new() -> Self {
Self {
columns: vec![
ColumnDef {
name: "ID".into(),
width: 60.0,
..ColumnDef::default()
},
ColumnDef {
name: "Name".into(),
width: 120.0,
..ColumnDef::default()
},
ColumnDef {
name: "Value".into(),
width: 80.0,
..ColumnDef::default()
},
],
}
}
}
impl RowSource for DemoData {
fn row_count(&self) -> usize {
1_000
}
fn row(&self, i: usize) -> Vec<Cell> {
vec![
Cell::Int(i as i64),
Cell::Text(format!("Item {i}")),
Cell::Float(i as f64 * 1.5),
]
}
fn column_defs(&self) -> &[ColumnDef] {
&self.columns
}
}
fn main() -> Result<(), UiError> {
let table = Table::new(DemoData::new());
let row_count = table.row_count();
oxiui::App::new(oxiui::AppConfig::new().title("OxiUI Table Demo"))
.theme(theme::cooljapan_default())
.content(move |ui| {
ui.heading("OxiUI Virtualized Table");
ui.label(&format!(
"Table has {row_count} rows — only a small viewport window is materialized per frame."
));
let sample = table.materialize_visible(240.0, 0.0);
ui.label(&format!(
"First {} rows materialized for a 240 px viewport at scroll=0:",
sample.len()
));
for row in &sample {
let line: Vec<String> = row.iter().map(|c| c.to_string()).collect();
ui.label(&line.join(" | "));
}
})
.run()?;
Ok(())
}