YSTest: Selector.h 源文件

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>
50 class GMSelector
51 {
52 public:
54 using StateType = _type;
56 using SelectedArgs = GValueEventArgs<StateType>;
58 DeclDelegate(HSelectedEvent, SelectedArgs)
59
60
61 StateType State;
62
63 GMSelector()
64 : State()
65 {}
66 GMSelector(StateType st)
67 : State(st)
68 {}
69
70 /*
71 \brief 更新状态。
72 \return 是否和旧状态相同。
73 */
74 bool
75 UpdateState(StateType st)
76 {
77 const StateType old(State);
78
79 State = st;
80 return st != old;
81 }
82 };
83
84
90 class YF_API MCheckBox
91 {
92 public:
94
95 using StateType = enum SelectedState : yimpl(size_t)
97 {
98 Unchecked = 0,
99 Checked = 1,
100 Partial = 2
101 };
102 using MSelector = GMSelector<StateType>;
107 using TickedArgs = MSelector::SelectedArgs;
109 using HTickedEvent = MSelector::HSelectedEvent;
111
112 protected:
113 MSelector mSelector;
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:
139 enum StyleItem : Styles::StyleItem
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;
154 using MCheckBox::HTickedEvent;
155
157 using MCheckBox::Ticked;
158
159 public:
164 explicit
165 CheckBox(const Rect& = {});
166 DefDeMoveCtor(CheckBox)
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
226 class YF_API MSharedSelection
227 {
228 public:
230
231 using StateType = IWidget*;
233 using MSelector = GMSelector<StateType>;
235 using SelectedArgs = MSelector::SelectedArgs;
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:
253 DeclEvent(HSelectedEvent, Selected)
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:
289 enum StyleItem : Styles::StyleItem
290 {
291 RadioBoxBackground = Thumb::EndStyle,
292 EndStyle
293 };
294 using MSharedSelection::StateType;
296 using MSharedSelection::SelectedArgs;
298 using MSharedSelection::HSelectedEvent;
299
301 using MSharedSelection::Selected;
302
303 public:
305 explicit
306 RadioBox(const Rect& = {});
307 DefDeMoveCtor(RadioBox)
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
YSLib::UI::Styles::StyleItem
size_t StyleItem
标识样式渲染项的类型。
Definition: ystyle.h:250
YSLib::UI::Refresh
void Refresh(PaintEventArgs &&) override
刷新：按指定参数绘制界面并更新状态。
YSLib::UI::MSharedSelection::p_selector
shared_ptr< MSelector > p_selector
Definition: Selector.h:246
YSLib::UI::MCheckBox
复选框模块。
Definition: Selector.h:90
YModules.h
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:172
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: label.h:61
YSLib::UI::DeclEvent
DeclEvent(HViewEvent, ViewChanged) DeclEvent(HIndexEvent
视图变更事件。
YSLib::UI::CheckBox
复选框。
Definition: Selector.h:132
YSLib::UI::RadioButton
单选按钮。
Definition: Selector.h:344
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: ywgtevt.h:276
YSLib::UI::MCheckBox::StateType
enum SelectedState:yimpl(size_t){Unchecked=0, Checked=1, Partial=2} StateType
选择框选中状态类型。
Definition: Selector.h:101
YF_API
#define YF_API
Definition: Platform.h:64
YSLib::UI::GMSelector::GMSelector
GMSelector(StateType st)
Definition: Selector.h:66
YSLib::UI::MCheckBox::TickedArgs
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:107
YSLib::UI::Thumb::EndStyle
Definition: button.h:56
YSLib::UI::Thumb
基本按钮。
Definition: button.h:46
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:177
YSLib::UI::MCheckBox::HTickedEvent
MSelector::HSelectedEvent HTickedEvent
选择框选中事件委托类型。
Definition: Selector.h:109
YSLib::UI::RadioBox
单选框。
Definition: Selector.h:285
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: label.h:76
YSLib::UI::PDefH
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活：使用指定屏幕、有效性、前景色和默认背景色。
YSLib::UI::MSharedSelection
单选框模块。
Definition: Selector.h:226
YSLib::UI::GMSelector
选择器模型模板。
Definition: Selector.h:50
YSLib::UI::SetSelected
void SetSelected(ListType::size_type)
按指定项目索引设置选中项目。
YSLib::UI::MSharedSelection::SelectedArgs
MSelector::SelectedArgs SelectedArgs
单选框选中状态参数类型。
Definition: Selector.h:235
YSLib::UI::GMSelector::DeclDelegate
DeclDelegate(HSelectedEvent, SelectedArgs) StateType State
选中事件委托模板。
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
DefSetter
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
YSLib::UI::MCheckBox::mSelector
MSelector mSelector
Definition: Selector.h:113
YSLib::UI::GMSelector::UpdateState
bool UpdateState(StateType st)
Definition: Selector.h:75
YSLib::UI::MSharedSelection::StateType
IWidget * StateType
单选框选中状态类型。
Definition: Selector.h:232
YSLib::UI::GValueEventArgs
简单 UI 事件参数类。
Definition: ywgtevt.h:252
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::DefDeMoveCtor
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
YSLib::UI::CheckButton
复选按钮。
Definition: Selector.h:202
YSLib::UI::MLabel
标签模块。
Definition: label.h:58
YSLib::UI::Selected
Selected const shared_ptr< ListType > const pair< Color, Color > Selected
Definition: textlist.h:122
YSLib::UI::Thumb::StyleItem
StyleItem
视觉样式项目。
Definition: button.h:53
YSLib::UI::MSharedSelection::HSelectedEvent
MSelector::HSelectedEvent HSelectedEvent
单选框选中事件委托类型。
Definition: Selector.h:237
YSLib::UI::GMSelector< StateType >::StateType
StateType StateType
状态类型。
Definition: Selector.h:54