Open bryceac opened 2 years ago
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.
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.
I see. That’s understandable, though a little disappointing. Thanks for the reply.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Mohammed Alyousef @.> Sent: Friday, March 18, 2022 5:19:49 AM To: fltk-rs/fltk-table @.> Cc: bryceac @.>; Author @.> Subject: Re: [fltk-rs/fltk-table] checkbox + boolean support (Issue #9)
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. Another api which can use widgets as children of the table, 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.
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.setcols(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.setframe(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 seems a bit overkill.
— Reply to this email directly, view it on GitHubhttps://github.com/fltk-rs/fltk-table/issues/9#issuecomment-1072358034, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAHKMOQGNBONJPOSNWOGLJDVARYGLANCNFSM5Q2BOJHQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>
@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?
Hello You would need to place the Table inside a Scroll widget
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.