I am using Leonid's macro method (see here) to help me manage the control variables layout of Manipulate
.
But I found that from within a macro, I am not able to use another macro defined elsewhere. So I am wondering if there is a way to use a macro from within another macro?
To explain the question, I will first show a very simple Manipulate using a one level macro, then I will show the problem, by trying to use a macro from within another.
Manipulate[Text["ok"],
Evaluate@With[{
x = Function[{}, (*----> macro x *)
TabView[{
"x" -> "working on x"
}], HoldAll
],
y = Function[{}, (*----> macro y *)
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
(* now use the above macros *)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
ContentSize -> 300
]
Now add a macro for a checkbox, and then try to use it from inside the 'x' macro above:
Manipulate[Text["ok"],
Evaluate@With[{
checkBox = Function[{}, Checkbox[Dynamic[c]], HoldAll],
x = Function[{},
TabView[{
"x" -> checkBox[] (*=====> DOES NOT WORK, did not bind *)
}], HoldAll
],
y = Function[{},
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
{{c, True}, None},
ContentSize -> 300
]
We see it did not work. The 'x' macro did not 'see' the checkbox macro.
But if I add the code for the checkbox directly inside the 'x' macro, it will of course work:
Manipulate[Text["ok"],
Evaluate@With[{
x = Function[{},
TabView[{
"x" -> Checkbox[Dynamic[c]] (* add the definition directly *)
}], HoldAll
],
y = Function[{},
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
{{c, True}, None},
ContentSize -> 300
]
So, the question is: Is it possible to use the checkbox macro above from inside the 'x' macro?
To make it is easier, I am NOT passing any arguments to the macros. I am simply using a macro as a 'short hand' name for a piece of larger code fragment (the control variable definition) as shown above.
This is only to make it easier for me to layout the UI by moving only the macro name around, instead of moving the larger piece of code which the macro defines. Since there is no GUI builder for Manipulate, this method helps when one has lots of controls to manage.