Next Previous Contents

2. Getting started

To begin our introduction to TinyWidgets, we'll start with the simplest program possible. This program will create a 200x200 pixel window.

/* base.c */

#include <TinyWidgets/tnWidgets.h>

int main( int   argc,
          char *argv[] )
    TN_WIDGETS *main_window,*window;

    main_window = tnAppInitialize(argc, argv);

    window = tnCreateWidget (TN_WINDOW,main_window,50,50,TN_HEIGHT,200, TN_WIDT
    tnMainLoop ();

/* example-end */

You can compile the above program with gcc using:
% gcc base.c -o base -ltnW -lnano-X

All programs will of course include the header tnWidgets.h which declares the variables, functions, structures etc. that will be used in your TinyWidgets application.

The next line:

        tnAppInitialize (argc, argv);

will be called in all TinyWidgets applications. This sets up a few things for us and then proceeds to call GrOpen() which opens a socket connection with the Nano-X server . This function initializes the library for use. As of yet there are no provisions for handling the command line parameters but it has been included for later implementation.

The next line creates and displays a window.

window = tnCreateWidget (TN_WINDOW,main_window,50,50,TN_HEIGHT,200, TN_WIDTH,20

The tnCreateWidget is a generalised function which accepts variable number of parameters. Only the first 4 parameters are mandatory. They are widget type, parent widget, xposition & yposition relative to parent. The rest of the parameters are optional and default values will be taken if they are not specified. Also the optional parameters can be specified in any order but they have to be specified as pairs of (parameter type, value). For eg to specify the height of the widget you have got to specify it as TN_HEIGHT, 200. The argument list must be terminated with TN_END to indicate end of parameter list. The use of this function will be more clear with further examples.

The last line enters the tnWidgets main processing loop.

        tnMainLoop ();

This is another call you will see in every TinyWidgets application. When control reaches this point, tnWidgets will sleep waiting for Nano-X events (such as button or key presses). In our simple example however, events are ignored. To end the application, you will have to call tnEndApp (within a call back).
Next Previous Contents