TGUI Forum

General Category => Help requests => Topic started by: sors on 29 September 2018, 13:52:33

Title: 0.8 Many Buttons on Grid
Post by: sors on 29 September 2018, 13:52:33
Hi, I create the table like this:
Quote
grid = tgui::Grid::create();
            for(int i = 0; i < 100; ++i)
                {
                    auto h = tgui::HorizontalLayout::create({ tgui::bindWidth(scrollablePanel), tgui::bindHeight(scrollablePanel) / 10 });
                    auto b = tgui::Button::create("Button");
                    h->add(tgui::Label::create("Label"));
                    h->add(tgui::Label::create("Label"));
                    h->add(tgui::Label::create("Label"));
                    h->add(tgui::Label::create("Label"));
                    h->add(b);
                    grid->addWidget(h, i, 0);
                }
how to find out which button in the table was pressed?
Title: Re: 0.8 Many Buttons on Grid
Post by: texus on 29 September 2018, 14:13:30
It depends a bit on what information you need exactly in the callback handler. But if you e.g. need to know the index of the button then you can just pass it as a constant to the connect function:
void buttonPressed(int index)
{
    std::cout << "The " << index << "th button was pressed" << std::endl;
}

// The following goes in the for loop that you showed
b->connect("pressed", &buttonPressed, i);
Title: Re: 0.8 Many Buttons on Grid
Post by: sors on 30 September 2018, 15:48:45
tnx!