Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkbox + boolean support #9

Open
bryceac opened this issue Mar 15, 2022 · 4 comments
Open

checkbox + boolean support #9

bryceac opened this issue Mar 15, 2022 · 4 comments

Comments

@bryceac
Copy link

bryceac commented Mar 15, 2022

I have been playing with this crate and while it is relatively easy to use, I think more data types should be supported.

In particular booleans should be accepted cell value with a check box or something to toggle.

From a user perspective, If I were to have a something in a table that can be true or false, it would be better for the user to say click the checkbox and have the program set it to be true.

However, with the current state of things, with every cell expected to be a string value, I can only simplify things down to Y/N, even though I thought I saw that tables in FLTK can render these properly.

@MoAlyousef
Copy link
Collaborator

MoAlyousef commented Mar 18, 2022

From what I understand, FLTK's table widget has 2 main apis, one for handling (viewing/modifying) large data, which is based on simple drawing of cells and data via Table::draw_cell. Another api which can use widgets as children of the table (via Table::find_cell), which might choke on large data.
This crate primarily targets the first role since it requires a lot of boilerplate.
The other role can be simply implemented directly using an fltk Table widget.

image

use fltk::{enums::*, prelude::*, *};

const ROWS: i32 = 6;
const COLS: i32 = 5;

struct MyTable {
    table: table::Table,
}

impl MyTable {
    pub fn new() -> Self {
        let mut table = table::Table::default()
            .with_size(400, 300)
            .center_of_parent();
        table.set_frame(FrameType::NoBox);
        table.set_rows(ROWS);
        table.set_cols(COLS);
        for i in 1..ROWS {
            if let Some((x, y, _, h)) = table.find_cell(table::TableContext::RowHeader, i, 0) {
                let mut f = frame::Frame::new(x, y, 80, h, None).with_label(&format!("row {}", i));
                f.set_frame(FrameType::ThinUpBox);
            }
        }
        for j in 1..COLS {
            if let Some((x, y, w, _)) = table.find_cell(table::TableContext::ColHeader, 0, j) {
                let mut f = frame::Frame::new(x, y, w, 25, None).with_label(&format!("col {}", j));
                f.set_frame(FrameType::ThinUpBox);
            }
        }
        for i in 1..ROWS {
            for j in 1..COLS {
                if let Some((x, y, w, h)) = table.find_cell(table::TableContext::Cell, i, j) {
                    if j == 2 {
                        button::CheckButton::new(x, y, w, h, None);
                    } else {
                        let mut i = input::Input::new(x, y, w, h, None);
                        i.set_value("");
                    }
                }
            }
        }

        table.end();
        Self { table }
    }
}

widget_extends!(MyTable, table::Table, table);

fn main() {
    let a = app::App::default();
    let mut win = window::Window::default().with_size(500, 400);
    let table = MyTable::new();
    win.end();
    win.show();
    a.run().unwrap();
}

It would benefit from a method to associate data with widgets, but adding this functionality to this crate might be complicated.

@bryceac
Copy link
Author

bryceac commented Mar 18, 2022 via email

@CezarGarrido
Copy link

@MoAlyousef Comrade, I'm trying to use this as an example. For some reason, the scroll doesn't work.

Can you tell me how I can solve it?

@MoAlyousef
Copy link
Collaborator

Hello
You would need to place the Table inside a Scroll widget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants