drawableButton, odd behaviour

I have a drawableButton placed onto my toolbar. It will toggle images when clicked. I call its setCommandToTrigger() and pass a valid command for it to trigger. The odd thing is that it will trigger the command if I don’t click directly on the image but beside it, if I click on the image it will toggle the image but not cause the command to be invoked. Perhaps the problem is with my drawablebutton class?

//class for start stop toggle button
class StartStopButton : public ToolbarItemComponent
StartStopButton (const int toolbarItemId)
: ToolbarItemComponent (toolbarItemId, T(“Custom Toolbar Item”), false) {
addAndMakeVisible (tglButton = new DrawableButton(T(“StartStop”), DrawableButton::ButtonStyle::ImageFitted ));
Drawable* play = Drawable::createFromImageFile(File(“C:\MyDocuments\SourceCode\cabbage\cabbage\src\images\file-play.svg”));
Drawable* stop = Drawable::createFromImageFile(File(“C:\MyDocuments\SourceCode\cabbage\cabbage\src\images\file-stop.svg”));
tglButton->setImages(play, 0, 0, 0, stop, 0, 0, 0);
tglButton->setClickingTogglesState (true);
tglButton->setBackgroundColours (Colour(0x00000000), Colour(0x00000000));

    delete tglButton;

bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize, int& minSize, int& maxSize){
    if (isToolbarVertical)
        return false;
    preferredSize = 50;
    minSize = 50;
    maxSize = 50;
    return true;

void paintButtonArea (Graphics& g, int, int, bool, bool){
	g.fillAll (Colour(0x00000000));

void contentAreaChanged (const Rectangle<int>& contentArea) {
    tglButton->setSize (contentArea.getWidth(), contentArea.getHeight());
    tglButton->setCentrePosition (contentArea.getCentreX(), contentArea.getCentreY());

DrawableButton* tglButton;

You really shouldn’t use setClickingTogglesState (true) in that kind of situation.

Presumably your button’s toggle state represents some boolean value somewhere, so you need to set up some proper sync between the button and the data - when the data changes, you update the button’s toggle state, and when the button is clicked, you change the data’s state. If you do that, you don’t need to make the button flip its own state, it should all just work.

(TBH the existance of setClickingTogglesState probably encourages bad design, and the class might be better without it. There aren’t many situations I can think of where it’s a good idea)

In my command perform routine I try to change the state of the toggle like this:

bool CsoundEditor::perform (const InvocationInfo& info)
toggleButton = dynamic_cast <StartStopButton*> (info.originatingComponent);
switch (info.commandID)
case CommandIDs::fileRun:
toggleButton->setToggleState(false, false);
toggleButton->setToggleState(true, false);
showMessage(“toggle button clicked”);

return true;

If I click on the image nothing happens, it doesn’t toggle and if I click just to the left of the image it causes my popup window to display my message. Perhaps I misunderstood the use of InvocationInfo originatingComponent member?

That’s exactly my point - if you use setClickingTogglesState (true) and also flip the state in your command callback, then clicking will flip the state twice.

Sorry, I should have mentioned that I no longer have setClickingToggleState set to true, yet I still get no toggling and my button only works if I click outside the image to the left. If I start the debugger and place a breakpoint in my perform function it doesn’t even enter the button command unless I click to the left, clicking on my button image doesn’t cause any command to be called?

Clicking anywhere inside a button will hit it unless you’ve set up a custom hitTest method or something.

I don’t know anything about custom hit methods so I’m pretty sure that’s not the issue. I’ll try to recreate the problem with a new project, if I can I’ll post the sample code here, if I can’t recreate the problem at least I’ll know something else in my code is causing the odd behaviour.

I’ve recreated the problem in a simple project which I’ve attached here as a VE08 project. The same issues persists, a) I can’t toggle the button image by calling it’s setToggleState() methods and I can only get a hit on my button if I click, in this case, just under the button image. I’ve included the images in the archive so it should build without problem once you change the include folders and what not. I’m interested to see where I went wrong.

If people have tried out my source code would they mind letting me know if they experience the same issue I did with regards the toggling of the tool bar button state? The lack of replies has me concerned that it’s working fine for others?