CheckBox — Clickable on/off toggle button
CheckBox
( | string label , |
boolean|nil
checked
) ; |
checked
whether the check box should start checked - nil means tristate condition, i.e. neither on nor off
A checkbox widget has two states: Checked and not checked. It returns no user input but you can query and change its state via the Value
property.
{ UI::OpenDialog( `CheckBox("A &checked check box\nwith multi-line", true) ); UI::UserInput(); UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `Label("Select your extras"), `Left(`CheckBox(`id(`cheese), "Extra Cheese")), `Left(`CheckBox(`id(`pepr), "Pepperoni", true)), `PushButton("&OK") ) ); UI::UserInput(); boolean cheese = (boolean) UI::QueryWidget(`cheese, `Value); boolean pepr = (boolean) UI::QueryWidget(`pepr, `Value); UI::CloseDialog(); define string yesno(boolean b) ``{ if (b) return "yes"; else return "no"; }; UI::OpenDialog( `VBox( `Left(`Label("Extra Cheese: " + yesno(cheese))), `Left(`Label("Pepperoni: " + yesno(pepr))), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ // Build dialog with one check box and buttons to set its state to // on, off or "don't care" (tri-state). UI::OpenDialog( `VBox( `CheckBox(`id(`cb), "Format hard disk"), `HBox( `HWeight(1, `PushButton(`id(`setOn ), "Set on" ) ), `HWeight(1, `PushButton(`id(`setOff), "Set off" ) ), `HWeight(1, `PushButton(`id(`dontCare), "Don't care" ) ) ), `PushButton(`id(`ok), "&OK") ) ); // Input loop. Will be left only after 'OK' is clicked. any button = nil; repeat { button = UI::UserInput(); if ( button == `setOn ) UI::ChangeWidget ( `id(`cb), `Value, true ); else if ( button == `setOff ) UI::ChangeWidget ( `id(`cb), `Value, false ); else if ( button == `dontCare ) UI::ChangeWidget ( `id(`cb), `Value, nil ); } until ( button == `ok ); // Get the check box's value. // // Notice: The return value of UI::UserInput() does NOT return this value! // Rather, it returns the ID of the widget (normally the PushButton) // that caused UI::UserInput() to return. boolean cb_val = (boolean) UI::QueryWidget(`id(`cb), `Value); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Convert the check box value to string. string valStr = "Don't care"; if ( cb_val == true ) valStr = "Yes"; if ( cb_val == false ) valStr = "No"; // Pop up a new dialog to echo the input. UI::OpenDialog( `VBox( `Label("Your selection:"), `Label(valStr), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }
{ UI::OpenDialog( `VBox( `Label("Select your extras"), `Left(`CheckBox(`id(`cheese), "Extra Cheese")), `Left(`CheckBox(`id(`pepr), "Pepperoni", true)), `Left(`CheckBox(`id(`salami), `opt(`boldFont), "Extra Salami")), `PushButton("&OK") ) ); UI::UserInput(); boolean cheese = (boolean) UI::QueryWidget(`cheese, `Value); boolean pepr = (boolean) UI::QueryWidget(`pepr, `Value); boolean salami = (boolean) UI::QueryWidget(`salami, `Value); UI::CloseDialog(); define string yesno(boolean b) ``{ if (b) return "yes"; else return "no"; }; UI::OpenDialog( `VBox( `Left(`Label("Extra Cheese: " + yesno(cheese))), `Left(`Label("Pepperoni: " + yesno(pepr))), `Left(`Label("Extra Salami: " + yesno(salami))), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); }