| editSliderCombo(editObj, sliderObj, minval, maxval, startval, stepsize, eventActionCallback)
|
function f = editSliderCombo(editObj, sliderObj, minval, maxval, startval, stepsize, eventActionCallback)
f.getValue = @getValue;
f.setValue = @setValue;
f.getMinMax = @getMinMax;
f.setStatus = @setStatus;
handles.editObj = editObj;
handles.sliderObj = sliderObj;
initialize(minval, maxval, startval, stepsize, eventActionCallback);
%%
function initialize(minval, maxval, startval, stepsize, eventActionCallback)
stepfrac = stepsize / (maxval - minval);
set(handles.sliderObj, ...
'min', minval, ... % kHz
'max', maxval, ...
'value', startval, ...
'sliderStep', [stepfrac stepfrac], ...
'callback', {@sliderCallback, handles.editObj});
set(handles.editObj, ...
'string', num2str(get(sliderObj, 'value')), ...
'callback', {@editCallback, handles.sliderObj});
set([handles.editObj handles.sliderObj], 'userdata', eventActionCallback);
end
function editCallback(hobj, eventdata, sliderObj) %#ok<INUSL>
newval = str2double( get(hobj, 'string') );
setValue(newval);
feval(get(hobj, 'userdata')); % do the custom callback
end
function sliderCallback(hobj, eventdata, editObj) %#ok<INUSL>
newval = get(hobj, 'value');
setValue(newval);
set(editObj, 'string', num2str(newval));
feval(get(hobj, 'userdata')); % do the custom callback
end
function out = getValue
out = get(handles.sliderObj, 'value');
end
function setValue(newval)
minval = get(handles.sliderObj, 'min');
maxval = get(handles.sliderObj, 'max');
checkedVal = min(maxval, max(minval, newval));
set(handles.editObj, 'string', num2str(checkedVal));
set(handles.sliderObj, 'value', checkedVal);
end
function setStatus(state)
switch state
case 'enable'
set([handles.editObj handles.sliderObj], 'enable', 'on');
case 'disable'
set([handles.editObj handles.sliderObj], 'enable', 'off');
case 'visible'
set([handles.editObj handles.sliderObj], 'visible', 'in');
case 'invisible'
set([handles.editObj handles.sliderObj], 'visible', 'off');
otherwise
warning('unknown state');
end
end
end
|
|