TNB Library
TnbBoxLayout.h
[詳解]
1#pragma once
11#include "TnbSimpleVector.h"
12#include "TnbLayout.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
102{
103 DEFSUPER(CAbstractLayout);
104public:
105
111 CBoxLayout(bool isHorizental = true, bool isLastFilling = true)
112 : m_isHorizental(isHorizental), m_isLastFilling(isLastFilling)
113 {
114 m_params = new CParamVector();
115 }
116
121 void SetLastFilling(bool isLastFilling)
122 {
123 m_isLastFilling = isLastFilling;
124 }
125
130 void SetHorizentalMode(bool isHorizental)
131 {
132 m_isHorizental = isHorizental;
133 }
134
143 CBoxLayout& Add(const ILayout& layout, ELocation hloc = DEFAULT, ELocation vloc = DEFAULT)
144 {
145 m_params->Add(TParam(hloc, vloc, layout));
146 return *this;
147 }
148
154 virtual ILayout* Clone(void) const
155 {
156 CBoxLayout* P = new CBoxLayout();
157 *P = *this;
158 return P;
159 }
160
168 virtual bool GetMinimumSize(SIZE& _size) const
169 {
170 return m_Calc(_size, NULL);
171 }
172
181 virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
182 {
183 CSizeEx position(m_margn.left, m_margn.top);
184 CSizeEx minSize;
186 if ( ! m_Calc(minSize, &poss) )
187 {
188 return;
189 }
190 size_t itemNum = m_params->GetSize();
191 loop ( item, itemNum )
192 {
193 TParam& pa = m_params->At(item);
194 CSizeEx nowItemSize;
195 if ( ! pa.pLayout->GetSize(nowItemSize) )
196 {
197 return;
198 }
199 CSizeEx areaSize = poss[item].size;
200 int ll = 0;
201 if ( m_isHorizental )
202 {
203 areaSize.cy = m_layoutSize.cy - m_margn.top - m_margn.bottom;
204 ll = m_layoutSize.cx - minSize.cx;
205 }
206 else
207 {
208 areaSize.cx = m_layoutSize.cx - m_margn.left - m_margn.right;
209 ll = m_layoutSize.cy - minSize.cy;
210 }
211 if ( m_isLastFilling && item == (itemNum - 1) )
212 {
213 areaSize.At(m_isHorizental) += ll;
214 }
215 loop ( hos, 2 )
216 {
217 bool isHos = (hos == 0);
218 if ( position.At(isHos) < 0 )
219 {
220 continue;
221 }
222 int ww = position.At(isHos);
223 if ( m_isHorizental == isHos )
224 {
225 ww += poss[item].pos;
226 }
227 if ( isHos )
228 {
229 HorizontalItemDecide(pa.pLayout, x, ww, areaSize.At(isHos), GetLocation(pa, isHos), wParam, lParam);
230 }
231 else
232 {
233 VerticalItemDecide(pa.pLayout, y, ww, areaSize.At(isHos), GetLocation(pa, isHos), wParam, lParam);
234 }
235 }
236 }
237 }
238
239private:
241 class CSizeEx : public SIZE
242 {
243 DEFSUPER(SIZE);
244 public:
245 CSizeEx() {}
246 CSizeEx(int x, int y) { cx = x; cy = y; }
247 CSizeEx(SIZE initSize) { cx = initSize.cx; cy = initSize.cy; }
248 LONG& At(bool isHorizen) { return isHorizen ? cx : cy; }
249 const LONG& At(bool isHorizen) const { return isHorizen ? cx : cy; }
250 };
252 struct TResult
253 {
254 LONG pos;
255 CSizeEx size;
256 };
258 bool m_Calc(SIZE& _size, CSimpleVectorT<TResult>* pRes) const
259 {
260 CSizeEx gapSize = m_gapSize;
261 TResult r;
262 r.pos = 0;
263 LONG hh = 0;
264 loop ( item, m_params->GetSize() )
265 {
266 const TParam& pa = m_params->At(item);
267 if ( ! pa.pLayout->GetMinimumSize(r.size) )
268 {
269 return false;
270 }
271 if ( item != 0 )
272 {
273 r.pos += gapSize.At(m_isHorizental);
274 }
275 if ( pRes != NULL )
276 {
277 pRes->Add(r);
278 }
279 r.pos += r.size.At(m_isHorizental);
280 hh = max(hh, r.size.At(! m_isHorizental));
281 }
282 CSizeEx sz;
283 GetMargnSize(sz);
284 sz.At(m_isHorizental) += r.pos;
285 sz.At(! m_isHorizental) += hh;
286 _size = sz;
287 return true;
288 }
290 static ELocation GetLocation(TParam& p, bool isHorizen)
291 {
292 return isHorizen ? p.horizontalLocate : p.verticalLocate;
293 }
294 typedef CSimpleVectorT<TParam> CParamVector;
296 bool m_isHorizental;
297 bool m_isLastFilling;
298};
299
300
301
302}; // TNB
#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 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
ボックスレイアウトアイテムクラス.
Definition: TnbBoxLayout.h:102
virtual bool GetMinimumSize(SIZE &_size) const
[取得] 最小サイズ取得.
Definition: TnbBoxLayout.h:168
virtual ILayout * Clone(void) const
[作成] クローン作成.
Definition: TnbBoxLayout.h:154
virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
[処理] 決定.
Definition: TnbBoxLayout.h:181
CBoxLayout(bool isHorizental=true, bool isLastFilling=true)
コンストラクタ
Definition: TnbBoxLayout.h:111
void SetLastFilling(bool isLastFilling)
[設定] 調整モード設定
Definition: TnbBoxLayout.h:121
CBoxLayout & Add(const ILayout &layout, ELocation hloc=DEFAULT, ELocation vloc=DEFAULT)
[設定] アイテム追加.
Definition: TnbBoxLayout.h:143
void SetHorizentalMode(bool isHorizental)
[設定] 並び向き設定
Definition: TnbBoxLayout.h:130
ポインタ型ハンドルテンプレート
INDEX Add(const TYP &t)
[追加] 要素一つ追加.
TNB Library
Definition: TnbDoxyTitle.txt:2
管理パラメータ型
Definition: TnbLayout.h:307
ILayout::Ptr pLayout
レイアウトアイテム
Definition: TnbLayout.h:310
レイアウトインターフェース.
Definition: TnbLayout.h:34
virtual bool GetSize(SIZE &_size) const =0
[取得] サイズ取得.