Chapter 4. Examples
Prev | Part I. The Basics | Next

## Chapter 4. Examples

## hello

The `hello.rb` example program is about as short as it gets for a working FXRuby program. Use this as a starting point for understanding the basic elements of an FXRuby program, especially if you're new to GUI programming in general.

## hello2

The `hello2.rb` example kicks it up a notch by adding an icon and tooltip to the button from the `hello.rb` example.

## scribble

The `scribble.rb` example is a good demonstration of how to obtain a device context for a window (in this case, an `FXCanvas`) and draw into that window. It also provides a basic demonstration of how FOX's GUI updating mechanism can be used to automatically update the state of widgets based on the application's state. Observe the "Clear" button becoming enabled and disabled (greyed-out) depending on whether the canvas is currently "dirty" or "clean", and then see how this updating is actually handled in the code.

## button

The `button.rb` example program shows off the various options (or button styles) for `FXButton` widgets.

## datatarget

The `datatarget.rb` example program demonstrates most or all of the widgets that can work with FOX data targets (that is, instances of class `FXDataTarget`). Data targets are special objects that have a a string, float or integer value associated with them, and can interact with widgets to keep the data target's value in sync with the widget's setting. For example, you can create a data target with a string value and attach that to a text field widget. When the user types a new value in the text field, the data target's value is automatically updated; and when the data target's value is changed, the text field will update its setting. Since a single data targets can be attached to multiple widgets, this can be a useful way to keep multiple controls for the same logical value in sync with each other.

## dialog

The `dialog.rb` example is a simple program demonstrating how to construct and display modal and non-modal dialog boxes.

## dirlist

The `dirlist.rb` example program demonstrates the `FXDirList` widget. The directory list is a special kind of tree list, where each tree item represents a directory (or folder) in the file system.

## iconlist

The `iconlist.rb` example program demonstrates the `FXIconList` widget. An icon list is a special kind of list widget that can display its contents in one of three basic modes (details mode, small icons mode or large icons mode). The first screenshot below shows an icon list in details mode, while the second shows the same icon list in "big icons" mode.

## mditest

The `mditest.rb` example program demonstrates FOX's Multiple Document Interface (MDI) capabilities, specifically the `FXMDIClient` and `FXMDIChild` classes.

## groupbox

The `groupbox.rb` example program is a kind of "periodic table of widgets" demonstration, FOX-style. It shows off a lot of the FOX widgets as well as providing a good exercise of FOX's layout managers.

## header

The `header.rb` example program mainly demonstrates the `FXHeader` widget and the `FXSplitter` layout manager.

## image

The `image.rb` example demonstrates how to draw directly into an `FXImage` object and then "draw" that image into a canvas.

## splitter

The `splitter.rb` example demonstrates the `FXSplitter` layout manager. It also provides an example of the `FXTreeList` widget (on the left side of the split) and the `FXMatrix` layout manager (in the middle pane).

## foursplit

The `foursplit.rb` example program demonstrates the `FX4Splitter` layout manager. This four-way split is especially useful for CAD-type programs where it's necessary to show multiple views of the model simultaneously.

## shutter

The `shutter.rb` example provides a simple demonstration of the `FXShutter` widget, with the skeleton of a PIM-type application. The very nice icons used for this program are courtesy of Gort's Icons.

## tabbook

The `tabbook.rb` example exists mainly to demonstrate the `FXTabBook` widget, but shows off a few other features in the process.

## table

The `table.rb` example features the `FXTable` widget, sometimes known as a "grid" or "spreadsheet" widget in other toolkits.

## gltest

The `gltest.rb` example program demonstrates how to create a basic OpenGL canvas (i.e. an instance of the `FXGLCanvas` widget) and draw into it. It also demonstrates how to use timers and chores. This example requires the Ruby/OpenGL extension, available from the Ruby Application Archive.

## glviewer

The `glviewer.rb` example program demonstrates how to use the `FXGLViewer` widget and draw various kinds of GL objects into it. It can also be used as model for a fairly complicated FXRuby application, since it includes a lot of typical features (like a menu bar, toolbar, status line, etc.).

## imageviewer

Like the `glviewer.rb` example, the `imageviewer.rb` can be used as a model for a typical full-featured GUI application, with a menu bar, toolbar, and so forth. It also features the `FXImageView` widget.

## dilbert

The `dilbert.rb` example fetches the "Daily Dilbert" cartoon and displays it in a window. This was just a fun little exercise for me, but it does provide a more bare-bones example of the `FXImageView` widget than that provided by the (more complicated) `imageviewer.rb` example.

This example program requires the html-parser extension, available from the Ruby Application Archive.

## raabrowser

The `raabrowser.rb` example program shows a treelist view of the current Ruby Application Archive (RAA) contents, and product-specific information for the currently selected product in the panel on the right. This is a good demonstration of the following features:

- the `FXSplitter` layout manager, used to split the left side (containing the tree list) from the right side (containing the information panel). If the panel on the left is too narrow to see all of its contents (especially when you've expanded the tree) try resizing the split.

- the `FXTreeList` widget, used to display the RAA contents.

- data targets (i.e. instances of class `FXDataTarget`), which are used for the contents of the fields in the information panel.

This example program requires the SOAP4R extension.

## babelfish

The `babelfish.rb` example program, like the `raabrowser.rb` example, depends on the SOAP4R extension. Other than that it doesn't bring anything new to the table.

## browser

The `browser.rb` example program is mainly a "me too" for the class browser distributed with Ruby/GTK. It's hard for me to get excited about it, but here it is.

Prev | Up | Next
Putting It All Together | Home | Chapter 5. FXRuby's Message-Target System