@@ -332,6 +332,34 @@ function createTableMenu(obj, hf, frame)
332332 set(hLine , ' Widths' , [-5 - 5 ]);
333333 end
334334
335+ function h = addSlider(obj , parent , range , varargin )
336+ % Add a slider to the specified widget.
337+ %
338+ % HS = addSlider(gui, parent, range)
339+ % HS = addSlider(gui, parent, range, value)
340+
341+ value = (range(1 ) + range(2 )) / 2 ;
342+ if ~isempty(varargin ) && isnumeric(varargin{1 }) && isscalar(varargin{1 })
343+ value = varargin{1 };
344+ varargin(1 ) = [];
345+ end
346+
347+ % compute slider steps
348+ valExtent = range(2 ) - range(1 );
349+ % set unit step equal to 1 grayscale unit
350+ sliderSteps = [1 10 ] / valExtent ;
351+
352+ % creates the new control
353+ bgColor = getWidgetBackgroundColor(obj );
354+ h = uicontrol(' Style' , ' Slider' , ...
355+ ' Parent' , parent , ...
356+ ' Min' , range(1 ), ' Max' , range(2 ), ...
357+ ' Value' , value , ...
358+ ' SliderStep' , sliderSteps , ...
359+ ' BackgroundColor' , bgColor , ...
360+ varargin{: });
361+ end
362+
335363 function h = addCheckBox(obj , parent , label , state , cb ) % #ok<INUSL>
336364
337365 hLine = uix .HBox(' Parent' , parent , ...
0 commit comments