Documentation

  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  ]
 

class Fl_Scroll


Class Hierarchy

Include Files

    #include <FL/Fl_Scroll.H>
    

Description

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:

Fl_Scroll widget.

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 arrangment 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.

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 it's drawing. To speed up drawing it should test fl_push_clip() .

Another very useful child is a single Fl_Pack, which is itself a group that packs it's 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 widgets should not be nested. Having an Fl_Scroll inside another Fl_Scroll may result in drawing errors when resizing.

Methods

Fl_Scroll::Fl_Scroll(int x, int y, int w, int h, const char *label = 0)

Creates a new Fl_Scroll widget using the given position, size, and label string. The default boxtype is FL_NO_BOX.

virtual Fl_Scroll::~Fl_Scroll()

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 it's children can be automatic (local) variables, but you must declare the Fl_Scrollfirst, so that it is destroyed last.

void Fl_Widget::type(int)

By default you can scroll in both directions, and the scrollbars disappear if the data will fit in the area of the scroll. type() can change this:
  • 0 - No scrollbars
  • Fl_Scroll::HORIZONTAL - Only a horizontal scrollbar.
  • Fl_Scroll::VERTICAL - Only a vertical scrollbar.
  • Fl_Scroll::BOTH - The default is both scrollbars.
  • Fl_Scroll::HORIZONTAL_ALWAYS - Horizontal scrollbar always on, vertical always off.
  • Fl_Scroll::VERTICAL_ALWAYS - Vertical scrollbar always on, horizontal always off.
  • Fl_Scroll::BOTH_ALWAYS - Both always on.

void Fl_Scroll::scrollbar.align(int)

This is used 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.

Fl_Scroll::bbox(int &x, int &y, int &w, int &h)

[protected] This method returns the bounding box for the interior of the scrolling area, inside the scrollbars.

int Fl_Scroll::xposition() const

Gets the current horizontal scrolling position.

int Fl_Scroll::yposition() const

Gets the current vertical scrolling position.

void Fl_Scroll::position(int w, int h)

Sets the upper-lefthand corner of the scrolling region.

User Comments [ Add Comment ]

From nentwig (GuessWho???, 10:39 Feb 25, 2004 (score=4)

Hello,

Problem: A FL_Scroll contains widgets. When scrolling, they are not drawn correctly. For example, labels "smear" over each other. Solution: use scroll->box(FL_DOWN_FRAME);

Reference: fltk.bugs list, Re: [fltk.bugs] Fl_Scroll and drawing widgets (possible bug) Thu, 18 Dec 2003 23:05:15 +0300
Reply ]

From Deuce, 00:10 Jan 16, 2003 (score=2)

Don't forget, Fl_Widget::x() is relative to the enclsing Fl_Window, not the Fl_Group.  So, if you want the scrollbox s to scroll the top left corner of a specific widget w, do something like: s->position(w->x() - s->x() + Fl::box_dx(s->box()), w->y() - s->y() + Fl::box_dy(s->box())) and NOT s->position(w->x(), w->y())
Reply ]

From Deuce, 00:26 Jan 16, 2003 (score=4)

Glah, that's an incorrect example... *sigh* working too late.

The CORRECT way to do it would be to add the values in the previous example to s->[xy]position()
Reply ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2015 by Bill Spitzak and others. This project is hosted by Seriss Corporation. Please report site problems to 'erco@seriss.com'.