This container widget lets you maneuver around a set of widgets much larger than your window. More...
#include <Fl_Scroll.H>
Classes | |
struct | ScrollInfo |
Structure to manage scrollbar and widget interior sizes. | |
Public Types | |
enum | { HORIZONTAL = 1, VERTICAL = 2, BOTH = 3, ALWAYS_ON = 4, HORIZONTAL_ALWAYS = 5, VERTICAL_ALWAYS = 6, BOTH_ALWAYS = 7 } |
Public Member Functions | |
void | clear () |
Clear all but the scrollbars. | |
Fl_Scroll (int X, int Y, int W, int H, const char *l=0) | |
Creates a new Fl_Scroll widget using the given position, size, and label string. | |
int | handle (int) |
Handles the specified event. | |
void | resize (int X, int Y, int W, int H) |
Resizes the Fl_Scroll widget and moves its children if necessary. | |
void | scroll_to (int, int) |
Moves the contents of the scroll group to a new position. | |
void | scrollbar_size (int newSize) |
Sets the pixel size of the scrollbars' troughs to newSize , in pixels. | |
int | scrollbar_size () const |
Gets the current size of the scrollbars' troughs, in pixels. | |
int | xposition () const |
Gets the current horizontal scrolling position. | |
int | yposition () const |
Gets the current vertical scrolling position. | |
Public Attributes | |
Fl_Scrollbar | hscrollbar |
Fl_Scrollbar | scrollbar |
Protected Member Functions | |
void | bbox (int &, int &, int &, int &) |
Returns the bounding box for the interior of the scrolling area, inside the scrollbars. | |
void | draw () |
Draws the widget. |
This container widget lets you maneuver around a set of widgets much larger than your window.
If the child widgets are larger than the size of this object then scrollbars will appear so that you can scroll over to them:
If all of the child widgets are packed together into a solid rectangle then you want to set box() to FL_NO_BOX or one of the _FRAME types. This will result in the best output. However, if the child widgets are a sparse arrangement you must set box() to a real _BOX type. This can result in some blinking during redrawing, but that can be solved by using a Fl_Double_Window.
By default you can scroll in both directions, and the scrollbars disappear if the data will fit in the area of the scroll.
Use Fl_Scroll::type() to change this as follows :
Use scrollbar.align(int) ( see void Fl_Widget::align(Fl_Align) ) : to change what side the scrollbars are drawn on.
If the FL_ALIGN_LEFT bit is on, the vertical scrollbar is on the left. If the FL_ALIGN_TOP bit is on, the horizontal scrollbar is on the top. Note that only the alignment flags in scrollbar are considered. The flags in hscrollbar however are ignored.
This widget can also be used to pan around a single child widget "canvas". This child widget should be of your own class, with a draw() method that draws the contents. The scrolling is done by changing the x() and y() of the widget, so this child must use the x() and y() to position its drawing. To speed up drawing it should test fl_not_clipped(int x,int y,int w,int h) to find out if a particular area of the widget must be drawn.
Another very useful child is a single Fl_Pack, which is itself a group that packs its children together and changes size to surround them. Filling the Fl_Pack with Fl_Tabs groups (and then putting normal widgets inside those) gives you a very powerful scrolling list of individually-openable panels.
Fluid lets you create these, but you can only lay out objects that fit inside the Fl_Scroll without scrolling. Be sure to leave space for the scrollbars, as Fluid won't show these either.
You cannot use Fl_Window as a child of this since the clipping is not conveyed to it when drawn, and it will draw over the scrollbars and neighboring objects.
Fl_Scroll::Fl_Scroll | ( | int | X, | |
int | Y, | |||
int | W, | |||
int | H, | |||
const char * | L = 0 | |||
) |
Creates a new Fl_Scroll widget using the given position, size, and label string.
The default boxtype is FL_NO_BOX.
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 Fl_Scroll and all of its children can be automatic (local) variables, but you must declare the Fl_Scroll first, so that it is destroyed last.
void Fl_Scroll::bbox | ( | int & | X, | |
int & | Y, | |||
int & | W, | |||
int & | H | |||
) | [protected] |
void Fl_Scroll::clear | ( | ) |
void Fl_Scroll::draw | ( | ) | [protected, virtual] |
Draws the widget.
Never call this function directly. FLTK will schedule redrawing whenever needed. If your widget must be redrawn as soon as possible, call redraw() instead.
Override this function to draw your own widgets.
If you ever need to call another widget's draw method from within your own draw() method, e.g. for an embedded scrollbar, you can do it (because draw() is virtual) like this:
Fl_Widget *s = &scroll; // scroll is an embedded Fl_Scrollbar s->draw(); // calls Fl_Scrollbar::draw()
Reimplemented from Fl_Group.
int Fl_Scroll::handle | ( | int | event | ) | [virtual] |
Handles the specified event.
You normally don't call this method directly, but instead let FLTK do it when the user interacts with the widget.
When implemented in a widget, this function must return 0 if the widget does not use the event or 1 otherwise.
Most of the time, you want to call the inherited handle() method in your overridden method so that you don't short-circuit events that you don't handle. In this last case you should return the callee retval.
[in] | event | the kind of event received |
0 | if the event was not used or understood | |
1 | if the event was used and can be deleted |
Reimplemented from Fl_Group.
void Fl_Scroll::resize | ( | int | X, | |
int | Y, | |||
int | W, | |||
int | H | |||
) | [virtual] |
Resizes the Fl_Scroll widget and moves its children if necessary.
The Fl_Scroll widget first resizes itself, and then it moves all its children if (and only if) the Fl_Scroll widget has been moved. The children are moved by the same amount as the Fl_Scroll widget has been moved, hence all children keep their relative positions.
Since children of an Fl_Scroll are not resized, the resizable() widget is ignored (if it is set).
The scrollbars are moved to their proper positions, as given by Fl_Scroll::scrollbar.align(), and switched on or off as necessary.
Reimplemented from Fl_Group.
void Fl_Scroll::scroll_to | ( | int | X, | |
int | Y | |||
) |
Moves the contents of the scroll group to a new position.
This is like moving the scrollbars of the Fl_Scroll around. For instance:
Fl_Scroll scroll (10,10,200,200); Fl_Box b1 ( 10, 10,50,50,"b1"); // relative (x,y) = (0,0) Fl_Box b2 ( 60, 60,50,50,"b2"); // relative (x,y) = (50,50) Fl_Box b3 ( 60,110,50,50,"b3"); // relative (x,y) = (50,100) // populate scroll with more children ... scroll.end(); scroll.scroll_to(50,100);
will move the logical origin of the internal scroll area to (-50,-100) relative to the origin of the Fl_Scroll (10,10), i.e. Fl_Box b3 will be visible in the top left corner of the scroll area.
void Fl_Scroll::scrollbar_size | ( | int | newSize | ) | [inline] |
Sets the pixel size of the scrollbars' troughs to newSize
, in pixels.
Normally you should not need this method, and should use Fl::scrollbar_size(int) instead to manage the size of ALL your widgets' scrollbars. This ensures your application has a consistent UI, is the default behavior, and is normally what you want.
Only use THIS method if you really need to override the global scrollbar size. The need for this should be rare.
Setting newSize
to the special value of 0 causes the widget to track the global Fl::scrollbar_size(), which is the default.
[in] | newSize | Sets the scrollbar size in pixels. If 0 (default), scrollbar size tracks the global Fl::scrollbar_size() |
int Fl_Scroll::scrollbar_size | ( | ) | const [inline] |
Gets the current size of the scrollbars' troughs, in pixels.
If this value is zero (default), this widget will use the Fl::scrollbar_size() value as the scrollbar's width.
int Fl_Scroll::xposition | ( | ) | const [inline] |
Gets the current horizontal scrolling position.
int Fl_Scroll::yposition | ( | ) | const [inline] |
Gets the current vertical scrolling position.