Logo ROOT  
Reference Guide
 
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
115
116////////////////////////////////////////////////////////////////////////////////
117/// Constructor. The x, y, w and h define the position of the widget in
118/// its frame and the size of the widget. The unit is the size of a
119/// character. The rubberFlag defines how to move and to resize the
120/// widget when the frame is resized. Default is moving the X and Y
121/// position but keep the size of the widget.
122
133
134////////////////////////////////////////////////////////////////////////////////
135/// Save XY layout hints as a C++ statement(s) on output stream.
136
137void TGXYLayoutHints::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
138{
140 if (fFlag & kLRubberX) {
141 if (flag.Length() == 0)
142 flag = "TGXYLayoutHints::kLRubberX";
143 else
144 flag += " | TGXYLayoutHints::kLRubberX";
145 }
146 if (fFlag & kLRubberY) {
147 if (flag.Length() == 0)
148 flag = "TGXYLayoutHints::kLRubberY";
149 else
150 flag += " | TGXYLayoutHints::kLRubberY";
151 }
152 if (fFlag & kLRubberW) {
153 if (flag.Length() == 0)
154 flag = "TGXYLayoutHints::kLRubberW";
155 else
156 flag += " | TGXYLayoutHints::kLRubberW";
157 }
158 if (fFlag & kLRubberH) {
159 if (flag.Length() == 0)
160 flag = "TGXYLayoutHints::kLRubberH";
161 else
162 flag += " | TGXYLayoutHints::kLRubberH";
163 }
164
165 out << ", new TGXYLayoutHints(" << GetX() << ", " << GetY() << ", " << GetW() << ", " << GetH();
166
167 if (!flag.Length())
168 out << ")";
169 else
170 out << ", " << flag << ")";
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Constructor. The main is the frame for which this layout manager works.
175
177{
179 Int_t dummy;
180
181 fMain = main;
182 fList = main->GetList();
183 fFirst = kTRUE;
185
187
188 // get standard width an height of a character
189 fTWidth = gVirtualX->TextWidth(fs, "1234567890", 10) / 10;
190 gVirtualX->GetFontProperties(fs, fTHeight, dummy);
191
192 // the size of the main window are defined in units of a character
193 // but the system does not understand this. We have to recalculate
194 // the size into pixels.
195 width = main->GetWidth() * fTWidth;
196 height = main->GetHeight() * fTHeight;
197
198 main->Resize(width, height);
199}
200
201////////////////////////////////////////////////////////////////////////////////
202///copy constructor
203
206 fList(xyl.fList),
207 fMain(xyl.fMain),
209 fFirstWidth(xyl.fFirstWidth),
210 fFirstHeight(xyl.fFirstHeight),
211 fTWidth(xyl.fTWidth),
212 fTHeight(xyl.fTHeight)
213{
214}
215
216////////////////////////////////////////////////////////////////////////////////
217///assignment operator
218
220{
221 if(this!=&xyl) {
223 fList=xyl.fList;
224 fMain=xyl.fMain;
225 fFirst=xyl.fFirst;
226 fFirstWidth=xyl.fFirstWidth;
227 fFirstHeight=xyl.fFirstHeight;
228 fTWidth=xyl.fTWidth;
229 fTHeight=xyl.fTHeight;
230 }
231 return *this;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Recalculates the postion and the size of all widgets.
236
238{
239 TGFrameElement *ptr;
243 Int_t newX, newY;
245 Double_t temp;
246
247 if (!fList) return;
248
249 if (fFirst) {
250 // save the original size of the frame. It is used to determin
251 // if the user has changed the window
254 fFirst = kFALSE;
255 }
256
257 // get the factor to increase of window size
259 if (xFactor < 1.0) xFactor = 1.0;
261 if (yFactor < 1.0) yFactor = 1.0;
262
263 // set the position an size for each widget and call the layout
264 // function for each widget
265 TIter next(fList);
266 while ((ptr = (TGFrameElement *) next())) {
267 if (ptr->fState & kIsVisible) {
269 if (layout == 0)
270 continue;
271
272 temp = layout->GetX() * fTWidth ;
273 if (layout->GetFlag() & TGXYLayoutHints::kLRubberX)
274 temp *= xFactor;
275 newX = (Int_t)(temp + 0.5);
276
277 temp = layout->GetY() * fTHeight;
278 if (layout->GetFlag() & TGXYLayoutHints::kLRubberY)
279 temp *= yFactor;
280 newY = (Int_t)(temp + 0.5);
281
282 temp = layout->GetW() * fTWidth;
283 if (layout->GetFlag() & TGXYLayoutHints::kLRubberW)
284 temp *= xFactor;
285 newW = (UInt_t)(temp + 0.5);
286
287 temp = layout->GetH() * fTHeight;
288 if (layout->GetFlag() & TGXYLayoutHints::kLRubberH)
289 temp *= yFactor;
290 newH = (UInt_t)(temp + 0.5);
292 ptr->fFrame->Layout();
293 }
294 }
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Returns the original size of the frame.
299
306
307////////////////////////////////////////////////////////////////////////////////
308/// Save XY layout manager as a C++ statement(s) on output stream.
309
310void TGXYLayout::SavePrimitive(std::ostream &out, Option_t * /*option = ""*/)
311{
312 out << "new TGXYLayout(" << fMain->GetName() << ")";
313}
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
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
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:621
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:508
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:334
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) noexcept
TObject assignment operator.
Definition TObject.h:299
Basic string class.
Definition TString.h:138
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17