YSTest: Selector.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Selector.h
浏览该文件的文档.
1 /*
2 © 2011-2016, 2020 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
160 DefPred(const ynothrow, Ticked, GetState() == Checked)
161
162
163 using MCheckBox::GetState;
164
170 void
171 SetTicked(StateType);
172
177 void
178 Refresh(PaintEventArgs&&) override;
179
185 void
186 Tick(StateType);
187 };
188
189
194 class YF_API CheckButton : public CheckBox, protected MLabel
195 {
196 public:
198 using MLabel::ForeColor;
199 using MLabel::Font;
200 using MLabel::Text;
201
206 explicit
207 CheckButton(const Rect& = {});
208
213 void
214 Refresh(PaintEventArgs&&) override;
215 };
216
217
224 class YF_API MSharedSelection
225 {
226 public:
228
229 using StateType = observer_ptr<IWidget>;
231 using MSelector = GMSelector<StateType>;
233 using SelectedArgs = MSelector::SelectedArgs;
235
236 private:
242 shared_ptr<MSelector> p_selector;
243
244 public:
249 GEvent<void(SelectedArgs)> Selected;
250
252
253 MSharedSelection(StateType st = {})
254 : p_selector(make_shared<MSelector>(st))
255 {}
256 MSharedSelection(shared_ptr<MSelector> p_sel, StateType st = {})
257 : p_selector(p_sel ? std::move(p_sel)
258 : make_shared<MSelector>(st))
259 {}
261
262 DefGetter(const ynothrow, StateType, State, p_selector->State)
263
264 DefSetter(, StateType, State, p_selector->State)
265
270 void
271 ShareTo(MSharedSelection&) const;
272
273 PDefH(bool, UpdateState, StateType st)
274 ImplRet(p_selector->UpdateState(st))
275 };
276
277
279
280 class YF_API RadioBox : public Thumb, protected MSharedSelection
282 {
283 public:
285 enum StyleItem : Styles::StyleItem
286 {
287 RadioBoxBackground = Thumb::EndStyle,
288 EndStyle
289 };
290 using MSharedSelection::StateType;
292 using MSharedSelection::SelectedArgs;
293
295 using MSharedSelection::Selected;
296
298 explicit
299 RadioBox(const Rect& = {});
300
302 DefPred(const ynothrow, Selected, GetState().get() == this)
303
304 using MSharedSelection::GetState;
305
311 void
312 SetSelected();
313
315 void
316 Refresh(PaintEventArgs&&) override;
317
323 void
324 Select();
325
330 void
331 ShareTo(RadioBox&) const;
332 };
333
334
336 class YF_API RadioButton : public RadioBox, protected MLabel
337 {
338 public:
340 using MLabel::ForeColor;
341 using MLabel::Font;
342 using MLabel::Text;
343
345 explicit
346 RadioButton(const Rect& = {});
347
352 void
353 Refresh(PaintEventArgs&&) override;
354 };
356
357 } // namespace UI;
358
359 } // namespace YSLib;
360
361 #endif
362
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
YSLib::UI::GMSelector::GMSelector
GMSelector(StateType st)
Definition: Selector.h:64
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:488
YSLib::UI::GValueEventArgs
简单 UI 事件参数类。
Definition: YWidgetEvent.h:306
YSLib::UI::RadioBox::StyleItem
StyleItem
视觉样式项目。
Definition: Selector.h:286
YSLib::UI::RadioBox
单选框。
Definition: Selector.h:282
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::CheckBox::StyleItem
StyleItem
视觉样式项目。
Definition: Selector.h:136
YSLib::UI::GMSelector
选择器模型模板。
Definition: Selector.h:51
YSLib::UI::MSharedSelection::p_selector
shared_ptr< MSelector > p_selector
共享状态。
Definition: Selector.h:242
YSLib::UI::MCheckBox::TickedArgs
MSelector::SelectedArgs TickedArgs
选择框选中状态参数类型。
Definition: Selector.h:105
YSLib::UI::MSharedSelection::SelectedArgs
MSelector::SelectedArgs SelectedArgs
单选框选中状态参数类型。
Definition: Selector.h:233
YSLib::UI::MSharedSelection::DefGetter
DefGetter(const ynothrow, StateType, State, p_selector->State) DefSetter(
YSLib::UI::MSharedSelection::MSharedSelection
MSharedSelection(shared_ptr< MSelector > p_sel, StateType st={})
Definition: Selector.h:256
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::CheckBox
复选框。
Definition: Selector.h:129
platform::KeyCodes::DS::Select
@ Select
Definition: Keys.h:218
YSLib::UI::Thumb
基本按钮。
Definition: Button.h:47
YSLib::UI::MSharedSelection
单选框模块。
Definition: Selector.h:225
YSLib::UI::GMSelector::GMSelector
GMSelector()
Definition: Selector.h:61
YSLib::UI::MSharedSelection::Selected
GEvent< void(SelectedArgs)> Selected
单选框选中事件。
Definition: Selector.h:249
YSLib::UI::MCheckBox::Ticked
GEvent< void(TickedArgs)> Ticked
复选框选中事件。
Definition: Selector.h:113
YSLib::UI::MLabel::Font
Drawing::Font Font
字体。
Definition: Label.h:78
YSLib::UI::GMSelector< StateType >::StateType
StateType StateType
状态类型。
Definition: Selector.h:54
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::UI::MCheckBox::StateType
enum SelectedState :yimpl(size_t) { Unchecked=0, Checked=1, Partial=2 } StateType
选择框选中状态类型。
Definition: Selector.h:99
YSLib::UI::MCheckBox::mSelector
MSelector mSelector
Definition: Selector.h:109
YSLib::UI::MLabel::ForeColor
Color ForeColor
默认前景色。
Definition: Label.h:77
YSLib::UI::RadioButton
单选按钮。
Definition: Selector.h:337
YSLib::UI::GMSelector::State
StateType State
状态。
Definition: Selector.h:59
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::UI::GMSelector::UpdateState
bool UpdateState(StateType st)
更新状态。
Definition: Selector.h:73
YSLib::UI::MLabel
标签模块。
Definition: Label.h:62
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::MCheckBox
复选框模块。
Definition: Selector.h:89
YSLib::UI::MCheckBox::MCheckBox
MCheckBox(StateType st=Unchecked)
Definition: Selector.h:115
DefSetter
#define DefSetter(_q, _t, _n, _m)
Definition: YBaseMacro.h:252
YSLib::UI::MSharedSelection::MSharedSelection
MSharedSelection(StateType st={})
Definition: Selector.h:253
YSLib::UI::Thumb::EndStyle
@ EndStyle
Definition: Button.h:56
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::UI::CheckButton
复选按钮。
Definition: Selector.h:195
YSLib::UI::MLabel::Text
String Text
标签文本。
Definition: Label.h:94
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::MSharedSelection::StateType
observer_ptr< IWidget > StateType
单选框选中状态类型。
Definition: Selector.h:230
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) YB_ATTR_nodiscard YB_PURE bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::Styles::StyleItem
size_t StyleItem
标识样式渲染项的类型。
Definition: YStyle.h:377