YSTest: TreeView.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

TreeView.h
浏览该文件的文档.
1 /*
2 © 2014-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_TreeView_h_
29 #define YSL_INC_UI_TreeView_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_ComboList
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;
75 std::function<String(const ValueNode&)> ExtractText{DefaultExtractText};
80 Color CursorOverColor{39, 199, 247};
85 ValueNode TreeRoot{};
87 SDst UnitIndent = 16;
88
89 protected:
95 size_t idxCursorOver = size_t(-1);
96
97 private:
106 IndentMap indent_map{};
107 SPos tmp_margin_left = 0;
116 set<NodePath> expanded{};
117
118 public:
120 explicit
121 TreeList(const Rect& = {}, const shared_ptr<ListType>& = {},
122 const pair<Color, Color>& = FetchGUIConfiguration().Colors.GetPair(
123 Styles::Highlight, Styles::HighlightText));
124 DefDeMoveCtor(TreeList)
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 SDst
145 GetIndentWidth(IndexType) const;
147 NodePath
148 GetNodePath(IndexType) const;
149 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>& = {});
227 DefDeMoveCtor(TreeView)
232 ~TreeView() override;
233
234 DefGetter(, GEvent<void(IndexType)>&, Collapse, GetTreeListRef().Collapse)
235 DefGetter(, GEvent<void(IndexType)>&, Expand, GetTreeListRef().Expand)
236 DefGetter(, std::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::TreeView
带滚动条的树形视图。
Definition: TreeView.h:219
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::UI::FetchGUIConfiguration
GUIConfiguration & FetchGUIConfiguration()
Definition: YGUI.cpp:519
YSLib::GEvent< void(IndexType)>
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
cast.hpp
C++ 转换模板。
UI
YSLib::UI::ListBox::IndexType
TextList::IndexType IndexType
Definition: ComboList.h:55
YSLib::UI::TreeList::Expand
GEvent< void(IndexType)> Expand
展开节点前的回调。
Definition: TreeView.h:70
platform::size_t
YF_API size_t
Definition: FileIO.h:1353
YSLib::UI::Styles::HighlightText
Definition: YStyle.h:327
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
Color
Pixel Color
Definition: CharRenderer.cpp:58
ystdex::polymorphic_downcast
_pDst polymorphic_downcast(_tSrc *v)
多态类指针向派生类指针转换。
Definition: cast.hpp:238
YSLib::UI::TextList
文本列表。
Definition: ListControl.h:201
YSLib::UI::TreeList::IndentType
size_t IndentType
缩进类型：用于表示视图中项目的层次。
Definition: TreeView.h:54
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
ystdex
特性测试宏。
Definition: ydef.h:822
YSLib::UI::TreeList::NodePath
vector< IndexType > NodePath
Definition: TreeView.h:65
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YF_API
#define YF_API
Definition: Platform.h:56
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
YSLib::UI::TreeList::NodeState
NodeState
节点状态。
Definition: TreeView.h:56
YSLib::UI::MTextList::IndexType
typename ListType::size_type IndexType
索引类型。
Definition: ListControl.h:143
YModules.h
YSLib::UI::ListBox
带滚动条的文本列表框。
Definition: ComboList.h:49
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:58
std
Definition: memory.hpp:1183
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::TreeList
树形列表。
Definition: TreeView.h:50
YSLib::UI::TreeList::IndentMap
map< IndexType, IndentType > IndentMap
Definition: TreeView.h:63
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::UI::TreeView::NodePath
TreeList::NodePath NodePath
Definition: TreeView.h:222
YSLib::UI::TreeList::Collapse
GEvent< void(IndexType)> Collapse
收缩节点后的回调。
Definition: TreeView.h:68
YSLib::UI::Styles::Highlight
高亮背景。
Definition: YStyle.h:319
YSLib::Text::String
YSLib 标准字符串（使用 UCS-2 作为内部编码）。
Definition: YString.h:46
ystdex::details::get
get())
Definition: cast.hpp:102