YSTest: TabControl.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

TabControl.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_TabControl_h_
29 #define YSL_INC_UI_TabControl_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_YPanel // for function;
33 #include YFM_YSLib_UI_WidgetIteration
34
35 namespace YSLib
36 {
37
38 namespace UI
39 {
40
45 class YF_API TabBar : public Control, protected MLinearUIContainer
46 {
47 public:
48 using TabPtrType = unique_ptr<Control>;
49
51 SPos Offset = 0;
53 SDst MinWidth = 12;
59 function<void(PaintEventArgs&&)> PaintTabBackground{};
62 function<void(PaintEventArgs&&)> PaintTabForeground{DefaultPaintTabBorder};
64
65 explicit
66 TabBar(const Rect& = {});
67
68 virtual void
69 operator+=(IWidget&);
70
71 virtual bool
72 operator-=(IWidget&);
73
74 DefWidgetChildrenGetter
75
76 using MLinearUIContainer::Contains;
77
79 using MLinearUIContainer::GetCount;
80
82 static void
83 DefaultPaintTabBorder(PaintEventArgs&&);
84
86 using MLinearUIContainer::Find;
87
92 SPos
93 PerformLayout();
94
95 void
96 Refresh(PaintEventArgs&&) override;
97
102 bool
103 SwitchPage(Control&);
104 };
105
106
111 class YF_API TabControl : public Control
112 {
113 public:
114 using iterator = ystdex::subscriptive_iterator<TabControl, IWidget>;
115
117 SDst BarHeight = 24;
118
119 private:
124 unique_ptr<TabBar> p_bar;
126 observer_ptr<Panel> p_page{};
128 vector<observer_ptr<Panel>> tab_pages{};
129
130 public:
131 explicit
132 TabControl(const Rect& = {});
137 ~TabControl() override;
138
139 DefWidgetMemberIterationOperations(iterator)
140
141 PDefHOp(IWidget&, [], size_t idx) ynoexcept
142 ImplRet(YAssertNonnull(idx == 0 || p_page),
143 *ystdex::forward_as_array<observer_ptr<IWidget>>(
144 make_observer(p_bar.get()), p_page).begin()[idx])
145
146
151 void
152 operator+=(IWidget&);
153
154 DefGetter(const ynothrow, size_t, ChildrenCount, p_page ? 2 : 1)
156 Rect
157 GetPageBounds() const ynothrow;
159 DefGetter(const ynothrow, TabBar&, TabBarRef, Deref(p_bar))
164 DefGetter(const ynothrow, size_t, TabCount, GetTabBarRef().GetCount())
166 DefGetter(const ynothrow, const vector<observer_ptr<Panel>>&, Pages, tab_pages)
167
168
170 void
171 Attach(Control&);
172
178 YB_ATTR_nodiscard YB_PURE size_t
179 Find(IWidget&) const;
180
185 bool
186 SwitchTab(Control&);
187
194 bool
195 SwitchPage(size_t);
197 bool
198 SwitchPage(Control&);
200
209 void
210 UpdateTabPages();
211 };
212
213 } // namespace UI;
214
215 } // namespace YSLib;
216
217 #endif
218
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefWidgetChildrenGetter
#define DefWidgetChildrenGetter
定义部件成员迭代器范围操作。
Definition: WidgetIteration.h:113
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::Panel
面板。
Definition: YPanel.h:46
YSLib::UI::MLinearUIContainer
线性部件容器模块。
Definition: YUIContainer.h:205
YSLib::UI::TabBar
标签栏控件。
Definition: TabControl.h:46
YSLib::UI::Control
控件。
Definition: YControl.h:271
YSLib::UI::TabControl::ImplRet
size_t idx ynoexcept ImplRet(YAssertNonnull(idx==0||p_page), *ystdex::forward_as_array< observer_ptr< IWidget >>(make_observer(p_bar.get()), p_page).begin()[idx]) void operator+
添加部件并隐藏。
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::TabBar::TabPtrType
unique_ptr< Control > TabPtrType
Definition: TabControl.h:48
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:405
YSLib::UI::TabControl::~TabControl
~TabControl() override
虚析构：类定义外默认实现。
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:165
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
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::TabControl
标签容器控件。
Definition: TabControl.h:112
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
YSLib::UI::MLinearUIContainer::Contains
Index is out of vWidgets[idx] Index is out of vWidgets[idx] YB_ATTR_nodiscard YB_PURE bool Contains(IWidget &) const
判断是否包含指定部件。
Definition: YUIContainer.cpp:196
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::UI::TabControl::DefGetter
DefGetter(const ynothrow, size_t, ChildrenCount, p_page ? 2 :1) Rect GetPageBounds() const ynothrow
取页面边界。
ystdex::forward_as_array
common_array_t< _type, _tParams... > forward_as_array(_tParams &&... args)
转移指定参数至 std::array 对象。
Definition: array.hpp:68
YSLib::UI::TabControl::p_bar
unique_ptr< TabBar > p_bar
标签栏。
Definition: TabControl.h:124
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
platform::SPos
std::int16_t SPos
屏幕坐标度量。
Definition: Video.h:43
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:1151
ystdex::subscriptive_iterator
成员下标迭代器。
Definition: iterator.hpp:1193
platform_ex::Attach
void Attach(COMPtr< _iCOM > &ptr, typename COMPtr< _iCOM >::InterfaceType *p) ynothrow
Definition: Win32/include/YCLib/COM.h:382
YSLib::UI::TabControl::DefWidgetMemberIterationOperations
DefWidgetMemberIterationOperations(iterator) PDefHOp(IWidget &