FLUID for FLTK 1.4.0
|
Functions and Methods
Fluid can generate C functions, C++ functions, and methods in classes. Functions can contain widgets to build windows and dialogs. Code nodes can be used to add more source code to a function.
To generate a function, the function node must be created at the top level or inside a declaration block. If added inside a class node, this node generates a method inside that class.
Function nodes can contain code nodes and windows that in turn contain widgets. If the function node has no children, only a forward declaration will be created in the header, but no source code will be generated.
A function node at the top level or inside a declaration block generates a C or C++ function.
The Name field contains the function name and all arguments. If the Name field is left empty, Fluid will generate a typical 'main()' function.
If a function node has a name but no children, a forward declaration is generated in the header, but the implementation in the source file is omitted. This is used to reference functions in other modules.
If the function contains one or more Code nodes, the implementation code will be generated. The default return type is void
. Text in the Return Type field overrides the default type.
If the function contains one or more windows, a pointer to the first window will be returned. The default return type will match the window class.
Choosing static in the pulldown menu will generate the function static
in the source file. No forward declaration will be generated in the header file.
Choosing global will generate a forward declaration of the function in the header file and no static
attribute in the source file.
Additionally, if the C option is checked, the function will be declared as a plain C function in the header file.
The local option will generate a function in the source file with no static
attribute. No forward declaration will be generated in the header file.
A function node inside a class node generates a C++ method. If a method node has no children, the declaration is generated in the header, but no implementation in the source file.
If the method contains one or more Code nodes, an implementation will also be generated.
If the method contains at least one widget, a pointer to the topmost widget will be returned and the return type will be generated accordingly.
Class access can be defined with the pulldown menu. It provides a choice of private
, protected
, and public
.
Fluid recognizes the keyword static
or virtual
at the beginning of the return type* and will generate the declaration including the keyword, but will omit it in the implementation. The return type defaults still apply if there is no text after the keyword.
Users can define a comment text in the comment field. The first line of the comment will be shown in the widget browser. The comment text will be generated in the source file before the function.
FLUID recognizes default values in the argument list and generates them in the declaration, but omits them in the implementation.
A short function body can be appended in the Name field. With no child, this creates an inlined function in the header file.
Code
Code nodes hold arbitrary C++ code that is copied verbatim into the source code file. They are commonly used inside Function nodes.
Code nodes can be added inside Functions, Code Blocks, and Widget Classes.
The Code Properties panel features a syntax-highlighting C++ code editor. Some basic bracket and braces match checking is done when closing the dialog.
When inside a Function or Code Block, the C++ code is inserted directly. Inside a Widget Class, the code will be added to the constructor of the widget class.
Code Block
Code Blocks are used when a single function generates different GUI elements conditionally.
Code Blocks are used inside functions and methods.
Code Blocks can contain widgets, code, or more code blocks.
The two fields expect the code before and after the { ... }
statements. The second field can be empty.
Two consecutive Code Blocks can be used to generate else
/else if
statements by leaving the second field of the first node empty.
Declaration
Declarations can be added at the top level or inside classes and widget classes.
Declaration nodes are quite flexible and can be a simple variable declaration such as int i;
. But include statements are also allowed, as are type declarations, and comments. FLUID does its best to understand user intention, but the generated code should be verified by the user.
Declarations nodes at the top level can selectively generate code in the header and /or in the source file. If a declaration is inside a class, the user can select if the class member is private, protected, or public instead.
Declaration Block
Declaration Blocks are a way to selectively compile child nodes via preprocessor commands, typically #ifdef TEST
and #endif
.
Declaration Blocks can be created at the top level or inside classes.
Declaration Blocks can contain classes, functions, methods, declarations, and comments.
Users can select if the block is generated in the source file only, or in the header file as well. The two input fields are used to enter the line of code before and after the child nodes. Two consecutive Declaration Blocks can be used to generate #else
/#elif
style code by leaving the second field of the first node empty.
Class
FLUID can generate code to implement C++ classes. Classes can be used to keep dialogs and groups of UI elements organized. See Widget Class nodes as an alternative to implement compound widgets.
Class nodes can be created at top level or inside a Class or Widget Class node.
Class nodes can contain Functions, Declarations, Widgets, Data, and other classes.
The Name: and Subclass of: fields should be set to standard C++ class names.
Function nodes inside classes are implemented as methods. Constructors and destructors are recognized and implemented as such. Inlined data is declared as a static class member.
Note that methods without a code or widget node are only declared in the header file, but no code is generated for them in the source file.
Widget Class
The Widget Class node creates a new widget type by deriving a class from another widget class. These are often compound widgets derived from Fl_Group
. A less automated but more flexible way to implement compound widgets is the Class node.
Widget Class nodes can be created at top level or inside a Class or Widget Class node.
Widget Class nodes can contain Functions, Declarations, Widgets, Data, and other classes.
Widget Class nodes use the Widget panel to edit their properties. The super class can be set in the C++ tab in the Class field. If that field is empty, FLUID derives from Fl_Group
.
The Widget Class always creates a constructor with the common widget parameters:
If the super class name contains the text Window
, two more constructors and a common initializer method are created:
Code and Widget nodes are then added to the constructor. Function nodes are added as methods to the class. Declarations are added as class members. Data nodes generate static class members.
It may be useful to design compound widgets with a variable size. The Widget Panel provides a choice menu in the GUI tab's Position row under Children*. The options resize and reposition generate code to fix up the coordinates of the widget after instantiation.
Note that methods without a code or widget node are only declared in the header file, but no code is generated for them in the source file.
Comment
This node adds a comment block to the generated source code.
Comment nodes can be added inside Functions, Code Blocks, and Widget Classes. If a Comment node is the top node in a tree, it will appear in the source files even before the // generated by FLUID ...
line.
Comment blocks are generated by adding //
to the start of each line unless the first line of a comment starts with /
*
. In that case, FLUID assumes a correct block comment and will copy the text verbatim.
Comments can be generated in the header file, the source file, or both.
FLUID keeps a small database of predefined comments. Users can add reoccurring comment blocks, license information for example, to this database via the pulldown menu.
Comments can also be imported from an external file.
Inlined Data
The Data node makes it easy to inline data from an external file into the source code.
Data nodes can be added at the top level or inside Widget Classes, Classes, and Declaration Blocks.
At top level, or inside a Declaration Block, Data can be declared in source file only, static in source file, or in source and extern in header.
If Data is inside a Class node, it is always declared static
. The user can select private, protected, or public.
Data in binary mode will be stored in an unsigned char
array. The data size can be queried with sizeof()
. In Text mode, it will be stored as const char*
and terminated with a NUL
character.
In compressed mode, data will be compressed with zlib compress()
and stored in an unsigned char
array. A second variable, holding the original data size, is declared int
by appending _size
to the variable name.
The Variable Name should be a regular C++ name. The Filename field expects the path and name of a file, relative to the location of the .fl file.