Button toggle momentary


#1

I noticed that if I do setClickingTogglesState(true) on a button we get a latching button behavior.

I think it would be very helpful if I could set it to act as a momentary button instead (setting the Value object high when pushed down, then back to 0 on release). Any chance you want to include that somewhere?


#2

I use that as well sometimes
quite useful with multitouch interface indeed


#3

So I finally got back around to this.

Here is a consistent (though somewhat hacky) momentary button, just by overriding the mouse up/down methods on a button. I also add a bool value to indicate if the button is momentary, and since there is an extra click in there you have to make sure that the buttonListener or ValueListener knows to check the value and acts appropriately.

I’m sure there is a better way to do this by modifying the button class - but there are too many private variables in buttons to get it cleanly done with a subclass.

[code]
void LT_Button_Drawable::mouseDown(const MouseEvent &e) {

DrawableButton::mouseDown(e);

// if momentary .... then trigger a click here ...
if (isMomentary && (bool)getToggleState() == false)
    setToggleState(true, false);

}

void LT_Button_Drawable::mouseUp(const MouseEvent &e) {

DrawableButton::mouseUp(e);

// if momentary .... then trigger a click here ...
if (isMomentary  && (bool)getToggleState() == true)
    setToggleState(false, false);

}[/code]