Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

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.

share|improve this answer
add comment
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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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