Main Menu

Button Down

Started by seydlitz, 28 August 2020, 17:13:43

seydlitz

Hello,

I'm building a inventory screen for a game, and on it I've got a set of BitmapButtons, each corresponding to a category of inventory items. The user clicks the buttons for the categories they want the list to include, then clicks a button which filters on the specified categories. There's a value in the UserData for the button that is being used to determine if the button has been selected. This is working great!

The problem is that there doesn't seem to be a way to visually indicate that the button is selected in some manner - there's 20-odd buttons, so it would be helpful. I tried with both the "Down" status, which seems to apply only in the moment the button is clicked, and "Focus" status, which seems to only apply to one button at a time (and also seems to be being used in the background so I probably shouldn't be manually manipulating it anyway). Is there another way to do this, other than changing the color manually based on that UserData value?

texus

TGUI currently doesn't support a ToggleButton.
You can simulate it with a Label and a CheckBox (or RadioButton if you want to automatically untoggle the other buttons when one button is toggled). The checkbox is only used for the background image (it will have no text) and a Label is positioned on top of it to display the text.

The label needs to be centered and any mouse event should pass through it so that the checkbox acts on the mouse hover/clicks, so you will need the following two lines for the label:
Code (cpp) Select
label->ignoreMouseEvents(true)
label->setPosition(bindPosition(checkBox) + (bindSize(checkBox) - bindSize(label)) / 2.0);

seydlitz

Interesting, yeah I'll give that a shot. Thanks!