parameters menu

Tired to have to add/hide/change parameters or navigate throught a big list of them, here is a small util to build nested menus from parameters : http://twolivesleft.com/Codea/CC/alpha/index.php?v=1367. Any feedbacks and ideas are welcome.

Cool.

@toffer I tried your code, but it cancels when I’m in the square and I slide the side above 200. I was going to fix it, but I couldn’t figure out the code. I don’t know if it’s the way it’s formatted or that it’s filled with comments or what’s going on.

@dave1707 what do you mean by cancels ? Also, my menu example is really stupid :s

@toffer It totally blows me out of Codea, so I’m not sure what’s happening. It does it every time I move the square side to 200. I know the line of code causing the problem, but I tried reformatting your code to make it easier to read, but no luck. Lot of stuff in tables, but I’m not sure what I need to change yet. Maybe it’s just me, but I like simple code. Here’s some code I had already written a while back. I modified it to resemble what you showed. I’m going to keep a copy of your code because it interest me. I’m going to look at it more tomorrow when I have more time and see if I can get comfortable with what’s going on. Maybe once I understand it, I’ll see why it cancels on my iPad1.


function setup()
    mainPar()
end

function draw()
    background(40, 40, 50)
    if circ then
        fill(col)
        ellipse(300,500,rad)
    end
    if sqr then
        fill(col)
        rect(300,500,side,side)
    end
    if ell then
        fill(col)
        ellipse(300,500,rad1,rad2)
    end
end

function mainPar()
    circ=false
    sqr=false
    ell=false
    parameter.clear()
    parameter.action("circle",cir)
    parameter.action("square",squr)
    parameter.action("ellipse",ellip)
end

function cir()
    circ=true
    parameter.clear()
    parameter.action("Back to Main Menu",mainPar)
    parameter.text("Circle","Slide rad to change radius")
    parameter.integer("rad",1,200,50)
    parameter.color("col",255)
end

function squr()
    sqr=true
    rectMode(CENTER)
    parameter.clear()
    parameter.action("Back to Main Menu",mainPar)
    parameter.text("Square","Slide side to change side")
    parameter.integer("side",1,300,50)
    parameter.color("col",255)
end

function ellip()
    ell=true
    parameter.clear()
    parameter.action("Back to Main Menu",mainPar)
    parameter.text("Ellipse","Slide rad1 or rad2 to change size")
    parameter.integer("rad1",1,200,50)
    parameter.integer("rad2",1,200,100)
    parameter.color("col",255)
end

@toffer everytime I move the square slider past 200 the menu options change.

@Briarfox it’s normal, my stupid example, look at line 24-26 (Main tab) in the callback, the lock_xy parameter visibility is mapped to slider value (<200 visible, >200 hidden), that was just to demonstrate menu handling inside callbacks.

@dave1707 - I’ve try to convert your example. Now I see it miss an enter menu callback. Also, It look like the descriptor syntax is a bit hard, maybe I should think another one.


--# Main
local menu = {
    "circle","square","ellipse"
    ,circle = {
        "Circle","rad","col",
        function()
            circ=true sqr=false ell=false
        end
        ,Circle = { "text","Slide rad to change radius" }
        ,rad =    { "integer",1,200,50 }
        ,col =    { "color",255 }
    }
    ,square = {
        "Square","side","col",
        function()
            sqr=true circ=false ell=false
        end
        ,Square = { "text","Slide side to change side" }
        ,side =   { "integer",1,300,50 }
        ,col =    { "color",255 }
    }
    ,ellipse = {
        "Ellipse","rad1","rad2","col",
        function()
            ell=true circ=false sqr=false
        end
        ,Ellispe = { "text", "Slide rad1 or rad2 to change size" }
        ,rad1 =    { "integer",1,200,50 }
        ,rad2 =    { "integer",1,200,100 }
        ,col =     { "color",255 }
    }
}

function setup()
    parameter.menu(menu):draw()
end

function draw()
    background(40, 40, 50)
    if circ then
        fill(col)
        ellipse(300,500,rad)
    end
    if sqr then
        fill(col)
        rect(300,500,side,side)
    end
    if ell then
        fill(col)
        ellipse(300,500,rad1,rad2)
    end
end

@toffer The above code is a lot easier to read than the original one. That should make it easier to understand how your code works. It also looks like it would be easier to make additions and modifications to it. I find it very interesting, it’s different, nice example. I also had to copy the original parameters_menu to include with the above code.