YSTest: ListControl.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ListControl.h
浏览该文件的文档.
1 /*
2 © 2011-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_ListControl_h_
29 #define YSL_INC_UI_ListControl_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YControl // for function;
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
105 using AMUnitList::GetFullViewHeight;
107 using AMUnitList::GetItemHeight;
109 YB_ATTR_nodiscard YB_PURE IWidget&
110 GetUnitRef() const ImplI(AMUnitList);
112 using AMUnitList::GetViewPosition;
113
119 void
120 SetUnit(unique_ptr<IWidget>);
121
127 YB_ATTR_nodiscard WidgetIterator
128 MakeIterator(size_t);
129 };
130
131
137 class YF_API MTextList : public AMUnitControlList
138 {
139 public:
141 using ItemType = String;
143 using ListType = vector<ItemType>;
145 using IndexType = typename ListType::size_type;
146
147 protected:
149 mutable shared_ptr<ListType> hList;
150
151 public:
153 MLabel LabelBrush{};
154
160 explicit
161 MTextList(const shared_ptr<ListType>& = {});
162 DefDeMoveCtor(MTextList)
163
164
168 DefGetter(const ynothrow, const ListType&, List, *hList)
173 DefGetter(ynothrow, ListType&, ListRef, *hList)
174
175 protected:
181 YB_ATTR_nodiscard YB_PURE SDst
182 GetItemHeightCore() const override;
183
184 public:
186 YB_ATTR_nodiscard YB_PURE size_t
187 GetTotal() const ImplI(AMUnitList);
188
194 void
195 SetList(const shared_ptr<ListType>&);
196 };
197
198
204 class YF_API TextList : public Control, public MTextList, protected MHilightText
205 {
206 public:
208
209 enum SelectionOption : size_t
211 {
213 ClearSelectionOnConfirm,
215 ClearSelectionOnLeave,
217 SelectOnHover,
218 SelectionOptionMax
219 };
220
222 std::bitset<SelectionOptionMax> SelectionOptions{};
227 function<bool(IWidget&)> IsRelated{};
229
233 Color ForeColor{Drawing::ColorSpace::Black};
235 using MHilightText::HilightBackColor;
237 using MHilightText::HilightTextColor;
238
243 explicit
244 TextList(const Rect& = {}, const shared_ptr<ListType>& = {},
245 const pair<Color, Color>& = FetchGUIConfiguration().Colors.GetPair(
246 Styles::Highlight, Styles::HighlightText));
247
248 DefPredMem(const ynothrow, Selected, vwList)
250 PDefH(bool, Contains, ListType::size_type i) const ynothrow
251 ImplRet(vwList.Contains(i))
252
254 DefGetter(override, WidgetRange, Children, WidgetRange(begin(), end()))
255 DefGetterMem(const ynothrow, ListType::size_type, HeadIndex, vwList)
257 size_t
258 GetLastLabelIndex() const;
259 DefGetterMem(const ynothrow, ListType::size_type, SelectedIndex, vwList)
261 PDefH(Rect, GetUnitBounds, size_t idx)
262 ImplRet(Rect(GetUnitLocation(idx), GetWidth(), GetItemHeight()))
263
269 void
270 SetList(const shared_ptr<ListType>&);
274 void
275 SetSelected(ListType::size_type);
276
282 PDefH(void, AdjustViewForContent, )
283 ImplExpr(MTextList::AdjustViewForContent(GetHeight()))
284
292 PDefH(void, AdjustViewLength, )
293 ImplExpr(AdjustViewLengthForHeight(GetItemHeight(), GetHeight()))
294
295 private:
299 void
300 CallSelected();
301
302 public:
303 PDefH(void, ClearSelected, )
304 ImplExpr(vwList.ClearSelected())
305
306 private:
313 void
314 ClearSelectedOnLeave(CursorEventArgs&&);
315
316 protected:
323 void
324 InvalidateSelected(ListType::difference_type offset,
325 ListType::size_type diff = 1);
326
333 void
334 InvalidateSelected2(ListType::difference_type, ListType::difference_type);
335
336 private:
340 void
341 InvokeConfirmed(ListType::size_type);
342
343 public:
347 void
348 LocateViewPosition(SDst);
349
356 void
357 Refresh(PaintEventArgs&&) override;
358
364 void
365 ResetView();
366
371 void
372 SelectFirst();
373
378 void
379 SelectLast();
380
382
383 WidgetIterator
384 begin();
385
386 WidgetIterator
387 end();
389 };
390
392
393
397 YF_API void
398 ResizeForContent(TextList&);
399
407 YF_API void
408 UpdateView(TextList&, bool is_active = {});
410
411 } // namespace UI;
412
413 } // namespace YSLib;
414
415 #endif
416
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::UI::MHilightText::HilightTextColor
Color HilightTextColor
高亮文本色。
Definition: Label.h:217
YSLib::UI::UpdateView
YF_API void UpdateView(TextList &, bool is_active={})
更新文本列表视图。
Definition: ListControl.cpp:425
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:488
YSLib::UI::TextList::ClearSelectionOnLeave
@ ClearSelectionOnLeave
离开时自动清空选择。
Definition: ListControl.h:215
YSLib::UI::MHilightText::HilightBackColor
Color HilightBackColor
高亮背景色。
Definition: Label.h:215
YSLib::UI::AMUnitList
单元部件列表模块。
Definition: Viewer.h:201
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::TextList::SelectOnHover
@ SelectOnHover
悬停时自动选择。
Definition: ListControl.h:217
YSLib::UI::GValueEventArgs
简单 UI 事件参数类。
Definition: YWidgetEvent.h:306
YSLib::UI::MTextList::hList
shared_ptr< ListType > hList
文本列表句柄。
Definition: ListControl.h:149
YSLib::UI::MTextList
文本列表模块。
Definition: ListControl.h:138
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::TextList::SelectionOption
SelectionOption
选择操作选项。
Definition: ListControl.h:211
YSLib::UI::AMUnitControlList::Iterated
GEvent< void(size_t)> Iterated
迭代器迭代事件。
Definition: ListControl.h:90
YSLib::UI::Control
控件。
Definition: YControl.h:271
YSLib::UI::CursorEventArgs
指针设备输入事件参数类。
Definition: YWidgetEvent.h:216
YSLib::UI::Styles::Highlight
@ Highlight
高亮背景。
Definition: YStyle.h:319
ystdex::any_input_iterator
动态泛型输入迭代器。
Definition: any_iterator.hpp:247
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::AMUnitControlList
控件列表模块。
Definition: ListControl.h:56
YSLib::UI::AMUnitControlList::ViewChanged
GEvent< void(ViewArgs)> ViewChanged
视图变更事件。
Definition: ListControl.h:71
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:396
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:47
ystdex::cpp2017::end
auto end(_tRange &c) -> decltype(c.end())
Definition: range.hpp:345
YSLib::UI::MTextList::ListType
vector< ItemType > ListType
列表类型。
Definition: ListControl.h:143
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:517
YSLib::UI::bool
IWidget bool b bool
Definition: YControl.h:122
YSLib::i
return i
Definition: YCoreUtilities.h:177
YSLib::Drawing::ColorSpace::Black
@ Black
Definition: YGDIBase.h:262
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
platform::containers::vector
std::vector< _type, _tAlloc > vector
Definition: Container.h:102
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
Color
Pixel Color
Definition: CharRenderer.cpp:59
YSLib::UI::MLabel
标签模块。
Definition: Label.h:62
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::TextList
文本列表。
Definition: ListControl.h:205
YSLib::UI::AMUnitList::GetItemHeight
YB_ATTR_nodiscard SDst GetItemHeight() const
取项目行高：调用 GetItemHeightCore 取结果。
Definition: Viewer.cpp:166
YSLib::UI::AMUnitControlList::Confirmed
GEvent< void(IndexEventArgs)> Confirmed
项目选中确认事件。
Definition: ListControl.h:85
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: ListControl.h:145
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::UI::MHilightText
高亮文本模块。
Definition: Label.h:212
YSLib::UI::AMUnitControlList::Selected
GEvent< void(IndexEventArgs)> Selected
项目选择状态变更事件。
Definition: ListControl.h:78
YSLib::UI::AMUnitList::GetFullViewHeight
YB_ATTR_nodiscard SDst GetFullViewHeight() const
取完整视图高。
Definition: Viewer.cpp:161
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::ImplExpr
IWidget bool b ImplExpr(wgt.GetController().SetEnabled(b)) YF_API bool Enable(IWidget &
设置部件可用性，且当可用性改变时无效化部件区域。
YSLib::UI::WidgetRange
pair< WidgetIterator, WidgetIterator > WidgetRange
两个部件迭代器组成的左闭右开区间确定的迭代器范围。
Definition: YWidget.h:57
YSLib::UI::TextList::ClearSelectionOnConfirm
@ ClearSelectionOnConfirm
确认时自动清空选择。
Definition: ListControl.h:213
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
YSLib::UI::TextList::DefPredMem
DefPredMem(const ynothrow, Selected, vwList) PDefH(bool
YSLib::Drawing::GetHeight
YB_ATTR_nodiscard YB_PURE tr GetHeight())) inline PDefH(void
按字体高度和行距调整文本区域的底边距。
YSLib::UI::AMUnitControlList::p_unit
unique_ptr< IWidget > p_unit
Definition: ListControl.h:93
YSLib::UI::Styles::HighlightText
@ HighlightText
Definition: YStyle.h:327
YSLib::UI::ResizeForContent
void ResizeForContent(TextList &tl)
Definition: ListControl.cpp:414
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) YB_ATTR_nodiscard YB_PURE bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::MTextList::DefDeMoveCtor
DefDeMoveCtor(MTextList) DefGetter(const ynothrow
取文本列表。
ystdex::cpp2017::begin
auto begin(_tRange &c) -> decltype(c.begin())
Definition: range.hpp:323