Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can TogglerBar be used as multiple CheckBox in Mathematica?

Would it be possible to have a TogglerBar instead of the 2 Check Box to show or not the different Shapes.

With Green & Red written in each Button of the TogglerBar ?

Manipulate[
Graphics[{If[thePink, {Pink, Disk[{5, 5}, 3]}], 
If[theGreen, {Green, Disk[{15, 2}, 1]}]}, 
PlotRange -> {{0, 20}, {0, 10}}], {{thePink, True, 
Style["Pink", Black, Bold, 12]}, {True, False}}, {{theGreen, True, 
Style["Green", Black, Bold, 12]}, {True, False}}]

enter image description here

The actual Manipulate object I am trying to adjust can be found there : http://www.laeh500.com/LAEH/COG.html The purpose being to replace the CheckBox by a nice TogglerBar.

like image 211
500 Avatar asked Jan 28 '26 12:01

500


1 Answers

Like this?

Manipulate[
 Graphics[{
   {White, Circle[{5, 5}, r]},  (* For Mma 7 compatibility*) 
   If[MemberQ[color, "Red"],   {Pink, Disk[{5, 5}, r]}],
   If[MemberQ[color, "Green"], {Green, Disk[{4, 2}, r]}]},
 PlotRange -> {{0, 20}, {0, 10}}],
 {{r, 1, "Radius"}, 1, 5, 1, ControlType -> Setter},
 {{color, "Red", "Color"}, {"Red", "Green"}, ControlType -> TogglerBar}, 
LabelStyle -> Large]

enter image description here

Edit

Answering your comment, I think your notebook could benefit from a template like this one:

Manipulate[
 Graphics[
  {
   {White, Circle[{5, 5}, r]},(* For Mma 7 compatibility*) 
   If[MemberQ[whatToDisplay, "Circle"], {Red,   Circle   [{5, 5}, r]}],
   If[MemberQ[whatToDisplay, "Square"], {Blue,  Rectangle[{5, 5}, {r, r}]}],
   If[MemberQ[whatToDisplay, "Other"],  {Black, Line     [Tuples[{3, 4}, 2]]}],
  },
 PlotRange -> {{0, 20}, {0, 10}}
 ], 
  (* Controls follow *)
  {{r, 1,  Style["Radius", Black, Bold, 12]}, 1, 5, 1, ControlType     -> Slider
                                                     , ControlPlacement-> Top
  },  
  Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]}, 
           {"Circle", "Square", "Other"}, 
           ControlType      -> TogglerBar,
           Appearance       -> "Vertical",
           ControlPlacement -> Left
  }
]

enter image description here

like image 138
Dr. belisarius Avatar answered Jan 30 '26 03:01

Dr. belisarius