Logo ROOT  
Reference Guide
buttonsLayout.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of different buttons' layout.
4/// To run it do either:
5/// ~~~
6/// .x buttonsLayout.C
7/// .x buttonsLayout.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Ilka Antcheva 1/12/2006
13
14
15#include <TGClient.h>
16#include <TGButton.h>
17
18class MyMainFrame : public TGMainFrame {
19
20private:
21 TGTextButton *test, *draw, *help, *ok, *cancel, *exit;
22
23public:
24 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
25 virtual ~MyMainFrame();
26
27 ClassDef(MyMainFrame, 0)
28};
29
30
31MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
32 TGMainFrame(p, w, h)
33{
34 // Create a container frames containing buttons
35
36 // one button is resized up to the parent width.
37 // Note! this width should be fixed!
38 TGVerticalFrame *hframe1 = new TGVerticalFrame(this, 170, 50, kFixedWidth);
39 test = new TGTextButton(hframe1, "&Test ");
40 // to take whole space we need to use kLHintsExpandX layout hints
42 2, 0, 2, 2));
43 AddFrame(hframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
44
45 // two buttons are resized up to the parent width.
46 // Note! this width should be fixed!
47 TGCompositeFrame *cframe1 = new TGCompositeFrame(this, 170, 20,
49 draw = new TGTextButton(cframe1, "&Draw");
50 // to share whole parent space we need to use kLHintsExpandX layout hints
52 2, 2, 2, 2));
53
54 // button background will be set to yellow
55 ULong_t yellow;
56 gClient->GetColorByName("yellow", yellow);
57 help = new TGTextButton(cframe1, "&Help");
58 help->ChangeBackground(yellow);
60 2, 2, 2, 2));
61 AddFrame(cframe1, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
62
63 // three buttons are resized up to the parent width.
64 // Note! this width should be fixed!
65 TGCompositeFrame *cframe2 = new TGCompositeFrame(this, 170, 20,
67 ok = new TGTextButton(cframe2, "OK");
68 // to share whole parent space we need to use kLHintsExpandX layout hints
70 3, 2, 2, 2));
71
72 cancel = new TGTextButton(cframe2, "Cancel ");
73 cframe2->AddFrame(cancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
74 3, 2, 2, 2));
75
76 exit = new TGTextButton(cframe2, "&Exit ","gApplication->Terminate(0)");
78 2, 0, 2, 2));
79
80 AddFrame(cframe2, new TGLayoutHints(kLHintsCenterX, 2, 2, 5, 1));
81
82 SetWindowName("Buttons' Layout");
83
84 // gives min/max window size + a step of x,y incrementing
85 // between the given sizes
86 SetWMSizeHints(200, 80, 320, 320, 1, 1);
87 MapSubwindows();
88 // important for layout algorithm
89 Resize(GetDefaultSize());
90 MapWindow();
91}
92
93
94MyMainFrame::~MyMainFrame()
95{
96 // Clean up all widgets, frames and layouthints that were used
97 Cleanup();
98}
99
100void buttonsLayout()
101{
102 // Popup the GUI...
103 new MyMainFrame(gClient->GetRoot(), 350, 80);
104}
@ kFixedWidth
Definition: GuiTypes.h:387
@ kHorizontalFrame
Definition: GuiTypes.h:382
#define h(i)
Definition: RSha256.hxx:106
unsigned int UInt_t
Definition: RtypesCore.h:46
unsigned long ULong_t
Definition: RtypesCore.h:55
#define ClassDef(name, id)
Definition: Rtypes.h:325
#define gClient
Definition: TGClient.h:166
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
Definition: test.py:1