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

Not enough info in set_on_submit #23

Open
smallB007 opened this issue Jul 26, 2020 · 2 comments
Open

Not enough info in set_on_submit #23

smallB007 opened this issue Jul 26, 2020 · 2 comments

Comments

@smallB007
Copy link

smallB007 commented Jul 26, 2020

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
Copy link
Author

smallB007 commented Jul 28, 2020

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
Copy link
Collaborator

gyscos commented Jan 5, 2022

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);    
}

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

2 participants