What is Fluid?

Fluid (the Fast Light User Interface Designer) is a graphical editor that is used to produce fltk source code.

Fluid edits and saves it's state in ".fl" files. These files are text, and you could (with care) edit them in a text editor, perhaps to get some special effects.

Fluid can "compile" the .fl file into a .C and a .H file. The .C file defines all the objects from the .fl file and the .H file declares all the global ones.

A simple program can be made by putting all your code (including a main() function) into the .fl file and thus making the .C file a single source file to compile. Normally though you write other .C files that call the fluid functions. These .C files must #include the .H file output (or they can #include the .C file so it still appears to make to be a single source file).

                               _________
                              /        /
    __________            +->/.C file /--------+
   /         /           /  /________/         |
  /.fl file /<==>[fluid]<     #include         |
 /_________/             \     ___v_____       |
                          \   /        /       |
                           +>/.H file /        |
                            /________/         |
                                  ^            |
                              #include         |
                               ___|_____       |          __________
                              /        /       V         /         /
                             / main.C /--->[c++,link]-->/ program /
                            /________/                 /_________/

Normally the fluid file defines one or more "functions", which output C++ functions. Each function defines a one or more fltk windows, and all the widgets that go inside those windows.

Widgets created by fluid are either "named", "complex named" or "unnamed". A named widget has a legal C++ variable identifier as it's name (ie only alphanumeric and underscore). In this case fluid defines a global variable that will point at the widget after the function defining it is called. A "complex named" object has punctuation such as '.' or '->' or any other symbols in it's name. In this case fluid assigns a pointer to the widget to the name, but does not attempt to declare it. This can be used to get the widgets into structures. An "unnamed" widget has a blank name and no pointer to them is stored.

Widgets may either call a named callback function that you write in another source file, or you can supply a small piece of C++ source and fluid will write a private callback function into the .C file.

Worlds shortest tutorial

  1. Type "fluid&"
  2. Pick "New/code/function" off the menu.
  3. Hit Tab, Delete to delete the function name and hit OK. This is how you get fluid to output a "main()" function. The text "main()" with a triangle next to it should appear highlighted in the main window.
  4. Pick "New/group/Window" off the menu.
  5. Move the new window and resize it to the size you want.
  6. Pick "New/buttons/Button" off the menu.
  7. Hit the "OK" button to dismiss the panel that appears.
  8. In the window you created, try moving the button by dragging it around. Notice that it "snaps" to fixed locations. If you want to drag it smoothly, hold down Alt. You can also change the size of the steps with Edit/Preferences.
  9. Try resizing the widget by dragging the edges and corners.
  10. Type Alt+c to copy the widget.
  11. Type Alt+v to paste a copy into the window.
  12. Type Alt+v several times.
  13. Drag the widgets and resize them so they don't overlap. Notice that you have to click a widget to pick it first, then drag it.
  14. Try selecting several widgets by dragging a box around them. Check what happens when you move them, or when you drag an edge to resize them.
  15. You can also use Shift+click to toggle widgets on and off.
  16. You can also select widgets by clicking on them in the list in the main window, try that.
  17. Double-click one of the widgets. You will get a control panel.
  18. Try changing the "label". Try changing other items near the top of the panel. To see any changes to the box type clearer, type "Alt+o" to make the red overlay disappear.
  19. Type "#include <stdlib.h>" into the first line of "extra code:".
  20. Type "exit(0);" into the "callback:".
  21. Hit OK.
  22. Pick "File/Save As" off the menu.
  23. Type "test.fl" into the file chooser and hit return.
  24. Pick "File/Write Code" off the menu, hit OK on the confirmation panel.
  25. Go back to your terminal window. Type "more test.C" and "more test.H" and you can see the code it made. Also try "more test.fl" to see how fluid saves it's data.
  26. Type "make test" (you may have to add libaries to your Makefile).
  27. Type "./test" to run your program.
  28. Try the buttons. The one you put the code into will exit the program.
  29. Type "Alt+Q" to exit fluid.
  30. Ok, now try to make a real program.

Running fluid

Type

	fluid <name>.fl &

to edit the .fl file <name>.fl. If the file does not exist you will get an error pop-up, but if you dismiss it you will be editing a blank setup of that name. You can run fluid without any name, in which case you will be editing an unnamed blank setup (but you can use save-as to write it to a file).

You can provide any of the standard fltk switches before the name:

	 -display host:n.n
	 -geometry WxH+X+Y
	 -title windowtitle
	 -name classname
	 -iconic
	 -fg color
	 -bg color
	 -bg2 color

Changing the colors may be useful to see what your interface will look at if the user calls it with the same switches.

In the current version, if you don't go into the background (with '&') then you will be able to abort fluid by typing ^C on the terminal. It will exit immediately, losing any changes.

Compiling .fl files

Fluid can also be called as a command-line "compiler" to create the .C and .H file from a .fl file. To do this type

	fluid -c <name>.fl

This will read the .fl file and write <name>.C and <name>.H (the directory will be stripped, they are written to the current directory always), and then exit. If there are any errors reading or writing the files it will print the error and exit with a non-zero code. This is useful in a makefile. A line like this will work:

my_panels.H my_panels.C : my_panels.fl
	fluid -c my_panels.fl

Some versions of Make will accept rules like this to allow all .fl files found to be compiled:

.SUFFIXES : .fl .C .H
.fl.H :
	fluid -c $<
.fl.C :
	fluid -c $<

Some versions of Make (gnumake) may prefer this syntax:

%.H: %.fl
        fluid -c $<

%.C: %.fl
        fluid -c $<

The Widget Browser

The main window shows a menu bar and a scrolling browser of all the defined widgets. The name of the .fl file being edited is shown in the window title.

The widgets are stored in a hierarchy. You can open and close a level by clicking the "triangle" at the left of a widget. This widget is the parent, and all the widgets listed below it are it's children. There can be zero children.

The top level of the hierarchy is functions. Each of these will produce a single C++ public function in the output .C file. Calling the function will create all of it's child windows.

The second level of the hierarchy is windows. Each of these produces an instance of class Fl_Window.

Below that are either widgets (subclasses of Fl_Widget) or groups of widgets (including other groups). Plain groups are for layout, navigation, and resize purposes. Tab groups provide the well-known file-card tab interface.

Widgets are shown in the browser as either their name (such as "main_panel" in the example), or if unnamed as their type and label (such as "Button "the green"").

You select widgets by clicking on their names, which highlights them (you can also select widgets from any displayed window). You can select many widgets by dragging the mouse across them, or by using shift+click to toggle them on and off. To select no widgets, click in the blank area under the last widget. Notice that hidden children may be selected and there is no visual indication of this.

You open widgets by double clicking them, or (to open several widgets you have picked) by typing the F1 key. This will bring up a control panel or window from which you can change the widget.

Menu Items

The menu bar at the top is duplicated as a pop-up menu on any displayed window. The shortcuts for all the menu items work in any window. The menu items are:

File/Open... (Alt+Shift+O)

File/Save (Alt+s)

File/Save As...(Alt+Shift+S)

File/Merge... (Alt+i)

File/Write code (Alt+Shift+C)

File/Quit (Alt+q)

Edit/Undo (Alt+z)

Edit/Cut (Alt+x)

Edit/Copy (Alt+c)

Edit/Paste (Alt+c)

Edit/Select All (Alt+a)

Edit/Open... (F1 or double click)

Edit/Sort

Edit/Earlier (F2)

Edit/Later (F3)

Edit/Group (F7)

Edit/Ungroup (F8)

Edit/Overlays on/off (Alt+o)

Edit/Preferences (Alt+p)

New/code/Function

New/Window

New/...

Help/About fluid

Help/Manual

The Widget Panel

When you double-click a widget or a set of widgets you will get the "widget attribute panel":

When you change attributes using this panel, the changes are reflected immediately in the window. It is useful to hit the "no overlay" button (or type Alt+o) to hide the red overlay so you can see the widgets more accurately, especially when setting the box type.

If you have several widgets selected, they may have different values for the fields. In this case the value for one of the widgets is shown. But if you change this value, all the selected widgets are changed to the new value.

Hitting "OK" makes the changes permanent. Selecting a different widget also makes the changes permanent. Fluid checks for simple syntax errors in any code (such as mismatched parenthesis) before saving any text.

"Revert" or "Cancel" put everything back to when you last brought up the panel or hit OK. However in the current version of Fluid, changes to "visible" attributes (such as the color, label, box) are not undone by revert or cancel. Changes to code like the callbacks is undone, however.

Widget Attributes

Name (text field)

Type (upper-right pulldown menu)

Box (pulldown menu)

Color

Color2

Label

Label style (pull down menu)

Label alignement (buttons)

Label font

Label size

Label color

Text font, size, color

Visible

Active

Resizable

Hotspot

subclass

Extra code

Callback

user_data

User data type

When

Selecting & Moving Widgets

Double-clicking a window name in the browser will display it, if not displayed yet. From this display you can select widgets, sets of widgets, and move or resize them. To close a window either double-click it or type Esc.

To select a widget, click it. To select several widgets drag a rectangle around them. Holding down shift will toggle the selection of the widgets instead.

You cannot pick hidden widgets. You also cannot choose some widgets if they are completely overlapped by later widgets. Use the browser to select these widgets.

The selected widgets are shown with a red "overlay" line around them. You can move the widgets by dragging this box. Or you can resize them by dragging the outer edges and corners. Hold down the Alt key while dragging the mouse to defeat the snap-to-grid effect for fine positioning.

If there is a tab box displayed you can change which child is visible by clicking on the file tabs. The child you pick is selected.

The arrow, tab, and shift+tab keys "navigate" the selection. Left, right, tab, or shift+tab move to the next or previous widgets in the hierarchy. Hit the right arrow enough and you will select every widget in the window. Up/down widgets move to the previous/next widgets that overlap horizontally. If the navigation does not seem to work you probably need to "Sort" the widgets. This is important if you have input fields, as fltk uses the same rules when using arrow keys to move between input fields.

To "open" a widget, double click it. To open several widgets select them and then type F1 or pick "Edit/Open" off the pop-up menu.

Type Alt+o to temporarily toggle the overlay off without changing the selection, so you can see the widget borders.

You can resize the window by using the window manager border controls. Fltk will attempt to round the window size to the nearest multiple of the grid size and makes it big enough to contain all the widgets (it does this using illegal X methods, so it is possible it will barf with some window managers!). Notice that the actual window in your program may not be resizable, and if it is, the effect on child widgets may be different.

The panel for the window (which you get by double-clicking it) is almost identical to the panel for any other Fl_Widget. There are three extra items:

Border

xclass

Image Labels

Selecting "Image..." off the label style pull-down menu will bring up a file chooser from which you pick the image file. If an image has already been chosen, you can change the image used by picking "Image..." again. The name of the image will appear in the "label" field, but you can't edit it.

The contents of the image file are written to the .C file, so if you wish to distribute the C code, you only need to copy the .C file, not the images. If many widgets share the same image then only one copy is written.

However the file name is stored in the .fl file, so to read the .fl file you need the image files as well. Filenames are relative to the location the .fl file is (not necessarily the current directory). I recommend you either put the images in the same directory as the .fl file, or use absolute path names.

Notes for all image types

XBM (X bitmap files)

XPM (X pixmap files)

GIF files

(back to contents)