Difference between revisions of "UI.Slider"
From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2023.1<br/> '''Class:''' UI<br/> === Description === Creates Slider widgets. The widget can be a '''Slider''', or an '''ArcSlider...") |
|||
Line 4: | Line 4: | ||
=== Description === | === Description === | ||
− | Creates Slider widgets. The widget can be a '''Slider''', or an '''ArcSlider'''. | + | Creates Slider widgets. The widget can be a '''Slider''', or an '''ArcSlider'''. Sliders give value from 0 to 1. |
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
UI.Slider.new(direction,svgpath,resolution,dual,offset) | UI.Slider.new(direction,svgpath,resolution,dual,offset) | ||
Line 46: | Line 46: | ||
stage:addChild(gui) | stage:addChild(gui) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''onWidgetChange''' | ||
+ | <syntaxhighlight lang="lua"> | ||
+ | --Sliders give value from 0 to 1 | ||
+ | local sliderA=UI.Slider.new() | ||
+ | sliderA:setDimensions(200,50) | ||
+ | sliderA:setPosition(250,50) | ||
+ | sliderA.name="Slider A" | ||
+ | |||
+ | local sliderB=UI.Slider.new() | ||
+ | sliderB:setDimensions(200,50) | ||
+ | sliderB:setPosition(250,150) | ||
+ | --This slider center is in the middle of the range | ||
+ | sliderB:setCenter(.5) | ||
+ | --Initial value is .6 | ||
+ | sliderB:setKnobPosition(.6) | ||
+ | --Discrete steps of .1 | ||
+ | sliderB:setResolution(.1) | ||
+ | sliderB.name="Slider B" | ||
+ | |||
+ | stage:addChild(sliderA) | ||
+ | stage:addChild(sliderB) | ||
+ | |||
+ | --Here we put the WidgetAction listener on stage. | ||
+ | --It will be propagated from each button up to stage through the sprite tree | ||
+ | --First parameter of event listeners are always the source widget of the event | ||
+ | function stage:onWidgetChange(w,v) | ||
+ | print(w.name.." value is "..v) | ||
+ | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{GIDEROS IMPORTANT LINKS}} | {{GIDEROS IMPORTANT LINKS}} |
Revision as of 00:41, 16 October 2023
Available since: Gideros 2023.1
Class: UI
Description
Creates Slider widgets. The widget can be a Slider, or an ArcSlider. Sliders give value from 0 to 1.
UI.Slider.new(direction,svgpath,resolution,dual,offset)
UI.ArcSlider.new(astart,aend,resolution,dual,offset)
Parameters
direction: (bool) is the Slider widget vertical default = true
svgpath: (string) the Slider widget svg path
resolution: (number) the Slider widget step increment
dual: (bool) has the Slider widget two knobs default = false
offset: (number) the Slider widget knob offset
astart: (number) the Slider widget start angle value
aend: (number) the Slider widget end angle value
Examples
A Slider
local gui = UI.Slider.new(false, nil, 0.25, true)
gui:setDimensions(256, 32)
--gui:setVertical(false)
gui:setColor(0xaa0000)
gui:setPosition(50, 50)
--gui:setResolution(0.25)
gui:setCenter(0.25)
gui:setKnobPosition(0.25)
stage:addChild(gui)
An ArcSlider
local gui = UI.ArcSlider.new(5, 60, 0.1, true, 0.1)
gui:setDimensions(128, 128)
--gui:setVertical(false)
gui:setColor(0xaa0000)
gui:setPosition(50, 50)
--gui:setResolution(0.25)
--gui:setCenter(0.25)
--gui:setKnobPosition(0.25)
stage:addChild(gui)
onWidgetChange
--Sliders give value from 0 to 1
local sliderA=UI.Slider.new()
sliderA:setDimensions(200,50)
sliderA:setPosition(250,50)
sliderA.name="Slider A"
local sliderB=UI.Slider.new()
sliderB:setDimensions(200,50)
sliderB:setPosition(250,150)
--This slider center is in the middle of the range
sliderB:setCenter(.5)
--Initial value is .6
sliderB:setKnobPosition(.6)
--Discrete steps of .1
sliderB:setResolution(.1)
sliderB.name="Slider B"
stage:addChild(sliderA)
stage:addChild(sliderB)
--Here we put the WidgetAction listener on stage.
--It will be propagated from each button up to stage through the sprite tree
--First parameter of event listeners are always the source widget of the event
function stage:onWidgetChange(w,v)
print(w.name.." value is "..v)
end