class ui.item.radiobutton
Contract
Parameter keyDefault valueType
nameoptstring
labelnullstring
xactive_valuenonnegative
yactive_valuenonnegative
widthactive_valuenonnegative
heightactive_valuenonnegative
foreground_colorblackcolor
background_colorwhitecolor
visibilityactive_valueboolean
tool_tipnulltype.<one_of string/>
the_valueactive_valueboolean
clickoptmethod
group"default_group"string
Water Contract
<class ui.item.radiobutton
  name          =opt=string
  label         =null=string
  the_value     =<active_value></active_value>=boolean
  click         =opt=method
  group         ="default_group"
/>
radiobuttons let a user pick one of a few values. Each radiobutton represents a possible value.
<set R =
       ui.<row>
        ui.<radiobutton name="yellow"/>
        ui.<radiobutton name="orange"/>
        ui.<radiobutton name="red"/>
       </row>
     />
ui.<window name="mywin"> null R </>
R.yellow.the_value
false
the_value defaults to false but can be initialized or set programmatically as well as manually.
ui.<window name="mywin"> null
  ui.<row>
   ui.<radiobutton name="yellow"/>
   ui.<radiobutton name="orange" the_value=true/>
   ui.<radiobutton name="red"/>
  </row>
</window>
<set R=ui.mywin.center/>
R.orange.the_value <!-- returns true -->
R.yellow.<set the_value=true/>
R.orange.the_value <!-- returns false -->
R.yellow.the_value <!-- returns true -->
Each radiobutton belongs to a group. Only one radiobutton within a group can be selected, which means that the value of its 'the_value' field is true. The radiobuttons within a group need not be spatially related, though its confusing to a user if they aren't adjacent. If you only have one radiobutton group, you needn't supply a group value to any of your radiobuttons as they will default to the group "default_group". But to guard against future additions, it is recommended that you give each radiobutton a group. You don't need to create radiobutton groups. You can use any object to be a group, it just needs to be unique amongst the group names. Conventionally a string is used to designate a group.
ui.<window name="mywin"> null
 ui.<column>
  ui.<row name="r1">
   ui.<label name="COLOR:"/>
   ui.<radiobutton name="yellow" group="color"/>
   ui.<radiobutton name="orange" group="color" the_value=true/>
   ui.<radiobutton name="red"    group="color"/>
  </row>
  ui.<row name="r2"> 
   ui.<label name="SIZE:"/>
   ui.<radiobutton name="small"  group="size"/>
   ui.<radiobutton name="medium" group="size" the_value=true/>
   ui.<radiobutton name="large"  group="size"/>
  </row>
 </column>
</window>
radiobuttons work in menus as well. When you click on a readiobutton that's in a menu, the menu stays expanded so you can verify that your click worked. Clich outside the menu to get the menu to shrink.
ui.<window name="mywin"> null
 ui.<menubar>
  ui.<menu name="Options">
    ui.<radiobutton name="yes"   group="g0"/> 
    ui.<radiobutton name="maybe" group="g0"/>
    ui.<radiobutton name="no"    group="g0" the_value=true/>
    ui.<separator/>
    ui.<radiobutton name="remember" group="g1"/> 
    ui.<radiobutton name="forget"   group="g1" the_value=true/>
  </menu>
</menubar>
  </window>
To determine which radiobutton within a group is selected, you can test each radiobutton in the group for a value of 'the_value' of true. You can also set a click method that sets some variable to the name of the selected radiobutton. A more convenient way is to ask the group. radiobuttons have a number of group operations to make manipulating them much less of a chore than in other languages. Given the ui created in the above example:
ui.radiobutton.groups <!--an object whose field keys are the names of groups
                               and whose values are a vector of the radiobuttons
                               in the group. -->
ui.radiobutton.groups.g0 <!-- a vector of the yes, maybe, and no radiobuttons -->
ui.radiobutton.groups.g0.<length/> <!-- the number of radiobuttons in the group. -->
ui.radiobutton.groups.g0.0.name <!-- "yes" -->
ui.radiobutton.<selected_radiobutton_in_group "g0"/> <!-- returns the selected radiobutton -->
The relationship between radiobuttons and their groups can be dynamically programmed. This is not a normal thing to do but can be useful in very dynamic user interfaces. Note that changing the group of a button does not affect its visibility or location on the screen.
Example: removes a radiobutton from its group
ui.<radiobutton name="black"/>.<remove_radiobutton_from_group/>
Example: removes the subject radiobutton from its group and adds it to the given group
ui.<radiobutton name="green"/>.<add_radiobutton_to_group "color"/>
removes each radiobutton in the group making it groupless, then gets rid of the whole group.
ui.radiobutton.<remove_group "color"/>
Example: calls remove_group on every radiobutton group
ui.radiobutton.<remove_all_groups/>