ROOT
v6-26
Reference Guide
Loading...
Searching...
No Matches
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
41
hframe1->
AddFrame
(
test
,
new
TGLayoutHints
(
kLHintsTop
|
kLHintsExpandX
,
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,
48
kHorizontalFrame
|
kFixedWidth
);
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,
66
kHorizontalFrame
|
kFixedWidth
);
67
ok =
new
TGTextButton
(cframe2,
"OK"
);
68
// to share whole parent space we need to use kLHintsExpandX layout hints
69
cframe2->
AddFrame
(ok,
new
TGLayoutHints
(
kLHintsTop
|
kLHintsExpandX
,
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
}
kFixedWidth
@ kFixedWidth
Definition
GuiTypes.h:387
kHorizontalFrame
@ kHorizontalFrame
Definition
GuiTypes.h:382
h
#define h(i)
Definition
RSha256.hxx:106
UInt_t
unsigned int UInt_t
Definition
RtypesCore.h:46
ULong_t
unsigned long ULong_t
Definition
RtypesCore.h:55
ClassDef
#define ClassDef(name, id)
Definition
Rtypes.h:325
TGButton.h
TGClient.h
gClient
#define gClient
Definition
TGClient.h:157
kLHintsCenterX
@ kLHintsCenterX
Definition
TGLayout.h:25
kLHintsTop
@ kLHintsTop
Definition
TGLayout.h:27
kLHintsExpandX
@ kLHintsExpandX
Definition
TGLayout.h:30
TGCompositeFrame
The base class for composite widgets (menu bars, list boxes, etc.).
Definition
TGFrame.h:287
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition
TGFrame.cxx:1117
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition
TGLayout.h:50
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition
TGFrame.h:398
TGTextButton
Yield an action as soon as it is clicked.
Definition
TGButton.h:142
TGVerticalFrame
A composite frame that layout their children in vertical way.
Definition
TGFrame.h:375
TGWindow
ROOT GUI Window base class.
Definition
TGWindow.h:23
test
Definition
test.py:1
tutorials
gui
buttonsLayout.C
ROOT v6-26 - Reference Guide Generated on Mon Sep 11 2023 21:03:03 (GVA Time) using Doxygen 1.9.8