YSTest: Selector.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

Selector.h
浏览该文件的文档.
1 /*
2 © 2011-2016 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>;
57
59 StateType State;
60
61 GMSelector()
62 : State()
63 {}
64 GMSelector(StateType st)
65 : State(st)
66 {}
67
72 bool
73 UpdateState(StateType st)
74 {
75 const auto old(State);
76
77 State = st;
78 return st != old;
79 }
80 };
81
82
88 class YF_API MCheckBox
89 {
90 public:
92
93 using StateType = enum SelectedState : yimpl(size_t)
95 {
96 Unchecked = 0,
97 Checked = 1,
98 Partial = 2
99 };
100 using MSelector = GMSelector<StateType>;
105 using TickedArgs = MSelector::SelectedArgs;
107
108 protected:
109 MSelector mSelector;
110
111 public:
113 GEvent<void(TickedArgs)> Ticked;
114
115 MCheckBox(StateType st = Unchecked)
116 : mSelector(st)
117 {}
118
119 DefGetter(const ynothrow, StateType, State, mSelector.State)
120 };
122
123
128 class YF_API CheckBox : public Thumb, protected MCheckBox
129 {
130 public:
135 enum StyleItem : Styles::StyleItem
136 {
137 CheckBoxBackground = Thumb::EndStyle,
138 EndStyle
139 };
141
142 using MCheckBox::StateType;
143 using MCheckBox::Checked;
144 using MCheckBox::Unchecked;
145 using MCheckBox::Partial;
147 using MCheckBox::TickedArgs;
149
151 using MCheckBox::Ticked;
152
157 explicit
158 CheckBox(const Rect& = {});
159 DefDeMoveCtor(CheckBox)
160
161 DefPred(const ynothrow, Ticked, GetState() == Checked)
162
164 using MCheckBox::GetState;
165
171 void
172 SetTicked(StateType);
173
178 void
179 Refresh(PaintEventArgs&&) override;
180
186 void
187 Tick(StateType);
188 };
189
190
195 class YF_API CheckButton : public CheckBox, protected MLabel
196 {
197 public:
199 using MLabel::ForeColor;
200 using MLabel::Font;
201 using MLabel::Text;
202
207 explicit
208 CheckButton(const Rect& = {});
209
210 void
211 Refresh(PaintEventArgs&&) override;
212 };
213
214
221 class YF_API MSharedSelection
222 {
223 public:
225
226 using StateType = observer_ptr<IWidget>;
228 using MSelector = GMSelector<StateType>;
230 using SelectedArgs = MSelector::SelectedArgs;
232
233 private:
239 shared_ptr<MSelector> p_selector;
240
241 public:
246 GEvent<void(SelectedArgs)> Selected;
247
249
250 MSharedSelection(StateType st = {})
251 : p_selector(make_shared<MSelector>(st))
252 {}
253 MSharedSelection(shared_ptr<MSelector> p_sel, StateType st = {})
254 : p_selector(p_sel ? std::move(p_sel)
255 : make_shared<MSelector>(st))
256 {}
258
259 DefGetter(const ynothrow, StateType, State, p_selector->State)
260
261 DefSetter(, StateType, State, p_selector->State)
262
267 void
268 ShareTo(MSharedSelection&) const;
269
270 PDefH(bool, UpdateState, StateType st)
271 ImplRet(p_selector->UpdateState(st))
272 };
273
274
276
277 class YF_API RadioBox : public Thumb, protected MSharedSelection
279 {
280 public:
282 enum StyleItem : Styles::StyleItem
283 {
284 RadioBoxBackground = Thumb::EndStyle,
285 EndStyle
286 };
287 using MSharedSelection::StateType;
289 using MSharedSelection::SelectedArgs;
290
292 using MSharedSelection::Selected;
293
295 explicit
296 RadioBox(const Rect& = {});
297 DefDeMoveCtor(RadioBox)
298
299
300 DefPred(const ynothrow, Selected, GetState().get() == this)
301
302 using MSharedSelection::GetState;
303
309 void
310 SetSelected();
311
313 void
314 Refresh(PaintEventArgs&&) override;
315
321 void
322 Select();
323
328 void
329 ShareTo(RadioBox&) const;
330 };
331
332
334 class YF_API RadioButton : public RadioBox, protected MLabel
335 {
336 public:
338 using MLabel::ForeColor;
339 using MLabel::Font;
340 using MLabel::Text;
341
343 explicit
344 RadioButton(const Rect& = {});
345
346 void
347 Refresh(PaintEventArgs&&) override;
348 };
350
351 } // namespace UI;
352
353 } // namespace YSLib;
354
355 #endif
356
YSLib::UI::MSharedSelection::p_selector
shared_ptr< MSelector > p_selector
共享状态。
Definition: Selector.h:239
YSLib::UI::GMSelector::State
StateType State
状态。
Definition: Selector.h:59
YSLib::UI::MSharedSelection::SelectedArgs
MSelector::SelectedArgs SelectedArgs
单选框选中状态参数类型。
Definition: Selector.h:230
platform::KeyCodes::DS::Select
Definition: Keys.h:217
YSLib::GEvent< void(TickedArgs)>
YSLib::UI::GMSelector< StateType >::StateType
StateType StateType
状态类型。
Definition: Selector.h:54
YSLib::UI::CheckBox
复选框。
Definition: Selector.h:128
YSLib::UI::MCheckBox::TickedArgs
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:105
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::UI::MSharedSelection::StateType
observer_ptr< IWidget > StateType
单选框选中状态类型。
Definition: Selector.h:227
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::UI::MLabel::ForeColor
Color ForeColor
默认前景色。
Definition: Label.h:77
YSLib::UI::MSharedSelection::Selected
GEvent< void(SelectedArgs)> Selected
单选框选中事件。
Definition: Selector.h:246
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::MSharedSelection
单选框模块。
Definition: Selector.h:221
YSLib::UI::MCheckBox
复选框模块。
Definition: Selector.h:88
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
YSLib::UI::MSharedSelection::MSharedSelection
MSharedSelection(StateType st={})
Definition: Selector.h:250
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::UI::MSharedSelection::MSharedSelection
MSharedSelection(shared_ptr< MSelector > p_sel, StateType st={})
Definition: Selector.h:253
YSLib::UI::Thumb::StyleItem
StyleItem
视觉样式项目。
Definition: Button.h:53
YSLib::UI::GMSelector::UpdateState
bool UpdateState(StateType st)
更新状态。
Definition: Selector.h:73
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:166
UI
YSLib::UI::MCheckBox::Ticked
GEvent< void(TickedArgs)> Ticked
复选框选中事件。
Definition: Selector.h:113
YSLib::UI::CheckButton
复选按钮。
Definition: Selector.h:195
YSLib::UI::Styles::StyleItem
size_t StyleItem
标识样式渲染项的类型。
Definition: YStyle.h:374
YSLib::UI::GMSelector::GMSelector
GMSelector(StateType st)
Definition: Selector.h:64
YModules.h
YSLib::UI::Thumb::EndStyle
Definition: Button.h:56
YSLib::UI::RadioBox
单选框。
Definition: Selector.h:278
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
YSLib::UI::Thumb
基本按钮。
Definition: Button.h:46
YSLib::UI::GMSelector::GMSelector
GMSelector()
Definition: Selector.h:61
YSLib::UI::MCheckBox::MCheckBox
MCheckBox(StateType st=Unchecked)
Definition: Selector.h:115
YSLib::UI::MCheckBox::mSelector
MSelector mSelector
Definition: Selector.h:109
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::RadioButton
单选按钮。
Definition: Selector.h:334
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:231
YSLib::UI::GMSelector
选择器模型模板。
Definition: Selector.h:50
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: Label.h:78
YSLib::UI::MLabel
标签模块。
Definition: Label.h:61
YSLib::UI::MCheckBox::StateType
enum SelectedState:yimpl(size_t){Unchecked=0, Checked=1, Partial=2} StateType
选择框选中状态类型。
Definition: Selector.h:99
DefSetter
#define DefSetter(_q, _t, _n, _m)
Definition: YBaseMacro.h:251
YSLib::UI::GValueEventArgs
简单 UI 事件参数类。
Definition: YWidgetEvent.h:299