This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Migration
Migrating to UNIGINE 2.0
C++ API Migration
Migrating from UNIGINE 2.0 to UNIGINE 2.1
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

WidgetTreeBox Class

This class creates a box with a tree-like hierarchy. For example:

Source code (UnigineScript)
int init() {

Gui gui = engine.getGui();

WidgetTreeBox tree = new WidgetTreeBox(gui);

tree.addItem("1st item");  // Add items into the tree.
tree.addItem("2nd item");
tree.addItem("3rd item");
tree.addItem("4th item");

tree.addItemChild(0,1);   // Make a 2nd item a child of the 1st one.
tree.setItemFolded(0,1);  // Collapse children of the 1st child.

WidgetWindow window = new WidgetWindow(gui);  // Create a window.
gui.addChild(window,GUI_ALIGN_CENTER);

window.addChild(tree,GUI_ALIGN_CENTER); // Render a tree in the window.

return 1;
}

As a result, you will get:

WidgetTreeBox in a window

See Also

WidgetTreeBox Class

This class inherits from Widget

Members


WidgetTreeBox (Gui gui)

Constructor. Creates an empty tree box.

Arguments

  • Gui gui - GUI, to which the new tree box will belong.

void addItemChild (int item, int child)

Adds a child to a given item.

Arguments

  • int item - Item ID.
  • int child - Child item ID.

int addItem (string text, int icon = -1 = -1)

Adds a new item with a given text and and an icon.

Arguments

  • string text - Item text.
  • int icon = -1 - Zero-based ID of the icon.

Return value

ID of the added item.

void clearSelection ()

Clears list of selected items.

void clear ()

Removes all items from the tree box.

string getCurrentItemData ()

Returns the data of a given item.

Return value

Item data.

string getCurrentItemText ()

Returns the text of the currently focused item.

Return value

Item text.

int getCurrentItem ()

Returns the item currently in focus.

Return value

Item ID.

Image getImage ()

Returns the image with mini-icons.

Return value

Image with mini-icons.

int getItemChild (int item, int child)

Returns a child of a given item.

Arguments

  • int item - Item ID.
  • int child - Child number in the list of children.

Return value

Child item ID.

vec4 getItemColor (int item)

Returns a color set to a given item.

Arguments

  • int item - Item ID.

Return value

Color.

string getItemData (int item)

Returns the data of the currently selected item.

Arguments

  • int item - Item number in range from 0 to the total number of items.

Return value

Item data.

int getItemParent (int item)

Returns the parent of a given item.

Arguments

  • int item - Item ID.

Return value

Parent item ID.

string getItemText (int item)

Returns the text of a given item.

Arguments

  • int item - Item ID.

Return value

Item text.

int getItemTexture (int item)

Returns the icon of a given item.

Arguments

  • int item - Item ID.

Return value

Zero-based ID of the icon.

int getItem (int item_number)

Returns the ID of a given item by its number. The IDs are unique, and the numbers simply point at the place in the list of all items.

Arguments

  • int item_number - Item number.

Return value

ID of the item.

void getItems (int items = [])

Returns all items in the tree box.

Arguments

  • int items - An array with item IDs.

int getNumItemChildren (int item)

Returns the number of child items of a given item.

Arguments

  • int item - Item ID.

Return value

Number of child items.

int getNumItemChilds (int item)

Returns the number of child items of a given item.
Warning
The function is deprecated. It is provided to keep your code working until the next release. Please, replace it with getNumItemChildren().

Arguments

  • int item - Item ID.

Return value

Number of child items.

int getNumItems ()

Returns the number of visible items in the tree box. Items that are currently to a parent level are not returned.

Return value

Number of items.

Examples

Source code (UnigineScript)
int init() {

Gui gui = engine.getGui();

WidgetTreeBox tree = new WidgetTreeBox(gui);

tree.addItem("1st item");
tree.addItem("2nd item");
tree.addItem("3rd item");
tree.addItem("4th item");

tree.addItemChild(0,1);   // Make a 2nd item a child of the 1st one.
tree.setItemFolded(0,1);  // Collapse children of the 1st child.

WidgetWindow window = new WidgetWindow(gui);
gui.addChild(window,GUI_ALIGN_CENTER);

window.addChild(tree,GUI_ALIGN_CENTER);

tree.arrange();  // Update widget layout to get relevant info in the same frame.

forloop(int i = 0; tree.getNumItems()) {
int item = tree.getItem(i);
log.message("item: %d %s\n",item,tree.getItemText(item));
}

return 1;
}
Output
item: 0 1st item
item: 2 3rd item
item: 3 4th item

int getNumSelectedItems ()

Returns number of selected items in the box.

Return value

Number of selected items.

int getSelectedItem (int num)

Returns ID of a selected item (multi-selection mode).

Arguments

  • int num - Number of an item in the list of selected items.

Return value

ID of the selected item.

string getTexture ()

Returns file name of the image with mini-icons.

Return value

Path to the texture file.

int isEditable ()

Returns a value indicating if item hierarchy can be edited.

Return value

1 if the hierarchy can be edited; otherwise, 0.

int isItemChild (int item, int child)

Checks if a given item is a child of another specified item.

Arguments

  • int item - Item ID.
  • int child - Child item ID.

Return value

1 if child is actually a child of the item; otherwise, 0.

int isItemFolded (int item)

Returns a value indicating if a given item is collapsed.

Arguments

  • int item - Item ID.

Return value

1 if the item is collapsed; otherwise, 0.

int isItemHidden (int item)

Returns a value indicating if an item is hidden or not.

Arguments

  • int item - Item ID.

Return value

1 if the item is hidden; otherwise, 0.

int isItemSelectable (int item)

Returns a value indicating if a given item can be selected.

Arguments

  • int item - Item number.

Return value

1 if the item is selectable; otherwise, 0.

int isItemSelected (int item)

Returns a value indicating if a given item is selected.

Arguments

  • int item - Item ID.

Return value

1 if the item is selected; otherwise, 0.

int isMultiSelection ()

Returns a value indicating if multiple selection of items is enabled.

Return value

1 if several items can be selected at once; otherwise, 0.

void removeItemChild (int item, int child)

Removes a child of a given item.

Arguments

  • int item - Item ID.
  • int child - Child item ID.

void removeItem (int item)

Removes a given item from the tree box. Children items will be kept.

Arguments

  • int item - Item ID.

void setCurrentItem (int item)

Places focus on a given item.

Arguments

  • int item - Item ID.

void setEditable (int mode)

Sets a value indicating if item hierarchy can be edited.

Arguments

  • int mode - 1 to make the hierarchy editable, 0 to make it read-only.

void setImage (Image image)

Sets an image with mini-icons to be used with items. The image is a vertical strip of square icons.

Arguments

  • Image image - Image to set.

void setItemColor (int item, vec4 color)

Sets a custom color for a given item.

Arguments

  • int item - Item ID.
  • vec4 color - Color to set.

void setItemData (int item, string data)

Sets the data for a given item. The data can be used as a text identifier of the item (instead of using the number of the item).

Arguments

  • int item - Item number in range from 0 to the total number of items.
  • string data - Data to set.

void setItemFolded (int item, int state)

Expands or collapses an hierarchy of a given item.

Arguments

  • int item - Item ID.
  • int state - 1 to collapse the item hierarchy, 0 to expand it.

void setItemHidden (int item, int state)

Sets a value indicating if a given item is hidden.

Arguments

  • int item - Item ID.
  • int state - 1 to hide the item, 0 to show it.

void setItemParent (int item, int parent)

Sets a parent for a given item.

Arguments

  • int item - Item ID.
  • int parent - Parent item ID. -1 removes the current parent.

void setItemSelectable (int item, int state)

Sets a value indicating if a given item can be selected.

Arguments

  • int item - Item number.
  • int state - 1 to set the item as selectable, 0 to set it as unselectable.

void setItemSelected (int item, int state)

Selects or deselects a given item.

Arguments

  • int item - Item ID.
  • int state - 1 to select the item, 0 to deselect it.

void setItemText (int item, string text)

Sets a text for a given item.

Arguments

  • int item - Item ID.
  • string text - Item text.

void setItemTexture (int item, int icon)

Sets an icon for a given item.

Arguments

  • int item - Item ID.
  • int icon - Zero-based ID of the icon.

void setMultiSelection (int mode)

Enables or disables multiple selection of items.

Arguments

  • int mode - 1 to enable multiple selection, 0 to disable it.

void setTexture (string texture)

Sets a texture with mini-icons to be used with items. The texture is a vertical strip of square icons.

Arguments

  • string texture - Path to a texture file.

void showItem (int item)

Scrolls a tree box so that a given item is visible.

Arguments

  • int item - Item ID.
Last update: 2017-07-03
Build: ()