YSTest: TreeView.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

TreeView.h
浏览该文件的文档.
1 /*
2 © 2014-2016, 2019-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_TreeView_h_
29 #define YSL_INC_UI_TreeView_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_ComboList // for function;
33 #include YFM_YSLib_Core_ValueNode // for YSLib::ValueNode;
34 #include <ystdex/cast.hpp> // for ystdex::polymorphic_downcast;
35
36 namespace YSLib
37 {
38
39 namespace UI
40 {
41
50 class YF_API TreeList : public TextList
51 {
52 public:
54 using IndentType = size_t;
56 enum class NodeState
57 {
58 None = 0,
59 Branch,
60 Expanded
61 };
63 using IndentMap = map<IndexType, IndentType>;
65 using NodePath = vector<IndexType>;
66
68 GEvent<void(IndexType)> Collapse;
70 GEvent<void(IndexType)> Expand;
76 function<String(const ValueNode&)> ExtractText{DefaultExtractText};
81 Color CursorOverColor{39, 199, 247};
86 ValueNode TreeRoot{};
88 SDst UnitIndent = 16;
89
90 protected:
96 size_t idxCursorOver = size_t(-1);
97
98 private:
107 IndentMap indent_map{};
108 SPos tmp_margin_left = 0;
117 set<NodePath> expanded{};
118
119 public:
121 explicit
122 TreeList(const Rect& = {}, const shared_ptr<ListType>& = {},
123 const pair<Color, Color>& = FetchGUIConfiguration().Colors.GetPair(
124 Styles::Highlight, Styles::HighlightText));
129 ~TreeList() override;
130
132 Rect
133 GetIndentBox() const;
138 Rect
139 GetIndentBoxBounds(IndexType) const;
141 DefGetter(const ynothrow, Size, IndentBoxSize, Size(16, GetItemHeight()))
143 DefGetter(const ynothrow, const IndentMap&, IndentMap, indent_map)
144 YB_ATTR_nodiscard YB_PURE SDst
145 GetIndentWidth(IndexType) const;
147 YB_ATTR_nodiscard NodePath
148 GetNodePath(IndexType) const;
149 YB_ATTR_nodiscard const ValueNode&
150 GetNodeRef(IndexType) const;
151
157 void
158 Bind(size_t = size_t(-1));
159
166 PDefH(void, BindView, size_t max_depth = size_t(-1))
167 ImplExpr(Bind(max_depth), ResetView())
168
175 PDefH(NodeState, CollapseNode, size_t idx)
176 ImplRet(ExpandOrCollapseNode(NodeState::Expanded, idx))
177
178 static String
179 DefaultExtractText(const ValueNode&);
180
181 static String
182 ExtractNodeName(const ValueNode&);
183
185
186
191 PDefH(NodeState, ExpandNode, size_t idx)
192 ImplRet(ExpandOrCollapseNode(NodeState::Branch, idx))
193
194 private:
195 NodeState
196 ExpandOrCollapseNode(NodeState, size_t);
197
199 void
200 ExpandOrCollapseNodeImpl(NodeState, size_t);
202
203 public:
208 NodeState
209 QueryNodeState(IndexType) const;
210 };
211
212
219 class YF_API TreeView : public ListBox
220 {
221 public:
222 using NodePath = TreeList::NodePath;
223 using IndentMap = TreeList::IndentMap;
224
225 explicit
226 TreeView(const Rect& = {}, const shared_ptr<ListType>& = {});
231 ~TreeView() override;
232
233 DefGetter(, GEvent<void(IndexType)>&, Collapse, GetTreeListRef().Collapse)
234 DefGetter(, GEvent<void(IndexType)>&, Expand, GetTreeListRef().Expand)
236 DefGetter(, function<String(const ValueNode&)>&, ExtractText,
237 GetTreeListRef().ExtractText)
238 DefGetterMem(const, Rect, IndentBox, GetTreeListRef())
239 PDefH(Rect, GetIndentBoxBounds, IndexType idx) const
240 ImplRet(GetTreeListRef().GetIndentBoxBounds(idx))
241 DefGetterMem(const ynothrow, Size, IndentBoxSize, GetTreeListRef())
242 DefGetterMem(const ynothrow, const IndentMap&, IndentMap, GetTreeListRef())
243 PDefH(SDst, GetIndentWidth, IndexType idx) const
244 ImplRet(GetTreeListRef().GetIndentWidth(idx))
245 PDefH(NodePath, GetNodePath, IndexType idx) const
246 ImplRet(GetTreeListRef().GetNodePath(idx))
247 PDefH(const ValueNode&, GetNodeRef, IndexType idx) const
248 ImplRet(GetTreeListRef().GetNodeRef(idx))
249 DefGetter(const, TreeList&, TreeListRef,
250 *ystdex::polymorphic_downcast<TreeList*>(pTextList.get()))
251 DefGetter(const, ValueNode&, TreeRootRef, GetTreeListRef().TreeRoot)
252
253 PDefH(void, Bind, size_t max_depth = size_t(-1))
254 ImplExpr(GetTreeListRef().Bind(max_depth))
255
256 PDefH(void, BindView, size_t max_depth = size_t(-1))
257 ImplExpr(GetTreeListRef().BindView(max_depth))
258
263 PDefH(void, QueryNodeState, IndexType idx)
264 ImplExpr(GetTreeListRef().QueryNodeState(idx))
265 };
266
267 } // namespace UI;
268
269 } // namespace YSLib;
270
271 #endif
272
YSLib::UI::ListBox::IndexType
TextList::IndexType IndexType
Definition: ComboList.h:55
cast.hpp
C++ 转换模板。
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:488
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
YSLib::UI::TreeList
树形列表。
Definition: TreeView.h:51
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::TreeView::~TreeView
~TreeView() override
虚析构：类定义外默认实现。
YSLib::UI::TreeList::NodeState
NodeState
节点状态。
Definition: TreeView.h:57
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::TreeView::DefGetter
DefGetter(, GEvent< void(IndexType)> &, Collapse, GetTreeListRef().Collapse) DefGetter(
YSLib::UI::Styles::Highlight
@ Highlight
高亮背景。
Definition: YStyle.h:319
ystdex::polymorphic_downcast
_pDst polymorphic_downcast(_tSrc *v)
多态类指针向派生类指针转换。
Definition: cast.hpp:238
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::map
映射容器。
Definition: map.hpp:79
NPL::Collapse
pair< TermReference, bool > Collapse(TermReference ref)
Definition: NPLA.cpp:614
YSLib::UI::TreeList::Expand
GEvent< void(IndexType)> Expand
展开节点前的回调。
Definition: TreeView.h:70
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:47
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:73
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:517
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::UI::TreeView
带滚动条的树形视图。
Definition: TreeView.h:220
platform::containers::set
std::set< _tKey, _fComp, _tAlloc > set
Definition: Container.h:126
platform::containers::vector
std::vector< _type, _tAlloc > vector
Definition: Container.h:102
YSLib::UI::TreeView::NodePath
TreeList::NodePath NodePath
Definition: TreeView.h:222
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
YSLib::UI::TreeList::~TreeList
~TreeList() override
虚析构：类定义外默认实现。
YSLib::UI::ListBox
带滚动条的文本列表框。
Definition: ComboList.h:50
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::UI::TreeList::IndentType
size_t IndentType
缩进类型：用于表示视图中项目的层次。
Definition: TreeView.h:54
Color
Pixel Color
Definition: CharRenderer.cpp:59
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::TextList
文本列表。
Definition: ListControl.h:205
YSLib::UI::TreeList::IndentMap
map< IndexType, IndentType > IndentMap
Definition: TreeView.h:63
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: ListControl.h:145
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::UI::TreeList::DefGetter
DefGetter(const ynothrow, Size, IndentBoxSize, Size(16, GetItemHeight())) DefGetter(const ynothrow
YSLib::UI::TreeList::Collapse
GEvent< void(IndexType)> Collapse
收缩节点后的回调。
Definition: TreeView.h:68
YSLib::UI::TreeList::NodePath
vector< IndexType > NodePath
Definition: TreeView.h:65
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::size_t
YF_API const char size_t
Definition: YException.h:149
ystdex::function
function_base< function_traits< _fSig, empty_function_policy::throwing >, _fSig > function
函数包装类模板。
Definition: function.hpp:900
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::UI::Styles::HighlightText
@ HighlightText
Definition: YStyle.h:327
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 &
判断点是否在部件的可视区域内。