0.8 Many Buttons on Grid

Started by sors, 29 September 2018, 13:52:33

sors

Hi, I create the table like this:
Quotegrid = 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?

texus

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:
Code (cpp) Select
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);