ubit::UListbox Class Reference

"classical" List widget. More...

#include <ulistbox.hpp>

Inheritance diagram for ubit::UListbox:

ubit::UBox ubit::UGroup ubit::UControl ubit::UBrick ubit::UObject List of all members.

Public Member Functions

 UListbox (const UArgs &args=UArgs::none)
 creates a new List widget.
bool isTransparent () const
UListbox & setTransparent (bool s=true)
UChoice & choice ()
const UChoice & choice () const
 the object that controls the selection in the listbox.
virtual UBox * getSelectedItem () const
 returns the selected item; null if there is no selected item.
virtual void setSelectedItem (UBox &)
 selects this item.
virtual int getSelectedIndex () const
 returns the index of the selected item; -1 if there is no selected item.
virtual void setSelectedIndex (int n)
 selects the Nth item; selects the last selectable item if n = -1.
virtual UListbox & addItem (const UStr &string)
virtual UListbox & addItem (UStr &string, bool duplicate)
 adds an item to the listbox.
virtual UListbox & addItems (const UStr &strings, const UStr &separ=",")
virtual UListbox & addItems (const UArgs &prefix, const UStr &strings, const UStr &separ=",")
 adds a list of items to the listbox.
virtual UListbox & addItems (const char *items[])
virtual UListbox & addItems (const std::vector< UStr * > &items, bool duplicate=true)
virtual UListbox & addItems (const UArgs &prefix, const char *items[])
virtual UListbox & addItems (const UArgs &prefix, const std::vector< UStr * > &items, bool duplicate=true)
 adds a list of items to the listbox.

Static Public Member Functions

static UStyle * createStyle ()
 < important: all subclasses MUST contain this declaration. static function that returns the UStyle of this class (see details!).

Protected Attributes

uptr< UChoice > pchoice
bool transp_style

Friends

UListbox & ulistbox (const UArgs &args=UArgs::none)
 shortcut that returns *new UListbox(args).

Detailed Description

"classical" List widget.

a UListbox can contain any widget. Each widget can contain an arbitrary combination of text, images, nested widgets, etc. But the selection (see below) only takes into account interactors (eg. UItem, UButton, UCheckbox, etc.)

Standard look and feel: UItem children should be used to obtain the usual look of list widgets

Strings: UStr objects should not be directly added to the list by using the add() methods (this will make them visible but not selectable). Instead, they should be included in list children that are interactors (eg. UItem children). They can also be added to the list by means of the addItem() and addItems() methods (which create an intermediate UItem)

Geometry and properties:

Selection:

Callbacks:

Exemple:

 GUI* gui = new GUI();

 UListbox& list = ulistbox
   (UOn::action / ucall(gui, &GUI:actionCB)
    + UOn::change / ucall(gui, &GUI::changeCB)
    + ulabel("title")         // a label can't be selected
    + uitem("first item")
    + uitem(UPix::right + "second item" + ubutton(...))
   );

 listbox.add(uitem("3rd item"));

 // returns the selected item
 UBox* item = listbox.choice().getSelectedItem());

 // returns the index of the selected item
 int index = listbox.choice().getSelectedIndex();

 void GUI::changeCB(UEvent& e) {
   // source == the listbox, target = the selected item (or null)
   UGroup* source = e.getSource();
   UBox* target = e.getTarget() ? e.getTarget()->boxCast() : null;

   if (target) {
     // retrieves the text that is enclosed in the item and copies it to 's'
     UStr s = target->retrieveText();
     cout << s << endl;
   }
 }
 


Member Function Documentation

UListbox & ubit::UListbox::addItem ( UStr &  string,
bool  duplicate 
) [virtual]

adds an item to the listbox.

the string argument is duplicated except if 'duplicate' if false (in which case it is shared and directly added to the scene graph)

Objects can also be be added/removed to the UListbox by using the add()/addlist()/remove() methods that are inherited from UGroup

addItem() is equivalent to:

UListbox & ubit::UListbox::addItems ( const UArgs &  prefix,
const std::vector< UStr * > &  items,
bool  duplicate = true 
) [virtual]

adds a list of items to the listbox.

UListbox & ubit::UListbox::addItems ( const UArgs &  prefix,
const UStr &  strings,
const UStr &  separ = "," 
) [virtual]

adds a list of items to the listbox.

UStyle * ubit::UListbox::createStyle (  )  [static]

< important: all subclasses MUST contain this declaration. static function that returns the UStyle of this class (see details!).

this macro defines the UClass that corresponds to this class and:

Reimplemented from ubit::UBox.


The documentation for this class was generated from the following files:
Generated on Mon Jan 29 00:20:52 2007 for Ubit by  doxygen 1.4.7