2 - FLVW Basics

This will give you the basics of using the Virtual Widgets.  For most of the conventions and programming guidelines see Chapter 2 of the FLTK documentation entitled 2 - FLTK Basics.  Only exceptions or differences will be listed here.


All public symbols in FLVW start with the characters 'Flv':

Compiling Programs with Standard Compilers

When compiling you should define FLTK_2 if compiling for 2.x cvs versions and not define FLTK_2 if compiling for 1.x production versions. 

For the Borland ide projects you will need to set FLTK to point to the 1.x FLTK directory and set FLTKCVS to point to the 2.x cvs FLTK directory.  For either version you should set BCROOT to point to the base Borland C++ directory.

Writing Your First Program with FLVW

You should include the widget header file for whichever widgets you will be using.  Listing 1 shows a very basic use of Flv_List.

After including the required header files, the program defines a class, implements a draw row and then in main creates a window with widgets and displays it:  We will not touch much on main since it is covered much better in the FLTK documentation.

First we inherit from Flv_List so we can define a function to draw the list row.  Since the classes are virtual they don't know (or want to know) how you will be storing the values.  This was a basic design decision so you won't have to change the way you want to write a program to accommodate the widgets.  The class definition is basically just copied from a header file.  Let's look at the draw function you need to override:

  Flv_Style s;

  get_style( R, s );       // Get trickled down row style

We make a call to get_style so that we can get the trickle down version of the row style for this row.  A trickle down style starts with the default style then adds any definitions from the global_style and then anything defined in row_style[R] (if row_style[R] actually exists)  All this is so we can get an alignment style.  For the simple example we could have easily just assumed what our alignment should be and used it.  In that case our function would look like:

  Flv_List::draw_row( R, Offset, X, Y, W, H );
  fl_draw(values[R], X+1-Offset, Y+1, W-2, H-2, FL_ALIGN_CLIP );

The reason I didn't do this in the original example, is it's generally a bad idea.  You should get in the habit of using the styles.  Then when you use them in code, they'll work.  That being said, just two lines of code and our text will always print centered!  This is truely the simplest it gets. :)  

The program is mostly a basic FLTK program, if you've written an FLTK program before there shouldn't be any supprises here.  We create a window, a table, set some table properties, show the window and run the program.  If you need further assistance with the main program loop see the FLTK documentation.

As a general practice you should define styles from lower values to higher values (indices) where possible.  This will ensure minimal overhead and the classes are specifically optimized for this condition.