#include <ugadgets.hpp>
Public Member Functions | |
UListbox (const UArgs &a=UArgs::none) | |
virtual const UStyle & | getStyle (UContext *) const |
UChoice & | choice () const |
UListbox & | addItem (UStr *) |
UListbox & | addItems (const std::vector< UStr * > &str_list) |
UListbox & | addItems (const UArgs &item_prefix, const std::vector< UStr * > &str_list) |
UStr strings are *NOT* duplicated and should not be destroyed. | |
UListbox & | addItem (const char *) |
UListbox & | addItems (const char *string_list[]) |
UListbox & | addItems (const UArgs &item_prefix, const char *string_list[]) |
char* strings are duplicated and can be destroyed. | |
Static Public Member Functions | |
static const UStyle & | makeStyle () |
Static Public Attributes | |
static UStyle * | style = null |
Protected Member Functions | |
virtual void | mouseCB (UEvent &) |
Protected Attributes | |
uptr< class UChoice > | pchoice |
uptr< UCall > | callbacks |
Friends | |
UListbox & | ulistbox (const UArgs &a=UArgs::none) |
Vertical (or horizontal) list of selectable gadgets.
A listbox gadget can contain any brick but only ARMable gadgets (UItem, UButton, UCheckbox...) will be *selectable*. Use UItem children to obtain the usual appearance of a list gadget. Strings that are directly added to the listbox are visible but cant be seletecd.
Listbox children (for instance selectable UItem children) can contain an arbitrary combination of text, images, gadgets...
Geometry:
Default Properties:
Selection management:
Exemple:
XXX* obj = ...; UListbox& list = ulistbox ( ulabel("title") // can't be selected + uitem("first item") + uitem("second item") + uitem(UPix::right + "third" + " item" + ubutton(...)) + UOn::action / ucall(obj, &XXX::foo) + UOn::select / ucall(obj, &XXX::foo) );
list.add(uitem("4th item"));
UGroup* item = list.choice().getItem()); // returns the selected item int index = list.choice().getIndex()) // returns the index of the selected item
Callbacks: as for other UBox subclasses generic callback conditions make it possible to specify callback methods and functions: see class UCond. For instance:
void XXX::foo(UEvent& e) { // getSource() returns the listbox UListbox* list = e.getSource() ? dynamic_cast<UListbox*>(e.getSource()) : null;
if (list) { UGroup* item = list->choice().getItem()); // returns the selected item int index = list->choice().getIndex()) // returns the index of the selected item }
// getTarget() returns the selected item (same as list->choice().getItem()) if (e.getTarget()) { // collates the text that is enclosed in the item and copies it to 's' UStr s = e.getTarget()->copyText(); } }