I’m making a board like this
GtkWidget *board[x][y];
If I do an array of buttons, how can I know which button was pressed?
Does
g_signal_connect(G_OBJECT(board[][]), "clicked",
G_CALLBACK(board_button_pressed), NULL);
// I want to know what [][] they pressed, how could I verify/check this?
return which button of the array was pressed? Or do I have to make a separate function for each of the board pieces?
For example:
OOO
OXO
OOO
How to know which button was pressed if all of the buttons are named the same?
One of the simplest way would be to just send the information when you are connecting to the callback as data. Something on these lines:
Please note that
"clicked"signal is associated only withGtkButton. If you need to use withGtkWidgetthen look at"button-press-event"or"button-release-event", in which case the callback signature will also change.Hope this helps!