Skip to content

Triggering a slider event only on release #60

digitologist opened this Issue Aug 28, 2012 · 8 comments

4 participants


What would be the best way to only respond to the event from a slider only when the mouse is released, instead of on every mouse movement?

My workaround was to add a "getState()" call to the ofxUIwidget base class and add to my handler this logic:

if(slider->getState() != OFX_UI_STATE_DOWN) { ... }

If there's a cleverer way to do it, would love to know, or otherwise hopefully you'll consider this for a future release.


I just started using oF and ofxUI.
this looks like a great way to prototype service interfaces.

I kinda had the same question.
it would be nice to be able and only listen to a certain type of event ("mouseReleased" or "change", for instance).

I hadn't figured out how to achieve your workaround yet (4 days into oF)
thanks a lot :)

from here I think I'll proceed adding a switch to dispatch events and add an extra class to handle/filter those.
not sure how the code will look, but it will be an interesting exercise to learn more C++ :)


Ditto, although I DON'T want it to "slide" when I release the mouse, only down & move. (But in my case I want it to apply to setting the value as well as the event callback...)

rezaali commented Jul 19, 2013

I will try to make slider flexible enough to handle these cases... @SoylentGraham have you tried using the arrow keys to change the value of the slider when your mouse is over the slider?

@hellosavants @digitologist I think the api call for this would be slider->setEventTriggerType(...);

enum ofxUIWidgetTriggerType



hi Reza

I'm the noob here, as I just started doing C++ last week.
my suggestion from experience with other event based async coding is that you should be able to register for a type of event.

I'm super-cool with this :)
enum ofxUIWidgetTriggerType

I've looked at your code, and the sliders are terrific!!!
I like how I can rely on them and how much control I have.

I've managed pretty quickly to customise how I handle the events and control the view.
(I still have some quirks to figure out)

btw, I checked your work.
awesome stuff ;)



as I said, I'm a newcomer to C++, so I might be doing it in a stupid way :)
right now this is how I handle the "release" of a ofxUILabelButton
working mainly in C for Atmel/Arduino you'll notice I'm a #define freak.

in testApp::setup()

ofxUILabelButton *loadFilesButton = new ofxUILabelButton(220, false, _FOLDER_SELECT_BUTTON,OFX_UI_FONT_MEDIUM);
ofAddListener(gui->newGUIEvent, this, &testApp::guiEvent);

in testApp::guiEvent(ofxUIEventArgs &e)

string wName = e.widget->getName();
int wState = e.widget->getState();
cout << "select folder" << endl;


@rezaali hmm arrow keys aren't doing anything... (maybe need to update my fork)

Just to be clear, my situation is thus; My slider is changing constantly (max is increasing), I drag to a point I want, but when I mouse-release [because the max has changed] it changes the current value, so it's really hard for me to select the value I want


arrows are by default increasing/decreasing via means of arrow keys, according to the resolution you set with sliderInstance->setIncrement(float _inc)

I had the need to create a "snapping" slider so I set the scaled values and handled the value to make some calculations and setValue() with the remapped one.
I only needed to handle 5 positions, but this can be easily turned into a dynamic one.

if(e.widget->getName() == _TIME_SLIDER)
ofxUISlider *slider = (ofxUISlider *) e.widget;

        ostringstream newLabelBase;
        //snprintf(newLabelBase, "%s %f", _TIME_LABEL, slider->getValue());
        float sliderValue = slider->getScaledValue()>1 ? slider->getScaledValue() : 1;
        unsigned short indx = slider->getScaledValue() > 0 ? slider->getScaledValue()-1 : 0;

        newLabelBase << "TIME: " << delayLabelList[indx];
        // string *newLabel = "_TIME_LABEL  " + slider->getValue() + slider->getScaledValue();

        // ofBackground(slider->getValue()); 

rezaali commented Feb 2, 2014 you can set the trigger type on any widget (especially useful and meaningful when it comes to sliders)

enum ofxUITriggerType
    OFX_UI_TRIGGER_NONE     = 0x00,
    OFX_UI_TRIGGER_BEGIN    = 0x01,
    OFX_UI_TRIGGER_END      = 0x04,
    OFX_UI_TRIGGER_ALL      = 0x07

so if you only want begin and change events to be emitted for sliders you can do (by default its OFX_UI_TRIGGER_ALL):


I decided to use a bitwise & comparison because its cool and I'm assuming its faster then a ton of if statements or whatnot. The All Widgets example shows how to set the TriggerType as well.

@rezaali rezaali closed this Feb 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.