YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
yuicont.h
浏览该文件的文档.
1 /*
2  © 2011-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YSL_INC_UI_yuicont_h_
29 #define YSL_INC_UI_yuicont_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YWidget
33 #include <ystdex/iterator.hpp>
34 
35 namespace YSLib
36 {
37 
38 namespace UI
39 {
40 
46 YF_API IWidget&
47 FetchTopLevel(IWidget&);
54 YF_API IWidget&
55 FetchTopLevel(IWidget&, Point&);
56 
57 
63 LocateOffset(const IWidget*, Point, const IWidget*);
64 
69 inline Point
70 LocateContainerOffset(const IWidget& wgt, const Point& pt)
71 {
72  return pt + GetLocationOf(wgt);
73 }
74 
80 LocateForWidget(const IWidget&, const IWidget&);
81 
88 template<class _tWidget, typename _fFetcher>
89 Point
90 LocateForWidgetNode(IWidget& wgt, _fFetcher fetch_ptr)
91 {
92  if(YB_LIKELY(dynamic_cast<_tWidget*>(&wgt)))
93  return Point();
94 
95  _tWidget* const pNode(fetch_ptr(wgt));
96 
97  return pNode ? LocateOffset(pNode, Point(), &wgt) : Point::Invalid;
98 }
99 
106 LocateForParentContainer(const IWidget&);
107 
108 
114 YF_API void
115 MoveToLeft(IWidget& wgt);
116 
122 YF_API void
123 MoveToRight(IWidget& wgt);
124 
130 YF_API void
131 MoveToTop(IWidget& wgt);
132 
138 YF_API void
139 MoveToBottom(IWidget& wgt);
140 
141 
142 /*
143 \brief Z 顺序类型:覆盖顺序,值越大表示越接近顶层。
144 \since build 212
145 */
146 using ZOrderType = u8;
151 const ZOrderType DefaultZOrder(64);
157 
158 
166 YF_API bool
167 RemoveFrom(IWidget&, IWidget&);
168 
169 
177 {
178 public:
180  using ItemType = IWidget*;
182  using WidgetVector = vector<ItemType>;
184 
185 protected:
186  /*
187  \brief 部件组:存储非空部件指针。
188  \invariant <tt>std::all_of(mWidgets.begin(), mWidget.end(),
189  [](ItemType item){return bool(item);})</tt> 。
190  */
192 
196 
201  void
202  operator+=(IWidget&);
203 
210  bool
211  operator-=(IWidget&);
212 
213 public:
219  PDefHOp(IWidget&, [], size_t idx) ynothrowv
220  ImplRet(YAssertNonnull(vWidgets[idx]),
221  YAssert(idx < GetCount(), "Index is out of range."), *vWidgets[idx])
222  PDefHOp(IWidget&, [], size_t idx) const ynothrowv
223  ImplRet(YAssertNonnull(vWidgets[idx]),
224  YAssert(idx < GetCount(), "Index is out of range."), *vWidgets[idx])
226 
231  bool
232  Contains(IWidget&) const;
233 
238  DefGetter(const ynothrow, size_t, Count, vWidgets.size())
239 
245  size_t
246  Find(IWidget&) const;
247 
248 protected:
250  void
251  PaintVisibleChildren(PaintEventArgs&);
252 
253 public:
260  PDefH(IWidget&, at, size_t idx) ythrow(std::out_of_range)
261  ImplRet(YAssertNonnull(vWidgets.at(idx)), *vWidgets.at(idx))
262  PDefH(IWidget&, at, size_t idx) const ythrow(std::out_of_range)
263  ImplRet(YAssertNonnull(vWidgets.at(idx)), *vWidgets.at(idx))
265 
266  iterator
267  begin();
268 
269  iterator
270  end();
271 };
272 
273 
280 {
281 public:
282  using ItemType = IWidget*;
283  using WidgetMap = multimap<ZOrderType, ItemType>; \
285  using PairType = WidgetMap::value_type;
288 
289 protected:
290  /*
291  \brief 部件映射:存储 Z 顺序映射至非空部件指针。
292  \invariant <tt>std::all_of(mWidgets.begin(), mWidget.end(),
293  [](const PairType& pr){return bool(pr.second);})</tt> 。
294  \since build 279
295  */
297 
301  DefDeCtor(MUIContainer)
302  DefDeMoveCtor(MUIContainer)
303 
310  PDefHOp(void, +=, IWidget& wgt)
311  ImplRet(Add(wgt))
312 
319  bool
320  operator-=(IWidget&);
321 
322 public:
326  bool
327  Contains(IWidget&);
328 
333  DefGetter(const ynothrow, size_t, Count, mWidgets.size())
334 
341  void
342  Add(IWidget&, ZOrderType = DefaultZOrder);
343 
344 protected:
349  void
350  PaintVisibleChildren(PaintEventArgs&);
351 
352 public:
358  ZOrderType
359  QueryZ(IWidget&) const;
360 
362  iterator
363  begin();
364 
366  iterator
367  end();
368 };
369 
370 
375 template<class _tCon>
376 inline void
377 AddWidget(_tCon& con, IWidget& wgt)
378 {
379  con += wgt;
380 }
381 
386 template<class _tCon>
387 inline void
388 AddWidget(_tCon& con, IWidget& wgt, ZOrderType z)
389 {
390  con.Add(wgt, z);
391 }
392 
398 template<class _tCon, class... _tWidgets>
399 inline void
400 AddWidgets(_tCon& con, _tWidgets&... wgts)
401 {
402  unseq_apply(std::bind(static_cast<void(_tCon::*)(IWidget&)>(
403  &_tCon::operator+=), std::ref(con), std::placeholders::_1),
404  std::forward<IWidget&>(wgts)...);
405 }
406 
412 template<class _tCon, class... _tWidgets>
413 inline void
414 AddWidgetsZ(_tCon& con, ZOrderType z, _tWidgets&... wgts)
415 {
416  unseq_apply(std::bind(static_cast<void(_tCon::*)(IWidget&, ZOrderType)
417  >(&_tCon::Add), std::ref(con), std::placeholders::_1, z),
418  std::forward<IWidget&>(wgts)...);
419 }
420 
426 template<class _tCon, class... _tWidgets>
427 inline void
428 RemoveWidgets(_tCon& con, _tWidgets&... wgts)
429 {
430  unseq_apply(std::bind(static_cast<bool(_tCon::*)(IWidget&)>(
431  &_tCon::operator-=), std::ref(con), std::placeholders::_1),
432  std::forward<IWidget&>(wgts)...);
433 }
434 
435 } // namespace UI;
436 
437 } // namespace YSLib;
438 
439 #endif
440 
Point LocateContainerOffset(const IWidget &wgt, const Point &pt)
取相对部件 wgt 的点 pt 相对于 wgt 的容器的偏移坐标。
Definition: yuicont.h:70
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
YF_API Point LocateOffset(const IWidget *, Point, const IWidget *)
取相对于第三参数指向的部件的点相对于第一参数指向的容器的偏移坐标。
Definition: yuicont.cpp:63
#define ynothrowv
YSLib 无异常抛出保证验证:有条件地使用无异常抛出规范。
Definition: ydef.h:494
void AddWidgetsZ(_tCon &con, ZOrderType z, _tWidgets &...wgts)
向部件容器添加指定 Z 顺序的子部件。
Definition: yuicont.h:414
#define DefDeCtor(_t)
Definition: YBaseMacro.h:131
部件绘制参数。
Definition: ywgtevt.h:276
#define YF_API
Definition: Platform.h:64
static const GBinaryGroup Invalid
无效(不在屏幕坐标系中)对象。
Definition: ygdibase.h:57
void unseq_apply(_fCallable &&f, _tParams &&...args)
无序调用。
Definition: functional.hpp:144
ystdex::any_input_iterator< IWidget > WidgetIterator
通用部件迭代器。
Definition: ywidget.h:52
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
void RemoveWidgets(_tCon &con, _tWidgets &...wgts)
从部件容器移除子部件。
Definition: yuicont.h:428
void AddWidgets(_tCon &con, _tWidgets &...wgts)
向部件容器添加子部件。
Definition: yuicont.h:400
YF_API void MoveToBottom(IWidget &wgt)
移动部件 wgt 至容器下端。
Definition: yuicont.cpp:135
YF_API bool RemoveFrom(IWidget &, IWidget &)
从容器中移除部件。
Definition: yuicont.cpp:144
YF_API void MoveToRight(IWidget &wgt)
移动部件 wgt 至容器右端。
Definition: yuicont.cpp:120
IWidget * ItemType
部件组项目类型。
Definition: yuicont.h:180
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活:使用指定屏幕、有效性、前景色和默认背景色。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
YF_API void MoveToTop(IWidget &wgt)
移动部件 wgt 至容器上端。
Definition: yuicont.cpp:128
IWidget * ItemType
部件组项目类型。
Definition: yuicont.h:282
_tWidget & wgt
Definition: ywgtevt.h:596
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
通用迭代器。
YF_API IWidget & FetchTopLevel(IWidget &)
取指定部件的顶层部件。
Definition: yuicont.cpp:40
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:476
u8 ZOrderType
Definition: yuicont.h:146
#define YAssertNonnull(_expr)
Definition: cassert.h:81
YF_API Point LocateForParentContainer(const IWidget &)
取指定部件相对于容器的父容器的偏移坐标。
Definition: yuicont.cpp:104
线性部件容器模块。
Definition: yuicont.h:176
YF_API Point LocateForWidget(const IWidget &, const IWidget &)
取第二参数指定的部件相对于第一参数指定的部件的偏移坐标。
Definition: yuicont.cpp:74
动态泛型输入迭代器。
const ZOrderType DefaultZOrder(64)
默认 Z 顺序值。
Selected const shared_ptr< ListType > const pair< Color, Color > viewer Contains
Definition: textlist.h:124
WidgetMap::value_type PairType
Definition: yuicont.h:285
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
std::uint8_t u8
通用数据类型。
Definition: yadaptor.h:67
void AddWidget(_tCon &con, IWidget &wgt)
向部件添加单一子部件。
Definition: yuicont.h:377
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
vector< ItemType > WidgetVector
部件组类型。
Definition: yuicont.h:182
Point LocateForWidgetNode(IWidget &wgt, _fFetcher fetch_ptr)
取指定部件相对于视图树中的直接节点指针的偏移坐标。
Definition: yuicont.h:90
#define YB_LIKELY(expr)
Definition: ydef.h:297
multimap< ZOrderType, ItemType > WidgetMap
部件映射表类型:映射 Z 顺序至部件。
Definition: yuicont.h:284
部件容器模块。
Definition: yuicont.h:279
const ZOrderType DefaultWindowZOrder(128)
默认窗口 Z 顺序值。
YF_API void MoveToLeft(IWidget &wgt)
移动部件 wgt 至容器左端。
Definition: yuicont.cpp:113
#define YAssert(_expr, _msg)
Definition: cassert.h:73