TNB Library
TnbBorderLayout.h
[詳解]
1#pragma once
11#include "TnbSimpleVector.h"
12#include "TnbLayout.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
50{
51 DEFSUPER(CAbstractLayout);
52public:
53
58 {
64 //
69 };
70
75 {
76 m_params = new TParams();
77 }
78
87 CBorderLayout& Add(EPosition pos, const ILayout& layout, ELocation hloc = DEFAULT, ELocation vloc = DEFAULT)
88 {
89 if ( pos >= Position_North && pos <= Position_East )
90 {
91 m_params->param[pos] = TParam(hloc, vloc, layout);
92 }
93 else
94 {
95 ASSERT( false );
96 }
97 return *this;
98 }
99
105 virtual ILayout* Clone(void) const
106 {
107 CBorderLayout* P = new CBorderLayout();
108 *P = *this;
109 return P;
110 }
111
119 virtual bool GetMinimumSize(SIZE& _size) const
120 {
121 _size.cx =0;
122 _size.cy =0;
123 SIZE sz;
124 for ( int e = Position_West; e <= Position_East; e++ )
125 {
126 if ( m_params->param[e].pLayout != NULL && m_params->param[e].pLayout->GetMinimumSize(sz) )
127 {
128 _size.cy = max(_size.cy, sz.cy);
129 if ( _size.cx != 0 )
130 {
131 _size.cx += m_gapSize.cx;
132 }
133 _size.cx += sz.cx;
134 }
135 }
136 for ( int e = Position_North; e <= Position_South; e++ )
137 {
138 if ( m_params->param[e].pLayout != NULL && m_params->param[e].pLayout->GetMinimumSize(sz) )
139 {
140 _size.cx = max(_size.cx, sz.cx);
141 if ( _size.cy != 0 )
142 {
143 _size.cy += m_gapSize.cy;
144 }
145 _size.cy += sz.cy;
146 }
147 }
148 //
149 AddMargnSize(_size);
150 return true;
151 }
152
161 virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
162 {
163 SIZE areaSize = m_layoutSize;
164 {
165 SIZE sz;
166 GetMargnSize(sz);
167 areaSize.cx -= sz.cx;
168 areaSize.cy -= sz.cy;
169 }
170 POINT cpos = { m_margn.left, m_margn.top };
171 SIZE csize = areaSize;
172 SIZE sz; //汎用
173 POINT pp[5] = { 0 };
174 SIZE ss[5] = { 0 };
175 //南(下)
176 {
177 TParam& pa = m_params->param[Position_South];
178 if ( ! pa.pLayout.IsNull() && pa.pLayout->GetSize(sz) )
179 {
180 pp[Position_South].x = cpos.x;
181 ss[Position_South].cx = csize.cx;
182 pp[Position_South].y = cpos.y + csize.cy - sz.cy;
183 ss[Position_South].cy = sz.cy;
184 csize.cy -= sz.cy + m_gapSize.cy;
185 }
186 }
187 //北(上)
188 {
189 TParam& pa = m_params->param[Position_North];
190 if ( ! pa.pLayout.IsNull() && pa.pLayout->GetSize(sz) )
191 {
192 pp[Position_North].x = cpos.x;
193 ss[Position_North].cx = csize.cx;
194 pp[Position_North].y = cpos.y;
195 ss[Position_North].cy = sz.cy;
196 csize.cy -= sz.cy + m_gapSize.cy;
197 cpos.y += sz.cy + m_gapSize.cy;
198 }
199 }
200 //西(右)
201 {
202 TParam& pa = m_params->param[Position_East];
203 if ( ! pa.pLayout.IsNull() && pa.pLayout->GetSize(sz) )
204 {
205 pp[Position_East].x = cpos.x + csize.cx - sz.cx;
206 ss[Position_East].cx = sz.cx;
207 pp[Position_East].y = cpos.y;
208 ss[Position_East].cy = csize.cy;
209 csize.cx -= sz.cx+ m_gapSize.cx;
210 }
211 }
212 //東(左)
213 {
214 TParam& pa = m_params->param[Position_West];
215 if ( ! pa.pLayout.IsNull() && pa.pLayout->GetSize(sz) )
216 {
217 pp[Position_West].x = cpos.x;
218 ss[Position_West].cx = sz.cx;
219 pp[Position_West].y = cpos.y;
220 ss[Position_West].cy = csize.cy;
221 csize.cx -= sz.cx + m_gapSize.cx;
222 cpos.x += sz.cx + m_gapSize.cx;
223 }
224 }
225 //中
226 {
227 TParam& pa = m_params->param[Position_Center];
228 if ( ! pa.pLayout.IsNull() && pa.pLayout->GetSize(sz) )
229 {
230 pp[Position_Center].x = cpos.x;
231 ss[Position_Center].cx = csize.cx;
232 pp[Position_Center].y = cpos.y;
233 ss[Position_Center].cy = csize.cy;
234 }
235 }
236 //レイアウト
238 loop ( j, 5 )
239 {
240 int i = row[j];
241 TParam& pa = m_params->param[i];
242 if ( ! pa.pLayout.IsNull() )
243 {
244 HorizontalItemDecide(pa.pLayout, x, pp[i].x, ss[i].cx, pa.horizontalLocate, wParam, lParam);
245 VerticalItemDecide(pa.pLayout, y, pp[i].y, ss[i].cy, pa.verticalLocate, wParam, lParam);
246 }
247 }
248 }
249
250private:
251 struct TParams
252 {
253 TParam param[5];
254 };
255 CPointerHandleT<TParams> m_params;
256};
257
258
259
260}; // TNB
261
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
レイアウト関係のヘッダ
簡易配列型情報管理関係のヘッダ
レイアウトアイテム抽象クラス.
Definition: TnbLayout.h:194
ELocation
レイアウトアイテム配置方法.
Definition: TnbLayout.h:204
@ DEFAULT
横方向は左寄せ、縦方向は中央
Definition: TnbLayout.h:205
void GetMargnSize(SIZE &_size) const
[取得] マージンサイズ取得.
Definition: TnbLayout.h:414
void AddMargnSize(SIZE &_size) const
[加算] マージンサイズ加算.
Definition: TnbLayout.h:425
void HorizontalItemDecide(ILayout *pLayout, INT_PTR x, INT_PTR xx, INT_PTR width, ELocation loc, WPARAM wParam, LPARAM lParam)
[設定] 水平方向アイテム決定.
Definition: TnbLayout.h:338
SIZE m_gapSize
各アイテム間のギャップ(縦、横)
Definition: TnbLayout.h:326
SIZE m_layoutSize
レイアウト全体サイズ(縦、横)
Definition: TnbLayout.h:324
void VerticalItemDecide(ILayout *pLayout, INT_PTR y, INT_PTR yy, INT_PTR height, ELocation loc, WPARAM wParam, LPARAM lParam)
[設定] 垂直方向アイテム決定.
Definition: TnbLayout.h:379
RECT m_margn
外周のマージン
Definition: TnbLayout.h:325
ボーダーレイアウトアイテムクラス.
virtual bool GetMinimumSize(SIZE &_size) const
[取得] 最小サイズ取得.
CBorderLayout(void)
コンストラクタ
virtual ILayout * Clone(void) const
[作成] クローン作成.
virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
[処理] 決定.
EPosition
ポジション種.
@ Position_Center
真ん中
CBorderLayout & Add(EPosition pos, const ILayout &layout, ELocation hloc=DEFAULT, ELocation vloc=DEFAULT)
[設定] アイテム追加.
bool IsNull(void) const
[確認] NULLチェック
TNB Library
Definition: TnbDoxyTitle.txt:2
管理パラメータ型
Definition: TnbLayout.h:307
ELocation horizontalLocate
アイテムの水平配置種
Definition: TnbLayout.h:308
ELocation verticalLocate
アイテムの垂直配置種
Definition: TnbLayout.h:309
ILayout::Ptr pLayout
レイアウトアイテム
Definition: TnbLayout.h:310
レイアウトインターフェース.
Definition: TnbLayout.h:34
virtual bool GetSize(SIZE &_size) const =0
[取得] サイズ取得.