*

sors

  • *
  • 13
    • View Profile
0.8 Many Buttons on Grid
« 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?

*

texus

  • *****
  • 1272
    • View Profile
    • Texus's Blog
Re: 0.8 Many Buttons on Grid
« Reply #1 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);

*

sors

  • *
  • 13
    • View Profile
Re: 0.8 Many Buttons on Grid
« Reply #2 on: 30 September 2018, 15:48:45 »
tnx!