SelectionBox — Scrollable list selection
SelectionBox
( | string | label , |
list | items
) ; |
make the widget very small
make `notify trigger immediately when the selected item changes
The label above the list describing what it is all about
The currently selected item or its ID, if it has one.
A selection box offers the user to select an item out of a list. Each item has a label and an optional id. When constructing the list of items, you have two way of specifying an item. Either you give a plain string, in which case the string is used both for the id and the label of the item. Or you specify a term `item( term id, string label ) or `item( term id, string label, boolean selected ), where you give an id of the form `id( any v ) where you can store an aribtrary value as id. The third argument controls whether the item is the selected item.
`SelectionBox( `id( `pizza ), "select your Pizza:", [ "Margarita", `item( `id( `na ), "Napoli" ) ] ) |
{ UI::OpenDialog( `VBox( `SelectionBox( "Select your Pizza:", [ "Napoli", "Funghi", "Salami" ] ), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } |
{ // Create a selection box with three entries. // All entries have IDs to identify them independent of locale // (The texts might have to be translated!). // Entry "Funghi" will be selected by default. UI::OpenDialog( `VBox( `SelectionBox(`id(`pizza), "Select your Pizza:", [ `item(`id(`nap), "Napoli" ), `item(`id(`fun), "Funghi", true ), `item(`id(`sal), "Salami" ) ] ), `PushButton("&OK") ) ); UI::UserInput(); // Get the input from the selection box. // // 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. any pizza = UI::QueryWidget(`id(`pizza), `CurrentItem); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Evaluate selection string toppings = "nothing"; if ( pizza == `nap ) toppings = "Tomatoes, Cheese"; else if ( pizza == `fun ) toppings = "Tomatoes, Cheese, Mushrooms"; else if ( pizza == `sal ) toppings = "Tomatoes, Cheese, Sausage"; // Pop up a new dialog to echo the selection. UI::OpenDialog( `VBox( `Label("You will get a pizza with:"), `Label(toppings), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } |
{ // Create a selection box with three entries. // All entries have IDs to identify them independent of locale // (The texts might have to be translated!). // Entry "Funghi" will be selected by default. // // There are two buttons to select a "Today's special" and a // "veggie" pizza to demonstrate how to select list entries // programmatically. UI::OpenDialog( `VBox( `SelectionBox(`id(`pizza), "Select your Pizza:", [ `item(`id(`nap), "Napoli" ), `item(`id(`fun), "Funghi", true ), `item(`id(`sal), "Salami" ) ] ), `HBox( `PushButton(`id(`todays_special), `opt(`hstretch), "&Today's special" ), `PushButton(`id(`veggie), `opt(`hstretch), "&Veggie" ) ), `PushButton(`id(`ok), `opt(`default), "&OK") ) ); any id = nil; repeat { id = UI::UserInput(); if ( id == `todays_special ) UI::ChangeWidget( `id( `pizza ), `CurrentItem, `nap ); else if ( id == `veggie ) UI::ChangeWidget( `id( `pizza ), `CurrentItem, `fun ); } until ( id == `ok ); // Get the input from the selection box. // // 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. any pizza = UI::QueryWidget(`id(`pizza), `CurrentItem); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Evaluate selection string toppings = "nothing"; if ( pizza == `nap ) toppings = "Tomatoes, Cheese"; else if ( pizza == `fun ) toppings = "Tomatoes, Cheese, Mushrooms"; else if ( pizza == `sal ) toppings = "Tomatoes, Cheese, Sausage"; // Pop up a new dialog to echo the selection. UI::OpenDialog( `VBox( `Label("You will get a pizza with:"), `Label(toppings), `PushButton(`opt(`default), "&OK") ) ); UI::UserInput(); UI::CloseDialog(); } |
{ // Create a selection box with three entries. // All entries have IDs to identify them independent of locale // (The texts might have to be translated!). // Entry "Funghi" will be selected by default. // // There are two buttons to select a "Today's special" and a // "veggie" pizza to demonstrate how to select list entries // from within a YCP script - even without having to use item IDs. UI::OpenDialog( `VBox( `SelectionBox(`id(`pizza), "Select your Pizza:", [ "Napoli", "Funghi", "Salami", "Quattro Stagioni (a pizza which is devided into 4 parts each with a different topping)", "Caprese", "Speciale", "Hawaii" ] ), `HBox( `PushButton(`id(`todays_special), `opt(`hstretch), "&Today's special" ), `PushButton(`id(`veggie), `opt(`hstretch), "&Veggie" ) ), `PushButton(`id(`ok), `opt(`default), "&OK") ) ); any id = nil; repeat { id = UI::UserInput(); if ( id == `todays_special ) UI::ChangeWidget( `id( `pizza ), `CurrentItem, "Napoli" ); else if ( id == `veggie ) UI::ChangeWidget( `id( `pizza ), `CurrentItem, "Funghi" ); } until ( id == `ok ); // Get the input from the selection box. // // 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. string pizza = (string) UI::QueryWidget(`id(`pizza), `CurrentItem); // Close the dialog. // Remember to read values from the dialog's widgets BEFORE closing it! UI::CloseDialog(); // Pop up a new dialog to echo the selection. UI::OpenDialog( `VBox( `Label("Pizza " + pizza + " coming right up"), `PushButton(`opt(`default), "&OK") ) ); UI::UserInput(); UI::CloseDialog(); } |