Crates.io | egui-selectable-table |
lib.rs | egui-selectable-table |
version | 0.1.0 |
source | src |
created_at | 2024-10-16 16:01:34.323116 |
updated_at | 2024-10-16 16:01:34.323116 |
description | A library for egui to create tables with draggable cell and row selection. |
homepage | https://github.com/TheRustyPickle/egui-selectable-table |
repository | https://github.com/TheRustyPickle/egui-selectable-table |
max_upload_size | |
id | 1411966 |
size | 65,602 |
A library for egui to create tables with draggable cell and row selection.
// See Demo folder for a complete example
use egui_selectable_table::{
ColumnOperations, ColumnOrdering, SelectableRow, SelectableTable, SortOrder,
};
// other use imports
struct Config {
// anything you want to pass
}
struct MyRow {
field_1: String,
// .. more fields
}
enum Column {
Field1,
// .. more column names
}
// Implement both traits for row and column
impl ColumnOperations<MyRow, ColumnName, Config> for Column {
// The text of a row based on the column
fn column_text(&self, row: &WhiteListRowData) -> String {}
// Create your own header or no header
fn create_header(&self, ui: &mut Ui, sort_order: Option<SortOrder>, table: &mut SelectableTable<MyRow, Column, Config>) -> Option<Response> {}
//Create your own table row UI
fn create_table_row(&self, ui: &mut Ui, row: &SelectableRow<MyRow, Column>, selected: bool, table: &mut SelectableTable<MyRow, Column, Config>,) -> Response {}
}
impl ColumnOrdering<MyRow> for Column {
fn order_by(&self, row_1: &MyRow, row_2: &MyRow) -> std::cmp::Ordering {
match self {
Column::Field1 => row_1.field_1.cmp(&row_2.field_1),
}
}
}
pub struct MainWindow {
table: SelectableTable<MyRow, Column, Config>
}
impl MainWindow {
pub fn new() -> Self {
Self {
table: SelectableTable::new(vec![Column::Field1])
}
}
}
impl eframe::App for MainWindow {
fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
self.table.show_ui(ui |table| {
table.striped(true)
.cell_layout(Layout::left_to_right(Align::Center))
.column(Column::exact(column_size).clip(true))
})
});
}
}
The demo is accessible online via this link
Clone the repository git clone https://github.com/TheRustyPickle/egui-selectable-table
Move into the demo folder cd egui-selectable-table/demo
cargo run --release
or
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
trunk serve
to run and visit http://127.0.0.1:8080/
Contributions, issues, and feature requests are welcome! If you'd like to contribute, please open a pull request.
This project is licensed under the MIT License.