Layout and Resizing


virtual void fltk::Widget::layout ()
bool fltk::Widget::resize (int x, int y, int w, int h)
bool fltk::Widget::position (int x, int y)
bool fltk::Widget::resize (int w, int h)
void fltk::Widget::relayout ()
uchar fltk::Widget::layout_damage () const
void fltk::Widget::layout_damage (uchar c)
bool fltk::Widget::horizontal () const
bool fltk::Widget::vertical () const
void fltk::Widget::set_vertical ()
void fltk::Widget::set_horizontal ()

Detailed Description

When a widget resized or moved (or when it is initially created), flags are set in it to indicate the layout is damaged. This will cause the virtual function layout() to be called later on, just before fltk attempts to draw the windows on the screen.

This is useful because often calculating the new layout is quite expensive, this expense is thus deferred until the user will actually see the new size.

Some Group widgets such as fltk::PackedGroup will also use the virtual layout() function to find out how big a widget should be. Widgets are allowed to change their own dimensions in layout(). The only rule is that if nothing except the x/y position is changed and layout() is called a second time, they must not change size again. Usually a widget will alter only one of w() or h(), and usually it will only make itself larger, not smaller. Most widgets only set w() or h() if one or both of them are zero.

Function Documentation

bool Widget::horizontal  )  const [inline, inherited]

Return true if this widget has a horizontal orientation and fltk::Pack will position it against the top or bottom edge. This is the default.

void Widget::layout  )  [virtual, inherited]

Virtual function to respond to layout_damage(), it should calculate the correct size of this widget and all it's children. This function is called by fltk or by the layout() method in other widgets. User programs should not call it.

A widget is allowed to alter it's own size in a layout() method, to indicate a size that the data will fit in. A parent widget is then expected to rearrange itself to accomodate the new size. This may mean it will move the widget and thus layout() will be called again.

You can look at layout_damage() to find out why this is being called.

The base class redraws the widget and sets layout_damage() to zero.

Reimplemented in fltk::Divider, fltk::Group, fltk::Window, fltk::BarHolder, fltk::DockHolder, fltk::GripperBar, fltk::RegionHolder, fltk::ToolBar, fltk::ToolDivider, fltk::ToolWindow, and fltk::WindowHolder.

void Widget::layout_damage uchar  c  )  [inline, inherited]

Directly change the value returned by layout_damage().

uchar Widget::layout_damage  )  const [inline, inherited]

The 'or' of all the calls to relayout() or resize() done since the last time layout() was called. For more information see the Layout and Resizing chapter.

A typical layout function does not care about the widget moving, an easy way to skip it is as follows:

MyClass::layout() {
  if (!(layout_damage() & ~LAYOUT_XY)) return;

bool Widget::position int  x,
int  y

Same as resize() to x, y, w(), h()

void Widget::relayout  )  [inherited]

Same as relayout(LAYOUT_DAMAGE), indicates that data inside the widget may have changed, but the size did not change. This flag is also on when the widget is initially created.

bool Widget::resize int  w,
int  h

Same as resize() to x(), y(), w, h

Reimplemented in fltk::Group, and fltk::DockBase.

bool Widget::resize int  x,
int  y,
int  w,
int  h

Change the size or position of the widget. Nothing is done if the passed size and position are the same as before. If there is a change then relayout() is called so that the virtual function layout() is called before the next draw().

Reimplemented in fltk::Group, and fltk::DockBase.

void Widget::set_horizontal  )  [inline, inherited]

Undoes set_vertical() and makes horizontal() return true. This will affect how a surrounding fltk::Pack (or similar group) will place the widget, but you must call relayout() to indicate that this must be recalculated.

void Widget::set_vertical  )  [inline, inherited]

Makes vertical() return true. This will affect how a surrounding fltk::Pack (or similar group) will place the widget, but you must call relayout() to indicate that this must be recalculated.

Some widgets classes such as fltk::MenuBar or fltk::Slider will draw differently if this is turned on, in a vertical arrangement.

bool Widget::vertical  )  const [inline, inherited]

Same as !horizontal().

Tue Jun 27 02:19:43 2006. FLTK Dock is copyright © 2006 by MD. Z. Hossain