YSTest: ListControl.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

ListControl.h
浏览该文件的文档.
1 /*
2 © 2011-2015 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_ListControl_h_
29 #define YSL_INC_UI_ListControl_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YControl
33 #include YFM_YSLib_UI_YGUI
34 #include YFM_YSLib_UI_Label
35 #include YFM_YSLib_UI_Viewer
36
37 namespace YSLib
38 {
39
40 namespace UI
41 {
42
47 using IndexEventArgs = GValueEventArgs<size_t>;
48
49
55 class YF_API AMUnitControlList : protected AMUnitList
56 {
57 public:
63 using ViewArgs = GValueEventArgs<bool>;
64
71 GEvent<void(ViewArgs)> ViewChanged;
78 GEvent<void(IndexEventArgs)> Selected;
85 GEvent<void(IndexEventArgs)> Confirmed;
90 GEvent<void(size_t)> Iterated;
91
92 private:
93 unique_ptr<IWidget> p_unit;
94
95 public:
101 explicit
102 AMUnitControlList(unique_ptr<IWidget>);
103 DefDeMoveCtor(AMUnitControlList)
104
105
106 using AMUnitList::GetFullViewHeight;
108 using AMUnitList::GetItemHeight;
110 IWidget&
111 GetUnitRef() const ImplI(AMUnitList);
113 using AMUnitList::GetViewPosition;
114
120 void
121 SetUnit(unique_ptr<IWidget>);
122
128 WidgetIterator
129 MakeIterator(size_t);
130 };
131
132
138 class YF_API MTextList : public AMUnitControlList
139 {
140 public:
141 using ItemType = String;
142 using ListType = vector<ItemType>;
143 using IndexType = typename ListType::size_type;
144
145 protected:
146 mutable shared_ptr<ListType> hList;
147
148 public:
150 MLabel LabelBrush{};
151
157 explicit
158 MTextList(const shared_ptr<ListType>& = {});
159 DefDeMoveCtor(MTextList)
160
161
165 DefGetter(const ynothrow, const ListType&, List, *hList)
170 DefGetter(ynothrow, ListType&, ListRef, *hList)
171
172 protected:
178 SDst
179 GetItemHeightCore() const override;
180
181 public:
183 size_t
184 GetTotal() const ImplI(AMUnitList);
185
191 void
192 SetList(const shared_ptr<ListType>&);
193 };
194
195
201 class YF_API TextList : public Control, public MTextList, protected MHilightText
202 {
203 public:
205
206 enum SelectionOption : size_t
208 {
210 ClearSelectionOnConfirm,
212 ClearSelectionOnLeave,
214 SelectOnHover,
215 SelectionOptionMax
216 };
217
219 std::bitset<SelectionOptionMax> SelectionOptions{};
221 std::function<bool(IWidget&)> IsRelated{};
223
227 Color ForeColor{Drawing::ColorSpace::Black};
229 using MHilightText::HilightBackColor;
231 using MHilightText::HilightTextColor;
232
237 explicit
238 TextList(const Rect& = {}, const shared_ptr<ListType>& = {},
239 const pair<Color, Color>& = FetchGUIConfiguration().Colors.GetPair(
240 Styles::Highlight, Styles::HighlightText));
241 DefDeMoveCtor(TextList)
242
243 DefPredMem(const ynothrow, Selected, vwList)
245 PDefH(bool, Contains, ListType::size_type i) const ynothrow
246 ImplRet(vwList.Contains(i))
247
249 DefGetter(override, WidgetRange, Children, WidgetRange(begin(), end()))
250 DefGetterMem(const ynothrow, ListType::size_type, HeadIndex, vwList)
252 size_t
253 GetLastLabelIndex() const;
254 DefGetterMem(const ynothrow, ListType::size_type, SelectedIndex, vwList)
256 PDefH(Rect, GetUnitBounds, size_t idx)
257 ImplRet(Rect(GetUnitLocation(idx), GetWidth(), GetItemHeight()))
258
264 void
265 SetList(const shared_ptr<ListType>&);
269 void
270 SetSelected(ListType::size_type);
271
277 PDefH(void, AdjustViewForContent, )
278 ImplExpr(MTextList::AdjustViewForContent(GetHeight()))
279
287 PDefH(void, AdjustViewLength, )
288 ImplExpr(AdjustViewLengthForHeight(GetItemHeight(), GetHeight()))
289
290 private:
294 void
295 CallSelected();
296
297 public:
298 PDefH(void, ClearSelected, )
299 ImplExpr(vwList.ClearSelected())
300
301 private:
308 void
309 ClearSelectedOnLeave(CursorEventArgs&&);
310
311 protected:
318 void
319 InvalidateSelected(ListType::difference_type offset,
320 ListType::size_type diff = 1);
321
328 void
329 InvalidateSelected2(ListType::difference_type, ListType::difference_type);
330
331 private:
335 void
336 InvokeConfirmed(ListType::size_type);
337
338 public:
342 void
343 LocateViewPosition(SDst);
344
351 void
352 Refresh(PaintEventArgs&&) override;
353
359 void
360 ResetView();
361
366 void
367 SelectFirst();
368
373 void
374 SelectLast();
375
377
378 WidgetIterator
379 begin();
380
381 WidgetIterator
382 end();
384 };
385
387
388
392 YF_API void
393 ResizeForContent(TextList&);
394
402 YF_API void
403 UpdateView(TextList&, bool is_active = {});
405
406 } // namespace UI;
407
408 } // namespace YSLib;
409
410 #endif
411
YSLib::UI::AMUnitControlList
控件列表模块。
Definition: ListControl.h:55
YSLib::UI::ImplExpr
IWidget bool b ImplExpr(wgt.GetController().SetEnabled(b)) YF_API bool Enable(IWidget &
设置部件可用性，且当可用性改变时无效化部件区域。
DefPredMem
#define DefPredMem(_q, _n, _m)
Definition: YBaseMacro.h:237
YSLib::UI::Styles::HighlightText
Definition: YStyle.h:327
YSLib::UI::TextList::SelectOnHover
悬停时自动选择。
Definition: ListControl.h:214
YSLib::GEvent< void(ViewArgs)>
YSLib::UI::AMUnitControlList::ViewChanged
GEvent< void(ViewArgs)> ViewChanged
视图变更事件。
Definition: ListControl.h:71
YSLib::UI::Control
控件。
Definition: YControl.h:275
YSLib::Consoles::Black
Definition: YConsole.h:53
YSLib::UI::MTextList::ListType
vector< ItemType > ListType
列表类型。
Definition: ListControl.h:142
YSLib::UI::UpdateView
void UpdateView(TextList &tl, bool is_active)
Definition: ListControl.cpp:425
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:386
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:519
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::AMUnitControlList::p_unit
unique_ptr< IWidget > p_unit
Definition: ListControl.h:93
YSLib::UI::MHilightText::HilightBackColor
Color HilightBackColor
高亮背景色。
Definition: Label.h:217
YSLib::UI::MTextList::hList
shared_ptr< ListType > hList
文本列表句柄。
Definition: ListControl.h:146
YSLib::UI::MHilightText
高亮文本模块。
Definition: Label.h:213
Color
Pixel Color
Definition: CharRenderer.cpp:58
YSLib::UI::TextList::SelectionOption
SelectionOption
选择操作选项。
Definition: ListControl.h:207
YSLib::UI::Styles::Highlight
高亮背景。
Definition: YStyle.h:319
YSLib::UI::MHilightText::HilightTextColor
Color HilightTextColor
高亮文本色。
Definition: Label.h:219
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:246
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:46
YSLib::UI::TextList::ClearSelectionOnConfirm
确认时自动清空选择。
Definition: ListControl.h:210
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
YSLib::UI::AMUnitControlList::Iterated
GEvent< void(size_t)> Iterated
迭代器迭代事件。
Definition: ListControl.h:90
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::UI::AMUnitList
单元部件列表模块。
Definition: Viewer.h:192
YSLib::UI::ResizeForContent
void ResizeForContent(TextList &tl)
Definition: ListControl.cpp:414
YSLib::UI::CursorEventArgs
指针设备输入事件参数类。
Definition: YWidgetEvent.h:210
YSLib::Drawing::GetHeight
tr GetHeight())) inline PDefH(void
按字体高度和行距调整文本区域的底边距。
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:166
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: ListControl.h:143
UI
YSLib::i
return i
Definition: YCoreUtilities.h:176
YSLib::UI::AMUnitControlList::Selected
GEvent< void(IndexEventArgs)> Selected
项目选择状态变更事件。
Definition: ListControl.h:78
YModules.h
YSLib::UI::WidgetRange
pair< WidgetIterator, WidgetIterator > WidgetRange
两个部件迭代器组成的左闭右开区间确定的迭代器范围。
Definition: YWidget.h:57
YSLib::UI::TextList
文本列表。
Definition: ListControl.h:201
YSLib::UI::MTextList
文本列表模块。
Definition: ListControl.h:138
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::UI::AMUnitControlList::Confirmed
GEvent< void(IndexEventArgs)> Confirmed
项目选中确认事件。
Definition: ListControl.h:85
YSLib::UI::TextList::ClearSelectionOnLeave
离开时自动清空选择。
Definition: ListControl.h:212
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
ystdex::any_input_iterator
动态泛型输入迭代器。
Definition: any_iterator.hpp:209
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
YSLib::UI::MLabel
标签模块。
Definition: Label.h:61
YSLib::UI::GValueEventArgs
简单 UI 事件参数类。
Definition: YWidgetEvent.h:299
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:43