5
$\begingroup$

Is it possible to use Manipulate and Switch to change the Manipulate controls?

Manipulate[Module[{...variables...},
  Switch[type,
    1,
    controls = ...,
    2,
    controls = ...]],
  controls]

Where Manipulate controls would be different for each type.

$\endgroup$
14
$\begingroup$

There are various viewers available that could used to switch between different arrangements of controls. For a seamless look, one might use PaneSelector. If type is to have its own control, putting it inside each of the panes ensures Manipulate will align them.

Manipulate[
 {x, yyy},
 {{x, a}, {a, b, c, d}, None},
 {{yyy, 0.5}, 0, 1, None},
 {{type, 1}, Range@3, None},
 PaneSelector[{
   1 -> Column[{
      Control@{x, {a, b, c, d}, RadioButtonBar},
      Control@{{yyy, 0.5}, 0, 1},
      Control@{type, Range@3}
      }],
   2 -> Column[{
      Control@{x, {a, b, c, d}, SetterBar},
      Control@{yyy},
      Control@{type, Range@3}
      }],
   3 -> Column[{
      Control@{x, {a, b, c, d}, PopupMenu},
      Control@{{yyy, 0.5}, 0, 1},
      Control@{type, Range@3}
      }]
   }, Dynamic@type]     
]

enter image description here


Comment: Your question suggests you might be seeking rather fine control over the UI. It might be easier in the long run to build it from the ground up with DynamicModule and the various user interface features Mathematica offers.

$\endgroup$
3
$\begingroup$
Manipulate[

 Which[
  typeSelected == 1,Row[{"you selected type 1 UI with input h = ", h}],
  typeSelected == 2,Row[{"you selected type 2 UI with input mass = ", m}],
  True, "No way ! Please report a bug"]
 ,

 Grid[{
   {Style["A self modifying dynamic Manipulate UI" , 10], SpanFromLeft},

   {"Which UI would you like to see?", 
    TabView[{
      {1,"type 1" ->Row[{"h? ", SetterBar[Dynamic[h, {h = #} &], {0, 1, 2}]}]},
      {2,"type 2" -> Row[{"mass= ",Manipulator[Dynamic[m, {m = #} &], {0, 100, 1}], 
          Dynamic[m]}]}
      }, Dynamic[typeSelected]
     ]
    }
   }, Frame -> All, Spacings -> .5, FrameStyle -> Gray],

 {{h, 1}, None},
 {{m, 4}, None},
 {{typeSelected, 1}, None},
 TrackedSymbols :> {h, m, typeSelected}     
 ]

Mathematica graphics Mathematica graphics

$\endgroup$
2
$\begingroup$

Using the command

 ControlType ->

and then listing the type of control you want, such as SetterBar, Manipulator, or Slider at the end of your Manipulate function allows you to customize the controls. Mathematica will also automatically change the control based on the data put in (i.e., if you put in code like this {frame, {True, False}} it will give a checkbox).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.