TNB Library
TnbGridLayout.h
[詳解]
1#pragma once
11#include "TnbSimpleVector.h"
12#include "TnbLayout.h"
13
14
15
16//TNB Library
17namespace TNB
18{
19
20
21
77{
78 DEFSUPER(CAbstractLayout);
79public:
80
85 CGridLayout(size_t cx) : m_sizex(cx)
86 {
87 ASSERT( m_sizex != 0 );
88 m_params = new CParamVector();
89 }
90
99 CGridLayout& Add(const ILayout& layout, ELocation hloc = DEFAULT, ELocation vloc = DEFAULT)
100 {
101 m_params->Add(TParam(hloc, vloc, layout));
102 return *this;
103 }
104
110 virtual ILayout* Clone(void) const
111 {
112 CGridLayout* P = new CGridLayout(m_sizex);
113 *P = *this;
114 return P;
115 }
116
124 virtual bool GetMinimumSize(SIZE& _size) const
125 {
126 _size.cx =0;
127 _size.cy =0;
128 int ly = 0;
129 CWorkMemT<LONG> lxs(GetHorizontalItemCount());
130 loop ( y, GetVerticalItemCount() )
131 {
132 loop ( x, GetHorizontalItemCount() )
133 {
134 if ( m_params->GetSize() > y * GetHorizontalItemCount() + x)
135 {
136 SIZE sz;
137 if ( m_params->At(y * GetHorizontalItemCount() + x).pLayout->GetMinimumSize(sz) )
138 {
139 ly = max(ly, sz.cy);
140 lxs[x] = max(lxs[x], sz.cx);
141 }
142 }
143 }
144 }
145 _size.cy += ToInt(ly * GetVerticalItemCount());
146 // Xを調べる
147 int lx = 0;
148 loop ( x, GetHorizontalItemCount() )
149 {
150 lx = max(lx, lxs[x]);
151 }
152 _size.cx += ToInt(lx * GetVerticalItemCount());
153 //
154 AddChinkSize(_size, GetHorizontalItemCount(), GetVerticalItemCount());
155 return true;
156 }
157
166 virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
167 {
168 SIZE areaSize = m_layoutSize;
169 {
170 SIZE sz = { 0, 0 };
171 AddChinkSize(sz, GetHorizontalItemCount(), GetVerticalItemCount());
172 areaSize.cx = ToInt((areaSize.cx - sz.cx) / GetHorizontalItemCount());
173 areaSize.cy = ToInt((areaSize.cy - sz.cy) / GetVerticalItemCount());
174 }
175 int posy = m_margn.top;
176 loop ( yy, GetVerticalItemCount() )
177 {
178 int posx = m_margn.left;
179 loop ( xx, GetHorizontalItemCount() )
180 {
181 if ( m_params->GetSize() > yy * GetHorizontalItemCount() + xx)
182 {
183 TParam& pa = m_params->At(yy * GetHorizontalItemCount() + xx);
184 HorizontalItemDecide(pa.pLayout, x, posx, areaSize.cx, pa.horizontalLocate, wParam, lParam);
185 VerticalItemDecide(pa.pLayout, y, posy, areaSize.cy, pa.verticalLocate, wParam, lParam);
186 posx += areaSize.cx + m_gapSize.cx;
187 }
188 }
189 posy += areaSize.cy + m_gapSize.cy;
190 }
191 }
192
193private:
194 typedef CSimpleVectorT<TParam> CParamVector;
196 size_t m_sizex;
198 size_t GetHorizontalItemCount(void) const
199 {
200 return m_sizex;
201 }
203 size_t GetVerticalItemCount(void) const
204 {
205 return (m_params->GetSize() + m_sizex - 1) / m_sizex;
206 }
207};
208
209
210
211}; // TNB
212
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
レイアウト関係のヘッダ
簡易配列型情報管理関係のヘッダ
レイアウトアイテム抽象クラス.
Definition: TnbLayout.h:194
ELocation
レイアウトアイテム配置方法.
Definition: TnbLayout.h:204
@ DEFAULT
横方向は左寄せ、縦方向は中央
Definition: TnbLayout.h:205
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
void AddChinkSize(SIZE &_size, size_t cx, size_t cy) const
[加算] 隙間サイズ加算.
Definition: TnbLayout.h:438
RECT m_margn
外周のマージン
Definition: TnbLayout.h:325
グリッドレイアウトアイテムクラス.
Definition: TnbGridLayout.h:77
virtual bool GetMinimumSize(SIZE &_size) const
[取得] 最小サイズ取得.
virtual ILayout * Clone(void) const
[作成] クローン作成.
virtual void Decide(int x, int y, WPARAM wParam, LPARAM lParam)
[処理] 決定.
CGridLayout(size_t cx)
コンストラクタ
Definition: TnbGridLayout.h:85
CGridLayout & Add(const ILayout &layout, ELocation hloc=DEFAULT, ELocation vloc=DEFAULT)
[設定] アイテム追加.
Definition: TnbGridLayout.h:99
ポインタ型ハンドルテンプレート
ワークメモリテンプレート.
Definition: TnbDef.h:633
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
Definition: TnbStrLib.h:367
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