Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
buttonsLayout.C File Reference

Detailed Description

This macro gives an example of different buttons' layout.

To run it do either:

.x buttonsLayout.C
.x buttonsLayout.C++
#include <TGClient.h>
#include <TGButton.h>
class MyMainFrame : public TGMainFrame {
private:
TGTextButton *test, *draw, *help, *ok, *cancel, *exit;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
~MyMainFrame() override;
ClassDef(MyMainFrame, 0)
};
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
{
// Create a container frames containing buttons
// one button is resized up to the parent width.
// Note! this width should be fixed!
TGVerticalFrame *hframe1 = new TGVerticalFrame(this, 170, 50, kFixedWidth);
test = new TGTextButton(hframe1, "&Test ");
// to take whole space we need to use kLHintsExpandX layout hints
hframe1->AddFrame(test, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 2, 2));
AddFrame(hframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
// two buttons are resized up to the parent width.
// Note! this width should be fixed!
draw = new TGTextButton(cframe1, "&Draw");
// to share whole parent space we need to use kLHintsExpandX layout hints
cframe1->AddFrame(draw, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
// button background will be set to yellow
ULong_t yellow;
gClient->GetColorByName("yellow", yellow);
help = new TGTextButton(cframe1, "&Help");
help->ChangeBackground(yellow);
cframe1->AddFrame(help, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
AddFrame(cframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
// three buttons are resized up to the parent width.
// Note! this width should be fixed!
ok = new TGTextButton(cframe2, "OK");
// to share whole parent space we need to use kLHintsExpandX layout hints
cframe2->AddFrame(ok, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2));
cancel = new TGTextButton(cframe2, "Cancel ");
cframe2->AddFrame(cancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 3, 2, 2, 2));
exit = new TGTextButton(cframe2, "&Exit ", "gApplication->Terminate(0)");
cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 2, 2));
AddFrame(cframe2, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
SetWindowName("Buttons' Layout");
// gives min/max window size + a step of x,y incrementing
// between the given sizes
SetWMSizeHints(200, 80, 320, 320, 1, 1);
// important for layout algorithm
Resize(GetDefaultSize());
MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Clean up all widgets, frames and layouthints that were used
Cleanup();
}
void buttonsLayout()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 350, 80);
}
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
#define h(i)
Definition RSha256.hxx:106
unsigned long ULong_t
Definition RtypesCore.h:55
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDef(name, id)
Definition Rtypes.h:342
#define gClient
Definition TGClient.h:157
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:287
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
ROOT GUI Window base class.
Definition TGWindow.h:23
Author
Ilka Antcheva 1/12/2006

Definition in file buttonsLayout.C.