From 367f908d8ed5a3464b9676223a26ddf4e11bdb5b Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 7 Jan 1999 16:36:11 +0000 Subject: "Final" changes for first draft of 1.0 documentation. git-svn-id: file:///fltk/svn/fltk/trunk@187 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- documentation/fluid.html | 578 ++++++++++++++++++++++------------------------- 1 file changed, 275 insertions(+), 303 deletions(-) (limited to 'documentation/fluid.html') diff --git a/documentation/fluid.html b/documentation/fluid.html index 47cb7d7fd..55a46d55f 100644 --- a/documentation/fluid.html +++ b/documentation/fluid.html @@ -1,269 +1,239 @@ -

6 - Programming with FLUID

+

8 - Programming with FLUID

This chapter shows how to use the Fast Light User-Interface Designer ("FLUID") to create your GUIs.

What is FLUID?

-

Creating A Simple Program

+The Fast Light User Interface Designer, or "FLUID", is a graphical +editor that is used to produce FLTK source code. -

Functions

- -

Windows

- -

Groups

- -

Tabs

- -

Menus

- -

Using Custom Widgets

- -

Classes

- - - -fluid Reference Manual - -
- -

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 +

FLUID edits and saves its state in ".fl" files. These files are +text, and you can (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 +

FLUID can "compile" the .fl file into a .cxx and a .h file. The .cxx +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 +main() function) into the .fl file and thus making the .cxx +file a single source file to compile. Most programs are more complex +than this, so you write other .cxx files that call the FLUID +functions. These .cxx files must #include the .h file or +they can #include the .cxx file so it still appears to be a single +source file. + +


+ + +

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 +

Widgets created by FLUID are either "named", "complex named" or +"unnamed". A named widget has a legal C++ variable identifier as its +name (i.e. only alphanumeric and underscore). In this case FLUID +defines a global variable or class member 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 its 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. +FLUID will write a private callback function into the .cxx file. - -

Worlds shortest tutorial

+

A Short Tutorial

    -
  1. Type "fluid&" +
  2. Type "FLUID&" -
  3. Pick "New/code/function" off the menu. +
  4. Pick "New/code/function" off the menu. -
  5. 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. +
  6. 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. -
  7. Pick "New/group/Window" off the menu. +
  8. Pick "New/group/Window" off the menu. -
  9. Move the new window and resize it to the size you want. +
  10. Move the new window and resize it to the size you want. -
  11. Pick "New/buttons/Button" off the menu. +
  12. Pick "New/buttons/Button" off the menu. -
  13. Hit the "OK" button to dismiss the panel that appears. +
  14. Hit the "OK" button to dismiss the panel that appears. -
  15. 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. +
  16. 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. -
  17. Try resizing the widget by dragging the edges and corners. +
  18. Try resizing the widget by dragging the edges and corners. -
  19. Type Alt+c to copy the widget. +
  20. Type Alt+c to copy the widget. -
  21. Type Alt+v to paste a copy into the window. +
  22. Type Alt+v to paste a copy into the window. -
  23. Type Alt+v several times. +
  24. Type Alt+v several times. -
  25. 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. +
  26. 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. -
  27. 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. +
  28. 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. -
  29. You can also use Shift+click to toggle widgets on and off. +
  30. You can also use Shift+click to toggle widgets on and off. -
  31. You can also select widgets by clicking on them in the list in the -main window, try that. +
  32. You can also select widgets by clicking on them in the list in the + main window, try that. -
  33. Double-click one of the widgets. You will get a control panel. +
  34. Double-click one of the widgets. You will get a control panel. -
  35. 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. +
  36. 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. -
  37. Type "#include <stdlib.h>" into the first line of "extra code:". +
  38. Type "#include <stdlib.h>" into the first line of "extra code:". -
  39. Type "exit(0);" into the "callback:". +
  40. Type "exit(0);" into the "callback:". -
  41. Hit OK. +
  42. Hit OK. -
  43. Pick "File/Save As" off the menu. +
  44. Pick "File/Save As" off the menu. -
  45. Type "test.fl" into the file chooser and hit return. +
  46. Type "test.fl" into the file chooser and hit return. -
  47. Pick "File/Write Code" off the menu, hit OK on the confirmation panel. +
  48. Pick "File/Write Code" off the menu, hit OK on the confirmation panel. -
  49. 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. +
  50. Go back to your terminal window. Type "more test.cxx" and "more + test.h" and you can see the code it made. Also try "more test.fl" to + see how FLUID saves its data. -
  51. Type "make test" (you may have to add libaries to your Makefile). +
  52. Type "make test" (you may have to add libaries to your Makefile). -
  53. Type "./test" to run your program. +
  54. Type "./test" to run your program. -
  55. Try the buttons. The one you put the code into will exit the -program. +
  56. Try the buttons. The one you put the code into will exit the + program. -
  57. Type "Alt+Q" to exit fluid. +
  58. Type "Alt+Q" to exit FLUID. -
  59. Ok, now try to make a real program. +
  60. Ok, now try to make a real program.
-
-

Running fluid

+

Running FLUID Under UNIX

-

Type +To run FLUID under UNIX, 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 +to edit the .fl file filename.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 file 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: +

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 +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. +'&') then you will be able to abort FLUID by typing ^C on the terminal. It will exit immediately, losing any changes. - +

Running FLUID Under Microsoft Windows

+ +To run FLUID under windows, double-click on the fluid.exe file. +You can also run FLUID from the Command Prompt window (FLUID +always runs in the background). +

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 can also be called as a command-line "compiler" to create the +.cxx 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 +This will read the .fl file and write filename.cxx and +filename.h. The directory will be stripped, so they are written to +the current directory always. 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 +non-zero code. In a makefile you can use a line like this: work: -

-my_panels.H my_panels.C : my_panels.fl
+
    +my_panels.h my_panels.cxx: my_panels.fl
     	fluid -c my_panels.fl
    -
    +
-

Some versions of Make will accept rules like this to allow all .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 :
+
    +.SUFFIXES: .fl .cxx .h
    +.fl.h .fl.cxx:
     	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 +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 +widget is the parent, and all the widgets listed below it are its 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. +will produce a single C++ public function in the output .cxx file. +Calling the function will create all of its child windows.

The second level of the hierarchy is windows. Each of these produces an instance of class Fl_Window. @@ -277,7 +247,12 @@ provide the well-known file-card tab interface. 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 +

+ +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 @@ -289,74 +264,73 @@ this. 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

+Not yet implemented. Use a HTML or PDF file viewer to read these pages +instead. -

The Widget Panel

-When you double-click a widget or a set of widgets you will get the -"widget attribute 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. +

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 @@ -502,12 +475,17 @@ 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 +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, +

+ +"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. @@ -515,55 +493,55 @@ 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

@@ -754,7 +730,7 @@ 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 +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 @@ -764,7 +740,7 @@ select them and then type F1 or pick "Edit/Open" off the pop-up menu. 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 +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 @@ -775,21 +751,19 @@ child widgets may be different. almost identical to the panel for any other Fl_Widget. There are three extra items: -

Border

    +

    Border

    This button turns the window manager border on or off. On most window managers you will have to close the window and reopen it to see the effect. -

xclass

    +

    xclass

    The string typed into here is passed to the X window manager as the class. This can change the icon or window decorations. On most (all?) window managers you will have to close the window and reopen it to see the effect. -
-

Image Labels

@@ -799,8 +773,8 @@ 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 +

The contents of the image file are written to the .cxx file, +so if you wish to distribute the C code, you only need to copy the .cxx file, not the images. If many widgets share the same image then only one copy is written. @@ -810,9 +784,9 @@ 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

    +

    Notes for all image types

    -

    Fluid runs using the default visual of your X server. This may be +

    FLUID runs using the default visual of your X server. This may be 8 bits, which will give you dithered images. You may get better results in your actual program by adding the code "Fl::visual(FL_RGB)" to your code right before the first window is displayed. @@ -822,12 +796,12 @@ source X pixmap. Thus once you have put an image on a widget, it is nearly free to put the same image on many other widgets.

    If you are using a painting program to edit an image: the only way -to convince Fluid to read the image file again is to remove the image +to convince FLUID to read the image file again is to remove the image from all widgets that are using it (including ones in closed windows), -which will cause it to free it's internal copy, and then set the image -again. You may find it easier to exit Fluid and run it again. +which will cause it to free its internal copy, and then set the image +again. You may find it easier to exit FLUID and run it again. -

    Don't rely on how fltk crops images that are outside the widget, as +

    Don't rely on how FLTK crops images that are outside the widget, as this may change in future versions! The cropping of inside labels will probably be unchanged. @@ -838,57 +812,55 @@ and you want the image inside it, you must change the button's boxtype to FL_UP_FRAME (or another frame), otherwise when it is pushed it will erase the image. -

XBM (X bitmap files)

    +

    XBM (X bitmap files)

    -

    Fluid will read X bitmap files. These files have C source code to +

    FLUID will read X bitmap files. These files have C source code to define a bitmap. Sometimes they are stored with the ".h" or ".bm" extension rather than the standard ".xbm". -

    Fluid will output code to construct an Fl_Bitmap widget and use it +

    FLUID will output code to construct an Fl_Bitmap widget and use it to label the widget. The '1' bits in the bitmap are drawn using the -label color of the widget. You can change the color in Fluid. The +label color of the widget. You can change the color in FLUID. The '0' bits are transparent.

    The program "bitmap" on the X distribution does an ok job of editing bitmaps. -

XPM (X pixmap files)

GIF files

- -

(back to contents) + + -- cgit v1.2.3