Giter VIP home page Giter VIP logo

egui-data-table's Introduction

Latest version Documentation

Data table UI implementation for egui

MSRV is 1.75, with RPITIT

Demo Web Page

Features

  • Undo/Redo for every editions
  • Show/Hide/Reorder columns
  • Row duplication / removal
  • Keyboard navigation
  • Internal clipboard support
  • System clipboard support
  • Tutorials documentation
  • Tidy light mode visuals

Usage

In Cargo.toml, add egui-data-table to your dependencies section

[dependencies]
egui-data-table = "0.1"

Minimal example:

// Use same version of `egui` with this crate!
use egui_data_table::egui;

// Don't need to implement any trait on row data itself.
struct MyRowData(i32, String, bool);

// Every logic is defined in `Viewer`
struct MyRowViewer;

// There are several methods that MUST be implemented to make the viewer work correctly.
impl egui_data_table::RowViewer<MyRowData> for MyRowViewer {
    fn num_columns(&mut self) -> usize {
        3
    }
    
    fn show_cell_view(&mut self, ui: &mut egui::Ui, row: &MyRowData, column: usize) {
        let _ = match column {
            0 => ui.label(format!("{}", row.0)),
            1 => ui.label(&row.1),
            2 => ui.checkbox(&mut { row.2 }, ""),
            _ => unreachable!()
        };
    }
    
    fn show_cell_editor(
        &mut self,
        ui: &mut egui::Ui,
        row: &mut MyRowData,
        column: usize,
    ) -> Option<egui::Response> {
        match column {
            0 => ui.add(egui::DragValue::new(&mut row.0).speed(1.0)),
            1 => {
                egui::TextEdit::multiline(&mut row.1)
                    .desired_rows(1)
                    .code_editor()
                    .show(ui)
                    .response
            }
            2 => ui.checkbox(&mut row.2, ""),
            _ => unreachable!()
        }
        .into() // To make focusing work correctly, valid response must be returned.
    }
    
    fn set_cell_value(&mut self, src: &MyRowData, dst: &mut MyRowData, column: usize) {
        match column {
            0 => dst.0 = src.0,
            1 => dst.1 = src.1.clone(),
            2 => dst.2 = src.2,
            _ => unreachable!()
        }
    }
    
    fn new_empty_row(&mut self) -> MyRowData {
        // Instead of requiring `Default` trait for row data types, the viewer is
        // responsible of providing default creation method.
        MyRowData(0, Default::default(), false)
    }
    
    // fn clone_row(&mut self, src: &MyRowData) -> MyRowData 
    // ^^ Overriding this method is optional. In default, it'll utilize `set_cell_value` which 
    //    would be less performant during huge duplication of lines.
}

fn show(ui: &mut egui::Ui, table: &mut egui_data_table::DataTable<MyRowData>) {
    ui.add(egui_data_table::Renderer::new(
        table,
        &mut { MyRowViewer },
    ));
}

For more details / advanced usage, see demo

egui-data-table's People

Contributors

kang-sw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.