Special callback for a quick click on slider, combo box?

I’m hoping for an instant click on certain controls to trigger something else in the GUI. Should I start wading through the code for these controls to make custom versions, or are they written “open” enough that such can be added to the existing controls?

Example: upon mouse-down do whatever would normally be done (e.g. pop up combo box menu) but if mouse-up is < 100ms, then abort that, re-hide the menu, and instead call my lambda…

you can define lambda functions for certain components, like this:

// in the slider's parent component's constructor...
slider.onValueChange = [this] { someOtherFunction(); // or you can write it all inline 
                              };
1 Like

Many thanks, Ben, but my question probably wasn’t clear.

I already have such a lamda callback for actual use of the control. For instance, in the case of a slider, when the user changes the slider value.

But I’m looking for an ADDITIONAL lambda for when a user simply gives the slider or combo box a quick click…

hmm, I’m not sure…

two options to try, just right off the top of my head:

  1. create an invisible button component to put on top of your slider, and implement the button’s .onClick() lamba
  2. look into component mouse events - not much experience there myself, but you should be able to create your own little callback handler by overriding the slider’s mouseDown() and mouseUp() methods

I think the challenge with either approach will be making sure that the callback/lambda for mouse click doesn’t happen if the slider value was actually changed, only for clicks that weren’t drag events. I see that the MouseEvent class has a mouseWasDraggedSinceMouseDown() method, perhaps that will be of some use to you…

Excellent brainstorming, thanks! One or two of those may turn out to be the solution.

In fact I’m refining my goal a little bit: maybe I can call my callback upon mouse down, even if the user should then continue to use the control. That’d probably fit my usage plan well and not be confusing or leave the user confused…

I think that is a good idea.

Btw event.getLengthOfMousePress() might become handy

1 Like