10 releases

new 0.2.2 Mar 18, 2023
0.2.1 Apr 9, 2022
0.2.0 Jan 9, 2022
0.1.8 Dec 22, 2021
0.1.6 Nov 30, 2021

#446 in GUI

Download history 22/week @ 2022-11-28 21/week @ 2022-12-05 24/week @ 2022-12-12 26/week @ 2022-12-19 12/week @ 2022-12-26 8/week @ 2023-01-02 11/week @ 2023-01-09 8/week @ 2023-01-16 25/week @ 2023-01-23 27/week @ 2023-01-30 54/week @ 2023-02-06 37/week @ 2023-02-13 58/week @ 2023-02-20 15/week @ 2023-02-27 15/week @ 2023-03-06 25/week @ 2023-03-13

118 downloads per month
Used in sqlui

MIT license

140KB
422 lines

fltk-table

A smart table widget for fltk-rs. It aims to reduce the amount of boilerplate required to create a table.

Usage

[dependencies]
fltk = "1.2"
fltk-table = "0.1"

Example

use fltk::{
    app, enums,
    prelude::{GroupExt, WidgetExt},
    window,
};
use fltk_table::{SmartTable, TableOpts};

fn main() {
    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut wind = window::Window::default().with_size(800, 600);

    /// We pass the rows and columns thru the TableOpts field
    let mut table = SmartTable::default()
    .with_size(790, 590)
    .center_of_parent()
    .with_opts(TableOpts {
        rows: 30,
        cols: 15,
        editable: true,
        ..Default::default()
    });
    
    wind.end();
    wind.show();

    // Just filling the vec with some values
    for i in 0..30 {
        for j in 0..15 {
            table.set_cell_value(i, j, &(i + j).to_string());
        }
    }

    // set the value at the row,column 4,5 to "another", notice that indices start at 0
    table.set_cell_value(3, 4, "another");

    assert_eq!(table.cell_value(3, 4), "another");

    // To avoid closing the window on hitting the escape key
    wind.set_callback(move |_| {
        if app::event() == enums::Event::Close {
            app.quit();
        }
    });

    app.run().unwrap();
}

You can retrieve a copy of the data using the SmartTable::data() method.

The TableOpts struct also takes styling elements for cells and headers:

let mut table = SmartTable::default(TableOpts {
        rows: 30,
        cols: 15,
        cell_selection_color: Color::Red.inactive(),
        header_frame: FrameType::FlatBox,
        header_color: Color::BackGround.lighter(),
        cell_border_color: Color::White,
        ..Default::default()
    });

image

The row/column header strings can also be changed using the set_row_header_value() and set_col_header_value() methods, which take an index to the required row/column.

Dependencies

~12MB
~278K SLoC