Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
slider release woes

Subject: slider release woes

From: Malcolm McLean

Date: 7 Feb, 2010 15:50:05

Message: 1 of 5

My slider very nicely calls the callback as the user drags the bar.
Unfortunately I can't tell when he has released it. I tried setting the WindowButtonUpFCn, but this wasn't called at the right time. It did get called later, when another click somewhere else in the figure was released.

Subject: slider release woes

From: ImageAnalyst

Date: 7 Feb, 2010 15:56:10

Message: 2 of 5

On Feb 7, 10:50 am, "Malcolm McLean" <malcolm.mcle...@btinternet.com>
wrote:
> My slider very nicely calls the callback as the user drags the bar.
> Unfortunately I can't tell when he has released it. I tried setting the WindowButtonUpFCn, but this wasn't called at the right time. It did get called later, when another click somewhere else in the figure was released.

-------------------------------------------------------------------
Mine doesn't behave that way. My slider callback gets called whenever
the user clicks on the end arrows or in the scrollable area. Nothing
gets called as the user clicks and drags the thumbbar. Then when the
user finally releases the thumbbar the callback finally gets called.
Pretty much exactly the opposite of yours. I didn't do anything
special and it operates like we would intuitively want. So I'm not
sure why yours is operating differently. What operating system are
you using?

Subject: slider release woes

From: Jan Simon

Date: 7 Feb, 2010 16:52:04

Message: 3 of 5

Dear Malcolm!

> My slider very nicely calls the callback as the user drags the bar.

Please explain how do you create "your" slider. The behaviour does not match the usual UICONTROL('Style', 'slider').

Kind regards, Jan

Subject: slider release woes

From: Malcolm McLean

Date: 8 Feb, 2010 07:33:04

Message: 4 of 5

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hkmr3k$c40$1@fred.mathworks.com>...
> Dear Malcolm!
>
> > My slider very nicely calls the callback as the user drags the bar.
>
> Please explain how do you create "your" slider. The behaviour does not match the usual UICONTROL('Style', 'slider').
>
> Kind regards, Jan

Here's what I'm trying to do.
My thinking is that sometimes the caller will want a callback in real time, as the user moves the spinner, other times he'll want a callback only when the user has finished the adjustment, eg if updating the state of the program is very lengthy.

There are a few other issues with this, eg how to pass extra arguments to the callback. Also, I'd like to bundle it into a class, but class members won't function as slider callbacks.

function [ obj ] = uispinner( val, min, max, step, pos, callback )
%Spinner Create a number spinner
% Allows the user to enter a scalar

obj = uipanel('Position', pos);
hedit = uicontrol('Style', 'edit', ...
'Position', [pos(1), pos(2), pos(3)-10, pos(4)]);
hslider = uicontrol('Style', 'slider', ...
'Position', [pos(1)+pos(3)-10, pos(2), 10, pos(4)], ...
'Callback', @slide, 'BusyAction', 'queue');

if(iscell(callback))
    cbdata = callback;
    callback = cbdata{1};
    cbdata(1) = [];
else
    cbdata = [];
end
s = struct('hedit', hedit, 'hslider', hslider, 'min', min, 'max', max, ...
'val', val, 'step', step, 'callback', callback, 'cbdata', {cbdata});
set(obj, 'UserData', s);
set(hslider, 'UserData', obj);
set(hedit, 'UserData', obj);
end

function slide(hObject, eventdata)
    t = get(hObject, 'Value');
    hpanel = get(hObject, 'UserData');
    s = get(hpanel, 'UserData')
    v = s.min + (s.max-s.min)*t;
    if(s.step ~= 0)
        v = v - mod(v, s.step);
    end
    set(s.hedit, 'String', sprintf('%g', v));
    s.val = v;
    set(hpanel, 'UserData', s);
    if(isempty(s.cbdata))
        s.callback(hpanel, [], s.val);
    elseif(length(s.cbdata) == 1)
        s.callback(hpanel, [], s.val, s.cbdata{1});
    elseif(length(s.cbdata) == 2)
        s.callback(hpanel, [], s.val, s.cbdata{1}, s.cbdata{2});
    end
end

Subject: slider release woes

From: Yair Altman

Date: 8 Feb, 2010 09:18:03

Message: 5 of 5

The solution to the continuous slider callback issue is explained here: http://UndocumentedMatlab.com/blog/continuous-slider-callback/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us