4

How can I dynamically change the appearance of b? Strangely it works for the Enabled state but not for the Appearance.

Thanks.

Manipulate[
  bAppearance = If[a > 1, "Open", "Closed"]; 
  bEnabled = If[a > 2, False, True];
  Plot[Sin[a x + b], 
  {x, 0, 6}], {a, 1, 4}, {b, 0, 10, Appearance -> Dynamic@bAppearance}]
dabd
  • 839
  • 4
  • 13

3 Answers3

2

You can change the appearance of most controls, but the Manipulator Control has something in it that prevents its dynamic behavior (a bug or a feature ?).

Look (with a slider):

Manipulate[
 {Dynamic@a, Plot[Sin[a x + b], {x, 0, 6}]},
 {a, 1, 4},
 {b, 0, 1, ControlType -> Slider, 
  Appearance -> Dynamic[If[a > 1, {Tiny}, {Large}]]}]

enter image description here

Now the same with a Manipulator (showing it doesn't work):

Manipulate[
 {Dynamic@a, Plot[Sin[a x + b], {x, 0, 6}]},
 {a, 1, 4},
 {b, 0, 1, ControlType -> Manipulator, 
  Appearance -> Dynamic[If[a > 1, {Tiny}, {Large}]]}]

enter image description here

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Interesting, but the problem is that the Sliders don't have an "Open", "Closed" state and I am using Manipulators for that reason. I would like the users to be able to input a value directly. – dabd May 03 '13 at 15:47
  • @dabd I know. I'm trying to tell you that that isn't going to work easily – Dr. belisarius May 03 '13 at 15:50
1

Here's one approach, perhaps not as straightforward as might be hoped for but it works:

Manipulate[
 Plot[Sin[a x + b], {x, 0, 6}],

 {a, 1, 4},

 Row@List@With[{choice = Dynamic[If[a < 2, 1, 2]]},
    Overlay[{
      Control[{b, 0, 1, Appearance -> "Closed"}],
      Control[{b, 0, 1, Appearance -> "Open"}]},
     {choice}, choice]]]

Also take a look at the ImageSize settings for Overlay, if the switching has resizing issues.

Edit Oops. We can just do it this way:

Manipulate[
 Plot[Sin[a x + b], {x, 0, 6}],

 {a, 1, 4},

 Row@List@Dynamic[If[a < 2,
     Control[{b, 0, 1, Appearance -> "Closed"}],
     Control[{b, 0, 1, Appearance -> "Open"}]]]]
amr
  • 5,487
  • 1
  • 22
  • 32
1

Here's one way around it -- make the Manipulator dynamic:

Manipulate[
 bAppearance = If[a > 1, "Open", "Closed"];
 bEnabled = If[a > 2, False, True];
 Plot[Sin[a x + b], {x, 0, 6}],
 {a, 1, 4}, {b, 0, 10, Dynamic@Manipulator[##, Appearance -> bAppearance] &}]

The Manipulator is recreated when bAppearance changes. It won't be recreated when b changes because b will be wrapped in Dynamic when the control is created.

Michael E2
  • 235,386
  • 17
  • 334
  • 747