diff --git a/widgetLibrary/widget_slider.lua b/widgetLibrary/widget_slider.lua index 7a9bd83..65971ed 100644 --- a/widgetLibrary/widget_slider.lua +++ b/widgetLibrary/widget_slider.lua @@ -113,6 +113,7 @@ local function createHorizontalSlider( slider, options ) -- We need to assign these properties to the object view._left = viewLeft view._right = viewRight + view._isEnabled = opt.isEnabled view._fill = viewFill view._middle = viewMiddle view._handle = viewHandle @@ -138,7 +139,12 @@ local function createHorizontalSlider( slider, options ) self.value = value return self._view:_setValue( value ) end - + + -- Function to set a button as active + function slider:setEnabled( isEnabled ) + self._view._isEnabled = isEnabled + end + ---------------------------------------------------------- -- PRIVATE METHODS ---------------------------------------------------------- @@ -320,12 +326,14 @@ local function createVerticalSlider( slider, options ) -- We need to assign these properties to the object view._top = viewTop view._bottom = viewBottom + view._isEnabled = opt.isEnabled view._fill = viewFill view._middle = viewMiddle view._handle = viewHandle view._currentPercent = opt.defaultValue view._width = opt.width view._height = opt.height + view._isEnabled = opt.isEnabled view._listener = opt.listener ------------------------------------------------------- @@ -346,7 +354,12 @@ local function createVerticalSlider( slider, options ) self.value = value return self._view:_setValue( value ) end - + + -- Function to set a button as active + function slider:setEnabled( isEnabled ) + self._view._isEnabled = isEnabled + end + ---------------------------------------------------------- -- PRIVATE METHODS ---------------------------------------------------------- @@ -357,6 +370,11 @@ local function createVerticalSlider( slider, options ) local _slider = event.target.parent -- Set the target to the handle event.target = self._handle + + -- If the button isn't active, just return + if not view._isEnabled then + return + end if "began" == phase then -- The content bounds of our handle @@ -485,10 +503,19 @@ function M.new( options, theme ) opt.width = customOptions.width or themeOptions.width or 200 -- from the sheet file opt.height = customOptions.height or themeOptions.height or 10 -- from the sheet file opt.id = customOptions.id + + opt.isEnabled = customOptions.isEnabled + + -- If the user didn't pass in a isEnabled flag, set it to true + if nil == opt.isEnabled then + opt.isEnabled = true + end + opt.baseDir = customOptions.baseDir or system.ResourceDirectory opt.defaultValue = customOptions.value or 50 opt.orientation = customOptions.orientation or "horizontal" opt.listener = customOptions.listener + -- Frames & Images opt.sheet = customOptions.sheet diff --git a/widgetLibrary/widget_stepper.lua b/widgetLibrary/widget_stepper.lua index c34ea49..7e6c097 100644 --- a/widgetLibrary/widget_stepper.lua +++ b/widgetLibrary/widget_stepper.lua @@ -96,7 +96,7 @@ local function initWithSprite( stepper, options ) local themeData = require( opt.themeData ) imageSheet = graphics.newImageSheet( opt.themeSheetFile, themeData:getSheet() ) end - + -- Create the view view = display.newSprite( stepper, imageSheet, sheetOptions ) view:setSequence( "default" ) @@ -122,6 +122,8 @@ local function initWithSprite( stepper, options ) ------------------------------------------------------- -- Assign to the view + + view._isEnabled = opt.isEnabled view._timerIncrementSpeed = opt.timerIncrementSpeed or 1000 view._changeIncrementSpeedAtTime = view._timerIncrementSpeed view._increments = 0 @@ -164,6 +166,11 @@ local function initWithSprite( stepper, options ) function stepper:setValue( newValue ) return self._view:_setValue( newValue ) end + + -- Function to set a button as active + function stepper:setEnabled( isEnabled ) + self._view._isEnabled = isEnabled + end ---------------------------------------------------------- -- PRIVATE METHODS @@ -174,6 +181,11 @@ local function initWithSprite( stepper, options ) local phase = event.phase local _stepper = self.parent event.target = _stepper + + -- If the button isn't active, just return + if not view._isEnabled then + return + end -- The content bounds of our increment/decrement segments local decrementBounds = self._decrementOverlay.contentBounds @@ -421,7 +433,13 @@ function M.new( options, theme ) opt.onHold = customOptions.onHold opt.timerIncrementSpeed = customOptions.timerIncrementSpeed or 1000 opt.changeSpeedAtIncrement = customOptions.changeSpeedAtIncrement or 5 - + opt.isEnabled = customOptions.isEnabled + + -- If the user didn't pass in a isEnabled flag, set it to true + if nil == opt.isEnabled then + opt.isEnabled = true + end + -- Frames & Images opt.sheet = customOptions.sheet opt.themeSheetFile = themeOptions.sheet