BonsaiDen / cursive_table_view

A basc table view compnent for cursive.
Apache License 2.0
49 stars 23 forks source link

Not enough info in set_on_submit #23

Open smallB007 opened 4 years ago

smallB007 commented 4 years ago

Hi everyone, I'm using cursive crate along with cursive_table_view crate. I'm registering callback to each created table and yes, this callback is being triggered, but I believe that there is not enough info in that callback.

//The callback
    fn Enter_Fn(app: &mut cursive::Cursive, row: usize,index: usize)
    {
    //how am I suppose to know which view triggered that callback???
    }
    ////<<<later in the code
    for i in 0..10
    {
//create panels
    let mut panel_left = create_table();//see decl below, it is the same as in examples from the repo
    panel_left.set_on_submit(Enter_Fn);//register callback
    //here I have some code that defines layout etc, so the last line is "pseudo code"
    siv.add_layout(panel_left);
    }

    fn create_table() -> TableView<Foo, BasicColumn> ;//this is function that creates table
//end of code

How to know in the Enter_Fn function which table was active when the enter was pressed, that is, we are inside of the Enter_Fn callback but all we have is app, row and index but not the view which triggered that callback.

Thanks for any help

smallB007 commented 4 years ago

Hi, I would appreciate if somebody would either tell me that this functionality is not supported/missing/or I'm doing something wrong(most likely). Seriously... For somebody (like author of the crate who know the code and workings of it) to be able to help this shouldn't be that difficult. Leaving/Ignoring questions is rather... well let's be honest disappointing and irritating.

gyscos commented 2 years ago

Note that set_on_submit can accept closures, which lets you embed parameters:

fn Enter_Fn(app: &mut cursive::Cursive, row: usize, index: usize, table_id: usize) { }

for i in 0..10 {
    //create panels
    let mut panel_left = create_table();//see decl below, it is the same as in examples from the repo
    panel_left.set_on_submit(|s, r, index| Enter_Fn(s,r,index, i)); //register callback. Note that here we include the `i` parameter.
    // here I have some code that defines layout etc, so the last line is "pseudo code"
    siv.add_layout(panel_left);    
}