How are the if's in a GUI.Toolbar handled?

Title explains it,

Since ve’ve got an array of strings that define the buttons, how do i check if and which button was clicked?



Just as Toggle takes a boolean and returns the new boolean (which changes if the user clicks it), Toolbar takes an int for the current selection and returns the new selection as an int.

Similarly Textfield takes and returns a String.