Page 1 of 1

Programatically add UI elements

Posted: 07 Apr 2017, 18:51
by markjc
I am working on a robot that will have a variable amount of joints at runtime. I would like to have a UI that has once slider per joint to control position. I know I can make a static UI that will have a fixed number of sliders. Is there a way to dynamically create UI elements at runtime depending on the number of joints I have?

Re: Programatically add UI elements

Posted: 10 Apr 2017, 08:26
by coppelia
Hello,

yes, you can easily do this with the new custom UI functionality. For example:

Code: Select all

    local xml='<ui title="MyJoints">'
    for i=1,#allJoints,1 do
        xml=xml..'<hslider minimum="-180" maximum="180" onchange="sliderChange_callback" id="'..i..'"/>'
    end
    xml=xml..'</ui>'
    myUi=simExtCustomUI_create(xml)
and the function that will be called when a slider is moved:

Code: Select all

sliderChange_callback=function(ui,id,value)
    print("My slider "..id.."just moved!")
end
Cheers