YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
Selector.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_Selector_h_
29 #define YSL_INC_UI_Selector_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_UI_Button
33 #include YFM_YSLib_UI_YStyle
34 
35 namespace YSLib
36 {
37 
38 namespace UI
39 {
40 
42 
43 
49 template<typename _type>
51 {
52 public:
54  using StateType = _type;
58  DeclDelegate(HSelectedEvent, SelectedArgs)
59 
60 
61  StateType State;
62 
64  : State()
65  {}
67  : State(st)
68  {}
69 
70  /*
71  \brief 更新状态。
72  \return 是否和旧状态相同。
73  */
74  bool
76  {
77  const StateType old(State);
78 
79  State = st;
80  return st != old;
81  }
82 };
83 
84 
91 {
92 public:
94 
95  using StateType = enum SelectedState : yimpl(size_t)
97  {
98  Unchecked = 0,
99  Checked = 1,
100  Partial = 2
101  };
109  using HTickedEvent = MSelector::HSelectedEvent;
111 
112 protected:
114 
115 public:
117  DeclEvent(HTickedEvent, Ticked)
118 
119  MCheckBox(StateType st = Unchecked)
120  : mSelector(st)
121  {}
122 
123  DefGetter(const ynothrow, StateType, State, mSelector.State)
124 };
126 
127 
132 class YF_API CheckBox : public Thumb, protected MCheckBox
133 {
134 public:
140  {
141  CheckBoxBackground = Thumb::EndStyle,
142  EndStyle
143  };
145 
146  using MCheckBox::StateType;
147  using MCheckBox::Checked;
148  using MCheckBox::Unchecked;
149  using MCheckBox::Partial;
151  using MCheckBox::TickedArgs;
155 
157  using MCheckBox::Ticked;
158 
159 public:
164  explicit
165  CheckBox(const Rect& = {});
167 
168  DefPred(const ynothrow, Ticked, GetState() == Checked)
169 
171  using MCheckBox::GetState;
172 
178  void
179  SetTicked(StateType);
180 
185  void
186  Refresh(PaintEventArgs&&) override;
187 
193  void
194  Tick(StateType);
195 };
196 
197 
202 class YF_API CheckButton : public CheckBox, protected MLabel
203 {
204 public:
205  using MLabel::Font;
206  using MLabel::Text;
207 
212  explicit
213  CheckButton(const Rect& = {});
214 
215  void
216  Refresh(PaintEventArgs&&) override;
217 };
218 
219 
227 {
228 public:
230 
231  using StateType = IWidget*;
237  using HSelectedEvent = MSelector::HSelectedEvent;
239 
240 private:
241  /*
242  \brief 共享状态。
243  \invariant <tt>bool(p_selector)</tt> 。
244  \since build 480
245  */
246  shared_ptr<MSelector> p_selector;
247 
248 public:
254 
255 
256 
257  MSharedSelection(StateType st = {})
258  : p_selector(ystdex::make_shared<MSelector>(st))
259  {}
260  MSharedSelection(shared_ptr<MSelector> p_sel, StateType st = {})
261  : p_selector(p_sel ? std::move(p_sel)
262  : ystdex::make_shared<MSelector>(st))
263  {}
265 
266  DefGetter(const ynothrow, StateType, State, p_selector->State)
267 
268  DefSetter(StateType, State, p_selector->State)
269 
274  void
275  ShareTo(MSharedSelection&) const;
276 
277  PDefH(bool, UpdateState, StateType st)
278  ImplRet(p_selector->UpdateState(st))
279 };
280 
281 
283 
284 class YF_API RadioBox : public Thumb, protected MSharedSelection
286 {
287 public:
290  {
291  RadioBoxBackground = Thumb::EndStyle,
292  EndStyle
293  };
299 
302 
303 public:
305  explicit
306  RadioBox(const Rect& = {});
308 
309 
310  DefPred(const ynothrow, Selected, GetState() == this)
311 
312  using MSharedSelection::GetState;
313 
319  void
320  SetSelected();
321 
323  void
324  Refresh(PaintEventArgs&&) override;
325 
331  void
332  Select();
333 
338  void
339  ShareTo(RadioBox&) const;
340 };
341 
342 
344 class YF_API RadioButton : public RadioBox, protected MLabel
345 {
346 public:
347  using MLabel::Font;
348  using MLabel::Text;
349 
351  explicit
352  RadioButton(const Rect& = {});
353 
354  void
355  Refresh(PaintEventArgs&&) override;
356 };
358 
359 } // namespace UI;
360 
361 } // namespace YSLib;
362 
363 #endif
364 
size_t StyleItem
标识样式渲染项的类型。
Definition: ystyle.h:250
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
shared_ptr< MSelector > p_selector
Definition: Selector.h:246
复选框模块。
Definition: Selector.h:90
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:172
Drawing::Font Font
字体。
Definition: label.h:61
DeclEvent(HViewEvent, ViewChanged) DeclEvent(HIndexEvent
视图变更事件。
复选框。
Definition: Selector.h:132
单选按钮。
Definition: Selector.h:344
部件绘制参数。
Definition: ywgtevt.h:276
enum SelectedState:yimpl(size_t){Unchecked=0, Checked=1, Partial=2} StateType
选择框选中状态类型。
Definition: Selector.h:101
#define YF_API
Definition: Platform.h:64
GMSelector(StateType st)
Definition: Selector.h:66
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:107
基本按钮。
Definition: button.h:46
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
#define yimpl(...)
实现标签。
Definition: ydef.h:177
MSelector::HSelectedEvent HTickedEvent
选择框选中事件委托类型。
Definition: Selector.h:109
单选框。
Definition: Selector.h:285
String Text
标签文本。
Definition: label.h:76
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活:使用指定屏幕、有效性、前景色和默认背景色。
单选框模块。
Definition: Selector.h:226
选择器模型模板。
Definition: Selector.h:50
void SetSelected(ListType::size_type)
按指定项目索引设置选中项目。
MSelector::SelectedArgs SelectedArgs
单选框选中状态参数类型。
Definition: Selector.h:235
DeclDelegate(HSelectedEvent, SelectedArgs) StateType State
选中事件委托模板。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
MSelector mSelector
Definition: Selector.h:113
bool UpdateState(StateType st)
Definition: Selector.h:75
IWidget * StateType
单选框选中状态类型。
Definition: Selector.h:232
简单 UI 事件参数类。
Definition: ywgtevt.h:252
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
复选按钮。
Definition: Selector.h:202
标签模块。
Definition: label.h:58
Selected const shared_ptr< ListType > const pair< Color, Color > Selected
Definition: textlist.h:122
StyleItem
视觉样式项目。
Definition: button.h:53
MSelector::HSelectedEvent HSelectedEvent
单选框选中事件委托类型。
Definition: Selector.h:237
StateType StateType
状态类型。
Definition: Selector.h:54