Table — Multicolumn table widget
Table
( | term | header , |
list | items
) ; |
make `notify trigger immediately when the selected item changes
keep the insertion order - don't let the user sort manually by clicking
the ID of the currently selected item
a list of all table items
read: a single item ( string or term )
write: replacement for one specific cell ( see example )
A Table widget is a generalization of the SelectionBox. Information is displayed in a number of columns. Each column has a header. The number of columns and their titles are described by the first argument, which is a term with the symbol header. For each column you add a string specifying its title. For example `header( "Name", "Price" ) creates the two columns "Name" and "Price".
The second argument is an optional list of items ( rows ) that are inserted in the table. Each item has the form `item( `id( id ), first column, second column, ... ). For each column one argument has to be specified, which must be of type void, string or integer. Strings are being left justified, integer right and a nil denote an empty cell, just as the empty string.
{ UI::OpenDialog( `VBox( `Label("Today's menu"), `Table( `header("Name", "Price"), [ `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil), `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12) ] ), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } |
{ UI::OpenDialog( `VBox( `Label("Today's menu"), `HSpacing(40), // make the table and thus the dialog wider `HBox( `VSpacing(10), // make the table higher `Table( `id(`table), `opt(`keepSorting), `header("Name", `Right("Price"), `Center("Rating")), [ `item(`id(0), "Steak Sandwich", 12, "+++"), `item(`id(1), "Salami Baguette", nil, "-" ), `item(`id(2), "Chili", 6, "--" ), `item(`id(3), "Spaghetti", 8, "+" ) ] ) ), `HBox( `HCenter(`PushButton(`id(`next), "&Next")), `PushButton(`id(`cancel), "&Close") ) ) ); UI::ChangeWidget(`id(`table), `CurrentItem, 2); while (UI::UserInput() != `cancel) { UI::ChangeWidget(`id(`table), `CurrentItem, ((integer) UI::QueryWidget(`id(`table), `CurrentItem) + 1) % 4); } UI::CloseDialog(); } |
{ list itemlist1 = [ `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12), `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil) ]; list itemlist2 = [ `item(`id(0), "Mercedes", 60000), `item(`id(1), "AUDI", 50000), `item(`id(2), "VW", 40000), `item(`id(3), "BMW", 60000), `item(`id(3), "Porsche", 80000) ]; list itemslists = [ itemlist1, itemlist2 ]; integer listnum = 0; UI::OpenDialog( `VBox( `Label("Prices"), `HSpacing(40), // make the table and thus the dialog wide enough `HBox( `VSpacing(10), `Table(`id(`table), `header("Name", "price"), itemlist1) ), `HBox( `HCenter(`PushButton(`id(`next), "Change &Table Contents")), `PushButton(`id(`cancel), "&Close") ) ) ); while (UI::UserInput() != `cancel) { listnum = 1 - listnum; UI::ChangeWidget(`id(`table), `Items, select(itemslists, listnum, nil)); } UI::CloseDialog(); } |
{ UI::OpenDialog( `VBox( `Label("Today's menu"), `HSpacing(40), // make the table and thus the dialog wider `HBox( `VSpacing(10), // make the table higher `Table(`id(`table), `header("Name", "Price"), [ `item(`id(1), "Chili", 6), `item(`id(2), "Salami Baguette", nil), `item(`id(3), "Spaghetti", 8), `item(`id(4), "Steak Sandwich", 12) ] ) ), `HBox( `HCenter(`PushButton("&Lookup")), `PushButton(`id(`cancel), "&Close" ) ) ) ); while (UI::UserInput() != `cancel) { any id = UI::QueryWidget(`id(`table), `CurrentItem); if (is(id, integer)) { string text = sformat("Line: %1", UI::QueryWidget(`id(`table), `Item(id))); UI::OpenDialog( `VBox( `Label(text), `PushButton("&OK") ) ); UI::UserInput(); UI::CloseDialog(); } } UI::CloseDialog(); } |
{ UI::OpenDialog( `VBox( `HSpacing(50), // make the dialog wider `Label("Double-click any item to increase the number."), `HBox( `VSpacing(10), // make the table higher `Table(`id(`table), `opt(`notify), `header("Name", "Amount"), [ `item(`id(1), "Chili", 0), `item(`id(2), "Salami Baguette", 0), `item(`id(3), "Spaghetti", 0), `item(`id(4), "Steak Sandwich", 0) ] ) ), `PushButton(`id(`cancel), "&Close") ) ); while ( UI::UserInput() != `cancel) { integer current_item = (integer) UI::QueryWidget(`id(`table), `CurrentItem); integer current_value = tointeger(select((list) UI::QueryWidget(`id(`table), `Item(current_item)), 2, 1)); UI::ChangeWidget(`id(`table), `Item(current_item, 1), current_value+1); } UI::CloseDialog(); } |