fltk::StringList Class Reference

Inherits fltk::StringHierarchy.

Inherited by fltk::StringArray.

List of all members.

Public Member Functions

virtual int children (const Menu *, const int *indexes, int level)

Detailed Description

This is a simplification of StringHierarchy where there are no subitems. It makes the virtual functions easier to write.

Typically you will create a subclass with the children() and label() functions overridden, and make a single static instance of this class. It can be used by several menus, but the Menu* argument to children() and label() is used to differentiate them.

class MyList : public StringList {
  int children(const Menu* menu) {
    return ((MyClass*)(menu->user_data()))->number_of_items();
  }
  const char* label(const Menu* menu, int index) {
    return ((MyClass*)(menu->user_data()))->label(index);
  }
};
static MyList myList;

Menu themenu;
MyClass myobject;
themenu->list(&mylist);
themenu->callback(mycallback, &myobject);

Member Function Documentation

int StringList::children ( const Menu menu,
const int *  indexes,
int  level 
) [virtual]

Return how many children are under a given item. If level is zero, this should return how many items are at the top level. Otherwise indexes is an array of level numbers indicating the index of an item at the top level, the index of the an item that is the child of that, and so on.

This should return -1 if the item is not a "parent" item or the index array is illegal. It is not necessary to return the correct value until the parent is "open", which means the fltk::STATE flag was set in it, so if it is expensive to calculate the number you can return 1 for any closed parent.

Here is a sample implementation, where Node is a data type that you have defined:

int My_List::children(const fltk::Menu*, const int* indexes, int level) {
  Node* node = root;
  for (int l = 0; l < level; l++) {
    if (indexes[l] >= node->children_count()) return -1;
    node = node->child(indexes[l]);
    if (!node->is_parent()) return -1;
  }
  return node->children_count();
}

Implements fltk::StringHierarchy.


The documentation for this class was generated from the following files: