Toolbar and toggle button

Ive been trying to implement a toggle button inside the toolbar, and assign a command manager to it. however i received a JUCE Assertion failure on button cpp
it had the following text:

[quote]
// if you’ve got clickTogglesState turned on, you shouldn’t also connect the button
// up to be a command invoker. Instead, your command handler must flip the state of whatever
// it is that this button represents, and the button will update its state to reflect this
// in the applicationCommandListChanged() method.[/quote]

Which i dont fully understand. how would the button be able to communicate with the command manager, and send a toggle message?
how does the button know what to represent?

Not sure I can think of a better way of explaining it than in the comment…

If you’re using the command manager you never use the button to send a toggle message, you just use the command manager to change the state of your data, and let the button update itself to reflect that change.

Aha! finaly got it! and it was much simpler than i tought:

all i had to do is implement the ApplicationCommandInfo::setTicked() function (inside the ApplicationCommandTarget::getCommandInfo() ) for that command. This takes care of toggling the button, even of its not defined as a toggle button.

then to make the same button class for both toggle and click behaviors, in my button’s paintButtonArea() method i used this:

and voila!
it worx!

Thanks!

1 Like