Dialog Editor

The dialog editor is integrated into the library and can be used at runtime. This was done because most ideas on how to fine tune the layout of a program come when one actually uses the program. Step 1: Write the Code
#include <toad/toad.hh>
#include <toad/dialog.hh>
#include <toad/textfield.hh>
#include <toad/pushbutton.hh>
 
class TMyWindow:
  public TDialog
{
  public:
    TMyWindow(TWindow *parent, const string &title);
 
    void printData();
 
    // the data we're going to edit
    TTextModel name, surname;
    TUnsignedModel age;
};
 
int
main(int argc, char **argv, char **envv)
{
  toad::initialize(argc, argv, envv);
  {
    // tell TOAD where to store/read the resource files
    TOADBase::setResourcePrefix("file://resource/");   
    TMyWindow(NULL, "MyWindow");
    // start the application
    toad::mainLoop();
  }
  toad::terminate();
  return 0;
}
 
TMyWindow::TMyWindow(TWindow *parent, const string &title):
  TDialog(parent, title)
{
  // create the widgets
  TTextField *tf;
  tf = new TTextField(this, "name", &name);
  tf = new TTextField(this, "surname", &surname);
  tf = new TTextField(this, "age", &age);
 
  TPushButton *pb;
  pb = new TPushButton(this, "print");
  CONNECT(pb->;sigActivate, this, printData);
  pb = new TPushButton(this, "quit");
  CONNECT(pb->sigActivate, this, closeRequest);
 
  // set a resource name for the layout
  doLayout("MyWindow");
}  
 
void
TMyWindow::printData()
{
  // print the data                                
  cout << "Name   : " << name << endl                    
       << "Surname: " << surname << endl                    
       << "Age    : " << age << endl;                    
}
Step 2: Execute your program
make
./program --layout-editor
When no earlier layout exists all the widgets are placed in the upper left corner of the window.

Step 3: Layout your widgets
Enable the layout editor and use the mouse to move and resize the widgets. You can even add additional graphical elements. The dialog editor used here is names "TDialogLayout", which is the default for dialog windows. But one can easily use other layout algorithms, for example TSpringLayout.

Step 4: Fin
Once the layout is finished you can save the layout.