UI.Slider.new (x, y, width, height, value, min_value, max_value, markers, direction)
Create a new slider x and y are the coordinates where the slider will be drawn: numbers width and height are the width and height of the slider: numbers value is the desired starting value: number min_value and max_value are the minimum and maximum values respectively, by which value is clamped: numbers markers are reference markers along the slider: table of floats or integers direction is the direction in which the slider moves, defaults to up: up, down, left or right
my_slider:set_value (number)
Set value : number
my_slider:set_value_delta (delta)
Set value using delta : number
my_slider:set_marker_position (id, position)
Set marker positions : number
my_slider:redraw ()
Redraw slider
variables
Syntax
Description
my_slider.x
Originating x-coordinate : number
my_slider.y
Originating y-coordinate : number
my_slider.width
Width : number
my_slider.height
Height : number
my_slider.value
Slider’s current value : number
my_slider.min_value
Slider’s minimum value : number
my_slider.max_value
Slider’s maximum value : number
my_slider.markers
Marker positions : table
my_slider.direction
Slider’s direction : string
my_slider.active
Slider’s active state : boolean
example
UI=require("ui")slider={}-- create 4 sliders:slider[1]=UI.Slider.new(5,10,5,50,30,0,127,{0},"down")slider[2]=UI.Slider.new(15,10,50,5,97,0,127,{},"right")slider[3]=UI.Slider.new(40,55,50,5,72,0,127,{72},"left")slider[4]=UI.Slider.new(100,10,5,50,72,0,127,{0,32,64,96,127})-- set fourth slider to inactive:slider[4].active=false-- label slidersslider[1].label="L"slider[2].label="R"slider[3].label="freq"slider[4].label="res"functionredraw()screen.clear()-- sliders need to be redrawn to display:fori=1,4doslider[i]:redraw()endscreen.level(15)screen.move(slider[1].x,slider[1].y-2)-- relative positioning using the originating x and y coordinatesscreen.text(slider[1].label)fori=2,4do-- another way to position labelsscreen.move(slider[i].x,slider[i].y-2)screen.text(slider[i].label)endscreen.move(42,28)screen.text("k2: pan")screen.move(42,37)screen.text("k3: lpf")screen.update()endfunctionkey(n,z)-- manipulating slider states + values:ifn==3andz==1thenslider[3].active=notslider[3].activeslider[4].active=notslider[3].activeelseifn==2thenslider[1]:set_value(z==1and97or30)slider[2]:set_value(z==1and30or97)endredraw()endfunctionenc(n,d)-- adjusting slider + marker values:ifn==3thenifslider[3].activethenslider[3]:set_value_delta(d)slider[3]:set_marker_position(1,slider[3].value)elseslider[4]:set_value_delta(d)endredraw()endend
description
Draws a slider on the screen from the specified (x, y) pair. Width and height can extend beyond the screen’s bounds. Value is clamped to the slider’s min and max values and can be changed by direct assignment or incremental adjustment. Reference markers can be added, in the form of a table of floats or integers. Direction defaults to “up” if it is not specified.