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 
18 class MyMainFrame : public TGMainFrame {
19 
20 private:
21  TGTextButton *test, *draw, *help, *ok, *cancel, *exit;
22 
23 public:
24  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
25  virtual ~MyMainFrame();
26 
27  ClassDef(MyMainFrame, 0)
28 };
29 
30 
31 MyMainFrame::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
51  cframe1->AddFrame(draw, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
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);
59  cframe1->AddFrame(help, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
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)");
77  cframe2->AddFrame(exit, new TGLayoutHints(kLHintsTop | kLHintsExpandX,
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 
94 MyMainFrame::~MyMainFrame()
95 {
96  // Clean up all widgets, frames and layouthints that were used
97  Cleanup();
98 }
99 
100 void buttonsLayout()
101 {
102  // Popup the GUI...
103  new MyMainFrame(gClient->GetRoot(), 350, 80);
104 }
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:32
kFixedWidth
@ kFixedWidth
Definition: GuiTypes.h:387
TGMainFrame
Definition: TGFrame.h:443
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:34
TGTextButton
Definition: TGButton.h:142
test
Definition: test.py:1
gClient
#define gClient
Definition: TGClient.h:166
h
#define h(i)
Definition: RSha256.hxx:106
TGVerticalFrame
Definition: TGFrame.h:411
TGLayoutHints
Definition: TGLayout.h:57
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TGClient.h
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
TGCompositeFrame
Definition: TGFrame.h:323
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102