Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
TGXYLayout.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Reiner Rohlfs 24/03/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TGXYLayout
14 \ingroup guiwidgets
15
16Is a layout manager where the position and the size of each widget
17in the frame are defined by X / Y - coordinates. The coordinates
18for each widget are defined by the TGXYLayoutHints. Therefore it
19is not possible to share a layout hint for several widgets.
20
21The coordinates (X, Y) and the size (W, H) are defined in units
22of the size of a typical character. Also the size of the
23TGCompositeFrame for which a TGXYLayout manager is used has to be
24defined in its constructor in units of the size of a character!
25
26It is not possible to use any other layout hint than the
27TGXYLayoutHints for this layout manager!
28
29The rubberFlag in the constructor of the TGLXYLayoutHins defines
30how the position and the size of a widget is recalculated if the
31size of the frame is increased:
32
33 - kLRubberX: The X - position (left edge) is increased by the same
34 factor as the width of the frame increases.
35 - kLRubberY: The Y - position (upper edge) is increased by the same
36 factor as the height of the frame increases.
37 - kLRubberW: The width of the widget is increased by the same
38 factor as the width of the frame increases.
39 - kLRubberH: The height of the widget is increased by the same
40 factor as the height of the frame increases.
41
42But the size never becomes smaller than defined by the
43TGXYLayoutHints and the X and Y coordinates becomes never smaller
44than defined by the layout hints.
45
46
47\class TGXYLayoutHints
48\ingroup guiwidgets
49
50This layout hint must be used for the TGXYLayout manager!
51
52Example how to use this layout manager:
53
54```
55TGMyFrame::TGMyFrame()
56 : TGMainFrame(gClient->GetRoot(), 30, 12)
57 // frame is 30 character long and 12 character heigh
58{
59 SetLayoutManager(new TGXYLayout(this));
60
61 // create a button of size 8 X 1.8 at position 20 / 1
62 TGTextButton * button;
63 button = new TGTextButton(this, "&Apply", 1);
64 AddFrame(button, new TGXYLayoutHints(20, 1, 8, 1.8));
65
66 // create a listbox of size 18 X 10 at position 1 / 1.
67 // The height will increase if the frame height increases
68 TGListBox * listBox;
69 listBox = new TGListBox(this, 2);
70 AddFrame(listBox, new TGXYLayoutHints(1, 1, 18, 10,
71 TGXYLayoutHints::kLRubberX |
72 TGXYLayoutHints::kLRubberY |
73 TGXYLayoutHints::kLRubberH ));
74 .
75 .
76 .
77}
78```
79
80Normally there is one layout hint per widget. Therefore these
81can be deleted like in the following example in the destructor
82of the frame:
83
84```
85TGMyFrame::~TGMyFrame()
86{
87 // Destructor, deletes all frames and their layout hints.
88
89 TGFrameElement *ptr;
90
91 // delete all frames and layout hints
92 if (fList) {
93 TIter next(fList);
94 while ((ptr = (TGFrameElement *) next())) {
95 if (ptr->fLayout)
96 delete ptr->fLayout;
97 if (ptr->fFrame)
98 delete ptr->fFrame;
99 }
100 }
101}
102```
103
104*/
105
106
107#include "TGXYLayout.h"
108#include "TGFrame.h"
109#include "TGLabel.h"
110#include "TVirtualX.h"
111
112#include <iostream>
113
114
117
118////////////////////////////////////////////////////////////////////////////////
119/// Constructor. The x, y, w and h define the position of the widget in
120/// its frame and the size of the widget. The unit is the size of a
121/// character. The rubberFlag defines how to move and to resize the
122/// widget when the frame is resized. Default is moving the X and Y
123/// position but keep the size of the widget.
124
135
136////////////////////////////////////////////////////////////////////////////////
137/// Save XY layout hints as a C++ statement(s) on output stream.
138
139void TGXYLayoutHints::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
140{
142 if (fFlag & kLRubberX) {
143 if (flag.Length() == 0)
144 flag = "TGXYLayoutHints::kLRubberX";
145 else
146 flag += " | TGXYLayoutHints::kLRubberX";
147 }
148 if (fFlag & kLRubberY) {
149 if (flag.Length() == 0)
150 flag = "TGXYLayoutHints::kLRubberY";
151 else
152 flag += " | TGXYLayoutHints::kLRubberY";
153 }
154 if (fFlag & kLRubberW) {
155 if (flag.Length() == 0)
156 flag = "TGXYLayoutHints::kLRubberW";
157 else
158 flag += " | TGXYLayoutHints::kLRubberW";
159 }
160 if (fFlag & kLRubberH) {
161 if (flag.Length() == 0)
162 flag = "TGXYLayoutHints::kLRubberH";
163 else
164 flag += " | TGXYLayoutHints::kLRubberH";
165 }
166
167 out << ", new TGXYLayoutHints(" << GetX() << ", " << GetY() << ", " << GetW() << ", " << GetH();
168
169 if (!flag.Length())
170 out << ")";
171 else
172 out << ", " << flag << ")";
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Constructor. The main is the frame for which this layout manager works.
177
179{
181 Int_t dummy;
182
183 fMain = main;
184 fList = main->GetList();
185 fFirst = kTRUE;
187
189
190 // get standard width an height of a character
191 fTWidth = gVirtualX->TextWidth(fs, "1234567890", 10) / 10;
192 gVirtualX->GetFontProperties(fs, fTHeight, dummy);
193
194 // the size of the main window are defined in units of a character
195 // but the system does not understand this. We have to recalculate
196 // the size into pixels.
197 width = main->GetWidth() * fTWidth;
198 height = main->GetHeight() * fTHeight;
199
200 main->Resize(width, height);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204///copy constructor
205
208 fList(xyl.fList),
209 fMain(xyl.fMain),
211 fFirstWidth(xyl.fFirstWidth),
212 fFirstHeight(xyl.fFirstHeight),
213 fTWidth(xyl.fTWidth),
214 fTHeight(xyl.fTHeight)
215{
216}
217
218////////////////////////////////////////////////////////////////////////////////
219///assignment operator
220
222{
223 if(this!=&xyl) {
225 fList=xyl.fList;
226 fMain=xyl.fMain;
227 fFirst=xyl.fFirst;
228 fFirstWidth=xyl.fFirstWidth;
229 fFirstHeight=xyl.fFirstHeight;
230 fTWidth=xyl.fTWidth;
231 fTHeight=xyl.fTHeight;
232 }
233 return *this;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Recalculates the postion and the size of all widgets.
238
240{
241 TGFrameElement *ptr;
245 Int_t newX, newY;
247 Double_t temp;
248
249 if (!fList) return;
250
251 if (fFirst) {
252 // save the original size of the frame. It is used to determin
253 // if the user has changed the window
256 fFirst = kFALSE;
257 }
258
259 // get the factor to increase of window size
261 if (xFactor < 1.0) xFactor = 1.0;
263 if (yFactor < 1.0) yFactor = 1.0;
264
265 // set the position an size for each widget and call the layout
266 // function for each widget
267 TIter next(fList);
268 while ((ptr = (TGFrameElement *) next())) {
269 if (ptr->fState & kIsVisible) {
271 if (layout == 0)
272 continue;
273
274 temp = layout->GetX() * fTWidth ;
275 if (layout->GetFlag() & TGXYLayoutHints::kLRubberX)
276 temp *= xFactor;
277 newX = (Int_t)(temp + 0.5);
278
279 temp = layout->GetY() * fTHeight;
280 if (layout->GetFlag() & TGXYLayoutHints::kLRubberY)
281 temp *= yFactor;
282 newY = (Int_t)(temp + 0.5);
283
284 temp = layout->GetW() * fTWidth;
285 if (layout->GetFlag() & TGXYLayoutHints::kLRubberW)
286 temp *= xFactor;
287 newW = (UInt_t)(temp + 0.5);
288
289 temp = layout->GetH() * fTHeight;
290 if (layout->GetFlag() & TGXYLayoutHints::kLRubberH)
291 temp *= yFactor;
292 newH = (UInt_t)(temp + 0.5);
294 ptr->fFrame->Layout();
295 }
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Returns the original size of the frame.
301
308
309////////////////////////////////////////////////////////////////////////////////
310/// Save XY layout manager as a C++ statement(s) on output stream.
311
312void TGXYLayout::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
313{
314 out << "new TGXYLayout(" << fMain->GetName() << ")";
315}
Handle_t FontStruct_t
Pointer to font structure.
Definition GuiTypes.h:39
int main()
Definition Prototype.cxx:12
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kIsVisible
Definition TGFrame.h:33
@ kLHintsNormal
Definition TGLayout.h:32
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
#define gVirtualX
Definition TVirtualX.h:337
T1 fFirst
Definition X11Events.mm:86
The base class for composite widgets (menu bars, list boxes, etc.).
Definition TGFrame.h:289
TGLayoutHints * fLayout
Definition TGLayout.h:114
TGFrame * fFrame
Definition TGLayout.h:112
void MoveResize(Int_t x, Int_t y, UInt_t w=0, UInt_t h=0) override
Move and/or resize the frame.
Definition TGFrame.cxx:629
UInt_t GetHeight() const
Definition TGFrame.h:227
virtual void Layout()
Definition TGFrame.h:201
UInt_t GetWidth() const
Definition TGFrame.h:226
static FontStruct_t GetDefaultFontStruct()
Static returning label default font struct.
Definition TGLabel.cxx:509
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Frame layout manager.
Definition TGLayout.h:135
const char * GetName() const override
Return unique name, used in SavePrimitive methods.
Definition TGWindow.cxx:336
This layout hint must be used for the TGXYLayout manager!
Definition TGXYLayout.h:19
Double_t GetX() const
Definition TGXYLayout.h:40
TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h, UInt_t rubberFlag=kLRubberX|kLRubberY)
Constructor.
Double_t fY
y - position of widget
Definition TGXYLayout.h:23
Double_t fW
width of widget
Definition TGXYLayout.h:24
Double_t fH
height of widget
Definition TGXYLayout.h:25
Double_t GetH() const
Definition TGXYLayout.h:43
Double_t GetW() const
Definition TGXYLayout.h:42
UInt_t fFlag
rubber flag
Definition TGXYLayout.h:26
void SavePrimitive(std::ostream &out, Option_t *="") override
Save XY layout hints as a C++ statement(s) on output stream.
Double_t fX
x - position of widget
Definition TGXYLayout.h:22
Double_t GetY() const
Definition TGXYLayout.h:41
Is a layout manager where the position and the size of each widget in the frame are defined by X / Y ...
Definition TGXYLayout.h:58
Int_t fTWidth
text width of a default character "1234567890" / 10
Definition TGXYLayout.h:68
TList * fList
list of frames to arrange
Definition TGXYLayout.h:61
TGXYLayout(const TGXYLayout &)
copy constructor
UInt_t fFirstWidth
original width of the frame fMain
Definition TGXYLayout.h:65
UInt_t fFirstHeight
original height of the frame fMain
Definition TGXYLayout.h:66
void Layout() override
Recalculates the postion and the size of all widgets.
TGCompositeFrame * fMain
container frame
Definition TGXYLayout.h:62
TGXYLayout & operator=(const TGXYLayout &)
assignment operator
Int_t fTHeight
text height
Definition TGXYLayout.h:69
Bool_t fFirst
flag to determine the first call of Layout()
Definition TGXYLayout.h:64
void SavePrimitive(std::ostream &out, Option_t *="") override
Save XY layout manager as a C++ statement(s) on output stream.
TGDimension GetDefaultSize() const override
Returns the original size of the frame.
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:302
Basic string class.
Definition TString.h:139
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17