Logo ROOT  
Reference Guide
TGXYLayout.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Reiner Rohlfs 24/03/2002
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2002, 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 // //
14 // TGXYLayout //
15 // //
16 // Is a layout manager where the position and the size of each widget //
17 // in the frame are defined by X / Y - coordinates. The coordinates //
18 // for each widget are defined by the TGXYLayoutHints. Therefore it //
19 // is not possible to share a layout hint for several widgets. //
20 // //
21 // The coordinates (X, Y) and the size (W, H) are defined in units //
22 // of the size of a typical character. Also the size of the //
23 // TGCompositeFrame for which a TGXYLayout manager is used has to be //
24 // defined in its constructor in units of the size of a character! //
25 // //
26 // It is not possible to use any other layout hint than the //
27 // TGXYLayoutHints for this layout manager! //
28 // //
29 // The rubberFlag in the constructor of the TGLXYLayoutHints defines //
30 // how the position and the size of a widget is recalculated if the //
31 // size of the frame is increased: //
32 // - kLRubberX: The X - position (left edge) is increased by the same //
33 // factor as the width of the frame increases. //
34 // - kLRubberY: The Y - position (upper edge) is increased by the same //
35 // factor as the height of the frame increases. //
36 // - kLRubberW: The width of the widget is increased by the same //
37 // factor as the width of the frame increases. //
38 // - kLRubberY: The height of the widget is increased by the same //
39 // factor as the height of the frame increases. //
40 // But the size never becomes smaller than defined by the //
41 // TGXYLayoutHints and the X and Y coordinates becomes never smaller //
42 // than defined by the layout hints. //
43 // //
44 // TGXYLayoutHints //
45 // //
46 // This layout hint must be used for the TGXYLouyout manager! //
47 // //
48 // //
49 // Example how to use this layout manager: //
50 // //
51 // TGMyFrame::TGMyFrame() //
52 // : TGMainFrame(gClient->GetRoot(), 30, 12) //
53 // // frame is 30 characters wide and 12 characters high //
54 // { //
55 // SetLayoutManager(new TGXYLayout(this)); //
56 // //
57 // // create a button of size 8 X 1.8 at position 20 / 1 //
58 // TGTextButton * button; //
59 // button = new TGTextButton(this, "&Apply", 1); //
60 // AddFrame(button, new TGXYLayoutHints(20, 1, 8, 1.8)); //
61 // //
62 // // create a listbox of size 18 X 10 at position 1 / 1. //
63 // // The height will increase if the frame height increases //
64 // TGListBox *listBox; //
65 // listBox = new TGListBox(this, 2); //
66 // AddFrame(listBox, new TGXYLayoutHints(1, 1, 18, 10, //
67 // TGXYLayoutHints::kLRubberX | //
68 // TGXYLayoutHints::kLRubberY | //
69 // TGXYLayoutHints::kLRubberH)); //
70 // . //
71 // . //
72 // . //
73 // } //
74 // //
75 // Normaly there is one layout hint per widget. Therefore these //
76 // can be deleted like in the following example in the desctuctor //
77 // of the frame: //
78 // //
79 // TGMyFrame::~TGMyFrame() //
80 // { //
81 // // Destructor, deletes all frames and their layout hints. //
82 // //
83 // // delete all frames and layout hints //
84 // Cleanup(); //
85 // } //
86 // //
87 //////////////////////////////////////////////////////////////////////////
88 
89 #ifndef ROOT_TGXYLayout
90 #define ROOT_TGXYLayout
91 
92 #include "TGLayout.h"
93 
94 
96 
97 protected:
98  Double_t fX; // x - position of widget
99  Double_t fY; // y - position of widget
100  Double_t fW; // width of widget
101  Double_t fH; // height of widget
102  UInt_t fFlag; // rubber flag
103 
104 public:
105 
106  enum ERubberFlag {
109  kLRubberW = BIT(2),
110  kLRubberH = BIT(3)
111  };
112 
114  UInt_t rubberFlag = kLRubberX | kLRubberY);
115 
116  Double_t GetX() const { return fX; };
117  Double_t GetY() const { return fY; };
118  Double_t GetW() const { return fW; };
119  Double_t GetH() const { return fH; };
120  UInt_t GetFlag() const { return fFlag; };
121 
122  void SetX(Double_t x) { fX = x; }
123  void SetY(Double_t y) { fY = y; }
124  void SetW(Double_t w) { fW = w; }
125  void SetH(Double_t h) { fH = h; }
126  void SetFlag(UInt_t flag) { fFlag = flag; }
127 
128  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
129 
130  ClassDef(TGXYLayoutHints,0) // Hits for the X / Y - layout manager
131 };
132 
133 
134 class TGXYLayout : public TGLayoutManager {
135 
136 protected:
137  TList *fList; // list of frames to arrange
138  TGCompositeFrame *fMain; // container frame
139 
140  Bool_t fFirst; // flag to determine the first call of Layout()
141  UInt_t fFirstWidth; // original width of the frame fMain
142  UInt_t fFirstHeight; // original height of the fram fMain
143 
144  Int_t fTWidth; // text width of a default character "1234567890" / 10
145  Int_t fTHeight; // text height
146 
147  TGXYLayout(const TGXYLayout&);
149 
150 public:
152 
153  virtual void Layout();
154  virtual TGDimension GetDefaultSize() const;
155  virtual void SavePrimitive(std::ostream &out, Option_t * = "");
156 
157  void NewSize() { fFirst = kTRUE; }
158 
159  ClassDef(TGXYLayout,0) // X / Y - layout manager
160 };
161 
162 #endif
TGXYLayout::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout manager as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:298
TGXYLayout::fTHeight
Int_t fTHeight
Definition: TGXYLayout.h:145
TGXYLayoutHints::GetH
Double_t GetH() const
Definition: TGXYLayout.h:125
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TGXYLayoutHints::fX
Double_t fX
Definition: TGXYLayout.h:104
TGXYLayout::fFirstWidth
UInt_t fFirstWidth
Definition: TGXYLayout.h:141
TGXYLayout::Layout
virtual void Layout()
Recalculates the postion and the size of all widgets.
Definition: TGXYLayout.cxx:225
TGXYLayoutHints::kLRubberH
@ kLRubberH
Definition: TGXYLayout.h:116
TGDimension
Definition: TGDimension.h:27
TGXYLayoutHints::SetH
void SetH(Double_t h)
Definition: TGXYLayout.h:131
TGXYLayoutHints::kLRubberW
@ kLRubberW
Definition: TGXYLayout.h:115
TGXYLayout::operator=
TGXYLayout & operator=(const TGXYLayout &)
assignment operator
Definition: TGXYLayout.cxx:207
TGLayout.h
TGXYLayoutHints::fFlag
UInt_t fFlag
Definition: TGXYLayout.h:108
TGXYLayoutHints
Definition: TGXYLayout.h:95
TGXYLayoutHints::SetY
void SetY(Double_t y)
Definition: TGXYLayout.h:129
x
Double_t x[n]
Definition: legend1.C:17
TGXYLayoutHints::kLRubberX
@ kLRubberX
Definition: TGXYLayout.h:113
TGXYLayoutHints::GetW
Double_t GetW() const
Definition: TGXYLayout.h:124
TGXYLayout
Definition: TGXYLayout.h:134
bool
TGLayoutManager
Definition: TGLayout.h:142
TGXYLayoutHints::SetX
void SetX(Double_t x)
Definition: TGXYLayout.h:128
TGXYLayoutHints::fW
Double_t fW
Definition: TGXYLayout.h:106
TGXYLayout::GetDefaultSize
virtual TGDimension GetDefaultSize() const
Returns the original size of the frame.
Definition: TGXYLayout.cxx:288
TGXYLayout::fFirstHeight
UInt_t fFirstHeight
Definition: TGXYLayout.h:142
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGXYLayoutHints::TGXYLayoutHints
TGXYLayoutHints(Double_t x, Double_t y, Double_t w, Double_t h, UInt_t rubberFlag=kLRubberX|kLRubberY)
Constructor.
Definition: TGXYLayout.cxx:117
h
#define h(i)
Definition: RSha256.hxx:124
TGXYLayout::fTWidth
Int_t fTWidth
Definition: TGXYLayout.h:144
TGXYLayout::fFirst
Bool_t fFirst
Definition: TGXYLayout.h:140
TGXYLayoutHints::GetY
Double_t GetY() const
Definition: TGXYLayout.h:123
TGXYLayoutHints::SetW
void SetW(Double_t w)
Definition: TGXYLayout.h:130
TGXYLayoutHints::ERubberFlag
ERubberFlag
Definition: TGXYLayout.h:112
main
int main(int argc, char **argv)
Definition: histspeedtest.cxx:751
TGLayoutHints
Definition: TGLayout.h:57
TGXYLayout::fList
TList * fList
Definition: TGXYLayout.h:137
BIT
#define BIT(n)
Definition: Rtypes.h:85
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGXYLayoutHints::GetFlag
UInt_t GetFlag() const
Definition: TGXYLayout.h:126
y
Double_t y[n]
Definition: legend1.C:17
TGXYLayoutHints::fH
Double_t fH
Definition: TGXYLayout.h:107
unsigned int
TGXYLayoutHints::kLRubberY
@ kLRubberY
Definition: TGXYLayout.h:114
TGXYLayout::fMain
TGCompositeFrame * fMain
Definition: TGXYLayout.h:138
Double_t
double Double_t
Definition: RtypesCore.h:59
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGXYLayoutHints::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *="")
Save XY layout hints as a C++ statement(s) on output stream.
Definition: TGXYLayout.cxx:131
TGXYLayout::TGXYLayout
TGXYLayout(const TGXYLayout &)
copy constructor
Definition: TGXYLayout.cxx:192
TGXYLayoutHints::SetFlag
void SetFlag(UInt_t flag)
Definition: TGXYLayout.h:132
TGCompositeFrame
Definition: TGFrame.h:324
TGXYLayoutHints::fY
Double_t fY
Definition: TGXYLayout.h:105
TList
Definition: TList.h:44
TGXYLayoutHints::GetX
Double_t GetX() const
Definition: TGXYLayout.h:122
int
TGXYLayout::NewSize
void NewSize()
Definition: TGXYLayout.h:157