Sample3: A quick view to the Form Widget.

This example shows a simple use of the FORM container object. Note there are no numbers in the code to specify object positions and dimensions. This is because the FORM object automatically positions and resizes children objects.
You can modify the object text or its font, the layout will always remain consistent.
Also, in response to a resize request to the program's window, all FORM objects in the window will rearrange their children to keep the layout consistent.

/* C version */ #include <stdio.h> #include <stdlib.h> #include "mgui.h"
/* Program termination callback */
void ExitCB(MOBJECT obj, void *a, void *b)
{
  MShellDestroy((MOBJECT)b);
  MGUITerm();
  exit(0);
}

void MGUIMain(int argc, char **argv)
{
   MOBJECT shell, rform, cform, pb, lbl;

   shell = MCreateShell("Example 3", SF_NO_CLOSE);

   rform = MCreateRowForm(shell); 
   lbl = MCreateLabel(rform, "This Label establishes the window width", HELV_MEDIUM);
   MObjectSetShadow(lbl, WS_SHADOW_IN, 1, 0); 
   lbl = MCreateLabel(rform, "Small resizeable Label", HELV_MEDIUM);
   MObjectSetShadow(lbl, WS_SHADOW_IN, 1, 0); 
   lbl = MCreateLabel(rform, "Unresizeable Label", HELV_MEDIUM); 
   MObjectSetShadow(lbl, WS_SHADOW_IN, 1, 0); 
   MObjectSetResize(lbl, False, False); 

   cform = MCreateColForm(shell); 
   pb = MCreatePButton(cform, "dummy", TIMES_MEDIUM); 
   pb = MCreatePButton(cform, "Quit", TIMES_MEDIUM);
   MObjectSetAttachment(pb, True, True, False, True);
   MPButtonSetCallback(pb, ExitCB, shell);
   MShellRealize(shell);
   MMainLoop();
}
Objects which have a SHELL as parent are actually contained in a main FORM (SHELL's child), so 'cform' is arranged on bottom of  'rform'. The window dimensions equal the main FORM ones, increased by its margins. The FORM width is determined by its largest child Object, while its height is equal to the sum of all children heights plus the spacing offsets.
The container 'rform' has three LABEL children with a shadow imposed to make their dimensions visible. The first object forces the parent width because it's the largest child. The second is enlarged by the FORM since it's resizeable. The last LABEL is moved since its resize capability has been inhibited and its natural width is smaller than it's parent one.
The ColForm 'cform' contains two push buttons arranged by columns (in the same row). Its natural width is smaller than it's parent one and both children are not resizeable in the horizontal direction. However, since its left and right ends are attached to the same container, 'cform' is resized horizontally to match 'rform' width. The size increase affects only the children relative spacing since their relative attachment has been removed.

// C++ version
#include <stdio.h>
#include "mguipp.h"

class CaAppl : public CmAppl {
public:
   void start(int, char **);
};

CaAppl appInstance;

class CaMainWindow : public CmShell {
public:
   CaMainWindow(const char *title, int flags);
   void exitCB(void);
};

void CaMainWindow::exitCB(void)
{
   delete this;
   CmAppl::end(0);
}

void CaAppl::start(int argc, char **argv)
{
   CaMainWindow *win = new CaMainWindow("Example 3", SF_NO_CLOSE);
   win->realize();
   mainLoop();
}

CaMainWindow::CaMainWindow(const char *title, int flags)
: CmShell(title, flags)
{
   CmRowForm *rform;
   CmColForm *cform;
   CmPushButton *pb;
   CmLabel *lbl;

   rform = new CmRowForm(this); 
   lbl = new CmLabel(rform, "This Label establishes the window width", HELV_MEDIUM);
   lbl->setShadow(WS_SHADOW_IN, 1, 0); 
   lbl = new CmLabel(rform, "Small resizeable Label", HELV_MEDIUM);
   lbl->setShadow(WS_SHADOW_IN, 1, 0); 
   lbl = new CmLabel(rform, "Unresizeable Label", HELV_MEDIUM); 
   lbl->setShadow(WS_SHADOW_IN, 1, 0); 
   lbl->setResize(False, False); 

   cform = new CmColForm(this); 
   pb = new CmPushButton(cform, "dummy", TIMES_MEDIUM); 
   pb = new CmPushButton(cform, "Quit", TIMES_MEDIUM);
   pb->setAttachment(True, True, False, True);
   pb->setCallback(this, (VOID_CB)exitCB);
}





Screenshot

Back