## class fltk::Group

### Class Hierarchy

    fltk::Widget
       |
       +----fltk::Group
               |
               +----fltk::Pack, fltk::Scroll, fltk::Tabs, fltk::Tile, fltk::Window

### Include Files

    #include <fltk/Group.h>

### Description

The fltk::Group class is the FLTK container widget. It maintains an array of child widgets. These children can themselves be any widget including fltk::Group, nesting groups allows much more control over layout and resize behavior. Nested groups are also necessary to group radio buttons together.

By default fltk::Group preserves the positions and sizes of all it's children, they do not move no matter what sizes or other children are added or removed.

Setting resizable() will change the layout behavior so that it responds to resizing by moving or resizing the children to fit. See below for details.

You may want to use an fltk::Pack or a fltk::Scroll to get other common layout behavior that can respond to changes in the sizes of child widgets.

The most-used subclass of fltk::Group is `fltk::Window`, all the rules about resizing apply to windows. Setting resizable() on a window will allow the user to resize it. If you want different behavior (such as from fltk::Pack) for your window you should make the window have that as a single resizable child that fills it.

fltk::Menu is a subclass and thus all menus and browsers are groups and the items in them are widgets.

### Methods

- fltk::Group
- ~Group
- add
- add_resizable
- begin

- child
- clear
- children
- current

- end
- focus
- find
- init_sizes

- insert
- remove
- replace
- resizable

#### fltk::Group::Group(int x, int y, int w, int h, const char *label = 0)

Creates a new `fltk::Group` widget using the given position, size, and label string. The default boxtype is `fltk::NO_BOX`.

#### virtual fltk::Group::~Group()

The destructor also deletes all the children. This allows a whole tree to be deleted at once, without having to keep a pointer to all the children in the user code. A kludge has been done so the `fltk::Group` and all of it's children can be automatic (local) variables, but you must declare the `fltk::Group` first, so that it is destroyed last.

#### void fltk::Group::add(fltk::Widget &w)
void fltk::Group::add(fltk::Widget *w)

The widget is removed from it's current group (if any) and then added to the end of this group.

#### void fltk::Group::insert(fltk::Widget &w, int n)

The widget is removed from it's current group (if any) and then inserted into this group. It is put at index `n` (or at the end if `n >= children()`. This can also be used to rearrange the windgets inside a group.

#### void fltk::Group::insert(fltk::Widget &w, fltk::Widget* beforethis)

This does `insert(w, find(beforethis))`. This will append the widget if `beforethis` is not in the group.

#### void fltk::Group::remove(int index)

Remove the indexed widget from the group.

#### void fltk::Group::remove(fltk::Widget &w)

Removes a widget from the group. This does nothing if the widget is not currently a child of this group.

#### void fltk::Group::replace(int index, fltk::Widget&)

Remove the indexed widget and insert the passed widget in it's place.

#### void fltk::Group::replace(fltk::Widget& old, fltk::Widget&)

Find the old widget and remove it and insert the new one. If the widget is not a child, the new widget is appended to the end of the list.

#### void clear();

Deletes all children from the group and makes it empty.

#### static fltk::Group *fltk::Group::current()
static void fltk::Group::current(fltk::Group *w)

`current()` returns the currently active group. The fltk::Widget constructor automatically does `current()->add(widget)` if this is not null. To prevent new widgets from being added to a group, call `fltk::Group::current(0)`.

#### void fltk::Group::begin()

`begin()` sets the current group so you can build the widget tree by just constructing the widgets. `begin()` is automatically called by the constructor for fltk::Group (and thus for fltk::Window as well). `begin()` is exactly the same as `current(this)`.

Don't forget to `end()` the group or window!

#### void fltk::Group::end()

`end()` is exactly the same as `current(this->parent())`. Any new widgets added to the widget tree will be added to the parent of the group.

#### void fltk::Group::init_sizes() const

If you call this immediately after a resize() it disables any automatic repositioning or resizing of the children (it acts as though resizable() is null). This is useful when the program wants to resize things.

#### void fltk::Group::focus(int i);
void fltk::Group::focus(fltk::Widget*);
int fltk::Group::focus() const;

The index of the widget that contains the focus. You can initialize this before the group is displayed. Changing it while it is displayed does not work, use widget->take_focus() instead.

#### fltk::Widget *fltk::Group::child(int n) const

Returns a child, `n >= 0 && n < children()`. No range checking is done!

#### int fltk::Group::children() const

Returns how many child widgets the group has.

#### int fltk::Group::find(const fltk::Widget *w) const
int fltk::Group::find(const fltk::Widget &w) const

Searches the children for w, returns the index of w or of a parent of w that is a child of this. Returns `children()` if the widget is `NULL` or not found.

#### void fltk::Group::resizable(fltk::Widget *box)
void fltk::Group::resizable(fltk::Widget &box)
fltk::Widget *fltk::Group::resizable() const

The resizable widget defines the resizing box for the group. When the group is resized it calculates a new size and position for all of its children. Widgets that are horizontally or vertically inside the dimensions of the box are scaled to the new size. Widgets outside the box are moved.

In these examples the gray area is the resizable:

The resizable may be set to the group itself, in which case all the contents are resized. If the resizable is `NULL` (the default) then all widgets remain a fixed size and distance from the top-left corner.

It is possible to achieve any type of resize behavior by using an invisible `fltk::InvisibleBox` as the resizable and/or by using a hierarchy of child `fltk::Group`'s.

#### fltk::Group& fltk::Group::add_resizable(fltk::Widget &box)

Adds a widget to the group and makes it the resizable widget.