YSTest: Scroll.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

Scroll.h
浏览该文件的文档.
1 /*
2 © 2011-2016, 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_Scroll_h_
29 #define YSL_INC_UI_Scroll_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_UI_Button
33 #include YFM_YSLib_UI_YUIContainer
34 #include YFM_YSLib_UI_WidgetIteration
35 //#include <ystdex/rational.hpp>
36 //#include YFM_YSLib_Service_YResource
37 //#include YFM_YSLib_UI_YStyle
38
39 namespace YSLib
40 {
41
42 namespace UI
43 {
44
49 enum class ScrollCategory
50 {
51 SmallDecrement = 0,
52 SmallIncrement = 1,
53 LargeDecrement = 2,
54 LargeIncrement = 3,
55 ThumbPosition = 4,
56 ThumbTrack = 5,
57 First = 6,
58 Last = 7,
59 EndScroll = 8
60 };
61
62
67 struct YF_API ScrollEventArgs : public UIEventArgs, protected pair<float, float>
68 {
69 public:
70 using ValueType = float;
71
76 ScrollCategory Category;
77
82 ScrollEventArgs(IWidget& wgt, ScrollCategory t, ValueType val)
83 : UIEventArgs(wgt), pair<float, float>(val, float()),
84 Category(t)
85 {}
89 ScrollEventArgs(IWidget& wgt, ScrollCategory t, ValueType val,
90 ValueType old_val)
91 : UIEventArgs(wgt), pair<float, float>(val, old_val),
92 Category(t)
93 {}
95 DefDeCopyCtor(ScrollEventArgs)
100 ~ScrollEventArgs() override;
101
106 DefGetter(const ynothrow, ValueType, Value, first)
111 DefGetter(const ynothrow, ValueType, OldValue, second)
112
117 DefSetter(, ValueType, Value, first)
122 DefSetter(, ValueType, OldValue, first)
123 };
124
125
130 class YF_API ATrack : public Control, public GMRange<ScrollEventArgs::ValueType>
131 {
132 public:
137 enum Area
138 {
139 None = 0,
140 OnThumb = 1,
141 OnPrev = 2,
142 OnNext = 3
143 };
144 //注意值类型需要和继承的 GMRange 的 ValueType 一致。
145 using ValueType = ScrollEventArgs::ValueType;
146 using iterator = ystdex::subscriptive_iterator<ATrack, IWidget>;
148
149 protected:
154 Thumb tmbScroll;
155
156 private:
157 SDst min_thumb_length;
158 // MRange 实现滚动事件关联值操作。
159 ValueType large_delta; \
161 // MRange::value 实际最大取值为 MRange::max_value - large_delta 。
162
163 public:
165 GEvent<void(UIEventArgs&&)> ThumbDrag;
167 GEvent<void(ScrollEventArgs&&)> Scroll;
168
173 explicit
174 ATrack(const Rect& = {}, SDst = 8);
175
176 DefPred(const ynothrow, Horizontal, GetOrientation() == Horizontal)
177 DefPred(const ynothrow, Vertical, GetOrientation() == Vertical)
178
180 DefWidgetMemberIteration(tmbScroll)
181
182 DefGetter(const ynothrow, SDst, MinThumbLength, min_thumb_length)
187 DeclIEntry(Orientation GetOrientation() const ynothrow)
188 DefGetter(const ynothrow, SDst, ScrollableLength,
189 GetTrackLength() - GetThumbLength())
190 DefGetter(const ynothrow, SDst, ThumbLength,
191 GetSizeOf(tmbScroll).GetRef(IsHorizontal()))
192
196 DefGetter(const ynothrow, SPos, ThumbPosition,
197 GetLocationOf(tmbScroll).GetRef(IsHorizontal()))
198 virtual DefGetter(const ynothrow, SDst, TrackLength,
199 GetSizeOf(*this).GetRef(IsHorizontal()))
200 DefGetter(const ynothrow, ValueType, LargeDelta, large_delta)
201
205 virtual void
206 SetThumbLength(SDst);
210 void
211 SetThumbPosition(SPos);
217 void
218 SetMaxValue(ValueType);
223 void
224 SetValue(ValueType);
229 void
230 SetLargeDelta(ValueType);
231
232 protected:
236 YB_ATTR_nodiscard YB_PURE Area
237 CheckArea(SPos) const;
238
239 public:
248 void
249 LocateThumb(ValueType, ScrollCategory = ScrollCategory::ThumbPosition);
250 };
251
252
257 YF_API void
258 DrawTrackBackground(PaintEventArgs&& e, ATrack&);
259
260
265 class YF_API HorizontalTrack : public ATrack
266 {
267 public:
273 explicit
274 HorizontalTrack(const Rect& = {}, SDst = 8);
279 ~HorizontalTrack() override;
280
281 DefGetter(const ynothrow ImplI(ATrack), Orientation, Orientation,
282 Horizontal)
283 };
284
285
290 class YF_API VerticalTrack : public ATrack
291 {
292 public:
298 explicit
299 VerticalTrack(const Rect& = {}, SDst = 8);
304 ~VerticalTrack() override;
305
306 DefGetter(const ynothrow ImplI(ATrack), Orientation, Orientation, Vertical)
307 };
308
309
314 class YF_API ScrollBar : public Control
315 {
316 public:
317 using ValueType = ATrack::ValueType;
318 using iterator = ystdex::subscriptive_iterator<ScrollBar, IWidget>;
320
325 Color ForeColor{Drawing::ColorSpace::Black};
326
327 private:
328 unique_ptr<ATrack> pTrack; //轨道。
329
330 protected:
336 Thumb btnPrev;
342 Thumb btnNext;
343
344 private:
345 ValueType small_delta; \
347
348 public:
353 explicit
354 ScrollBar(const Rect& = {}, Orientation = Horizontal, SDst = 8);
355
356 protected:
358 void
359 InitializeArrowPainters(Rotation, Rotation);
360
361 public:
363 DefWidgetMemberIteration(btnPrev, btnNext, *pTrack)
364
365 protected:
367 YB_ATTR_nodiscard YB_PURE observer_ptr<IWidget>
368 GetBoundControlPtr(const KeyInput&) override;
369
370 public:
372 DefGetterMem(const ynothrow, Orientation, Orientation, GetTrackRef())
377 DefGetter(const ynothrow, ATrack&, TrackRef, Deref(pTrack))
378 DefGetterMem(const ynothrow, ValueType, MaxValue, GetTrackRef())
379 DefGetterMem(const ynothrow, ValueType, Value, GetTrackRef())
380 DefGetterMem(const ynothrow, ValueType, LargeDelta, GetTrackRef())
381 DefGetter(const ynothrow, ValueType, SmallDelta, small_delta)
382
383 DefSetterMem(, ValueType, MaxValue, GetTrackRef())
384 DefSetterMem(, ValueType, Value, GetTrackRef())
385 DefSetterMem(, ValueType, LargeDelta, GetTrackRef())
386 DefSetter(, ValueType, SmallDelta, small_delta)
387
393 PDefH(void, LocateThumb, ValueType val,
394 ScrollCategory t = ScrollCategory::ThumbPosition)
395 ImplRet(GetTrackRef().LocateThumb(val, t))
396 };
397
398
403 class YF_API ScrollableContainer : public Control
404 {
405 public:
407 using iterator
408 = ystdex::subscriptive_iterator<ScrollableContainer, IWidget>;
409
410 protected:
415 ScrollBar hsbHorizontal, vsbVertical;
416
417 public:
419 explicit
420 ScrollableContainer(const Rect& = {});
425 ~ScrollableContainer() override;
426
428 DefWidgetMemberIteration(hsbHorizontal, vsbVertical)
429
430 protected:
435 Size
436 FixLayout(const Size&);
437 };
438
439 } // namespace UI;
440
441 } // namespace YSLib;
442
443 #endif
444
YSLib::UI::ScrollBar::ValueType
ATrack::ValueType ValueType
Definition: Scroll.h:317
YSLib::GMRange
判断是否持有相同对象。
Definition: YObject.h:1737
YSLib::UI::ScrollEventArgs::DefDeCopyCtor
DefDeCopyCtor(ScrollEventArgs) ~ScrollEventArgs() override
虚析构：类定义外默认实现。
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::UI::SPos
const IWidget &wgt SPos
Definition: YWidget.h:109
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::ScrollBar::DefGetterMem
DefGetterMem(const ynothrow, Orientation, Orientation, GetTrackRef()) DefGetter(const ynothrow
取轨道引用。
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::UI::ATrack::ThumbDrag
GEvent< void(UIEventArgs &&)> ThumbDrag
滑块拖动事件。
Definition: Scroll.h:165
YSLib::UI::ScrollCategory::ThumbTrack
@ ThumbTrack
滚动框当前正在移动。
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
YSLib::UI::ATrack::min_thumb_length
SDst min_thumb_length
最小滑块长度。
Definition: Scroll.h:157
YSLib::UI::ATrack
轨道。
Definition: Scroll.h:131
platform::KeyCategory::Category
Category
按键类别。
Definition: Keys.h:99
YSLib::UI::Control
控件。
Definition: YControl.h:271
YSLib::UI::ScrollCategory::ThumbPosition
@ ThumbPosition
滚动框定位（通过直接设置位置）。
YSLib::UI::ScrollableContainer::~ScrollableContainer
~ScrollableContainer() override
虚析构：类定义外默认实现。
YSLib::UI::ScrollBar::ScrollBar
ScrollBar(const Rect &={}, Orientation=Horizontal, SDst=8)
构造：使用指定边界、大小和方向。
YSLib::UI::GetSizeOf
YB_ATTR_nodiscard YB_PURE pt pt Y YB_ATTR_nodiscard YB_PURE const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:165
YSLib::UI::ATrack::large_delta
ValueType large_delta
大距离滚动偏移量：滚动事件关联的滑块位置变化绝对值。
Definition: Scroll.h:159
YSLib::UI::VerticalTrack
竖直轨道。
Definition: Scroll.h:291
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::VerticalTrack::VerticalTrack
VerticalTrack(const Rect &={}, SDst=8)
构造：使用指定边界和最小滑块长。
YSLib::UI::Thumb
基本按钮。
Definition: Button.h:47
YSLib::UI::ScrollCategory
ScrollCategory
滚动类别。
Definition: Scroll.h:50
YSLib::UI::ScrollEventArgs
滚动事件参数类。
Definition: Scroll.h:68
YSLib::UI::ScrollBar::pTrack
unique_ptr< ATrack > pTrack
Definition: Scroll.h:328
YSLib::UI::ScrollableContainer
带滚动条的容器。
Definition: Scroll.h:404
YSLib::UI::ScrollBar::btnPrev
Thumb btnPrev
前滚动条按钮。
Definition: Scroll.h:336
YSLib::UI::ATrack::ValueType
ScrollEventArgs::ValueType ValueType
Definition: Scroll.h:145
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:396
YSLib::UI::ScrollEventArgs::Category
ScrollCategory Category
滚动事件类别。
Definition: Scroll.h:76
YSLib::UI::ScrollEventArgs::ScrollEventArgs
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val, ValueType old_val)
构造：使用指定事件源、滚动事件类型、值和旧值。
Definition: Scroll.h:89
YSLib::UI::ScrollBar::small_delta
ValueType small_delta
小距离滚动偏移量：滚动事件关联的滑块位置变化绝对值。
Definition: Scroll.h:345
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:1145
YSLib::UI::ATrack::Area
Area
轨道区域。
Definition: Scroll.h:138
YSLib::UI::ATrack::tmbScroll
Thumb tmbScroll
滑块：轨道区域上的滚动框。
Definition: Scroll.h:154
YSLib::UI::DrawTrackBackground
YF_API void DrawTrackBackground(PaintEventArgs &&e, ATrack &)
绘制指定色调的基本按钮背景。
Definition: Scroll.cpp:248
YSLib::UI::ScrollCategory::Last
@ Last
滚动框移动至最大位置。
YSLib::Drawing::ColorSpace::Black
@ Black
Definition: YGDIBase.h:262
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::UI::HorizontalTrack
水平轨道。
Definition: Scroll.h:266
DefWidgetMemberIteration
#define DefWidgetMemberIteration(...)
定义部件成员下标及部件成员迭代器起始、终止和范围操作。
Definition: WidgetIteration.h:131
YSLib::UI::ScrollCategory::First
@ First
滚动框移动至最小位置。
YSLib::UI::e
void e
Definition: YWidget.h:356
YSLib::UI::ScrollBar::btnNext
Thumb btnNext
后滚动条按钮。
Definition: Scroll.h:342
YSLib::UI::ScrollEventArgs::ValueType
float ValueType
值类型。
Definition: Scroll.h:70
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
platform::KeyInput
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:67
YSLib::UI::ATrack::Scroll
GEvent< void(ScrollEventArgs &&)> Scroll
滚动事件。
Definition: Scroll.h:167
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
YSLib::UI::ScrollEventArgs::ScrollEventArgs
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val)
构造：使用指定事件源、滚动事件类型和值。
Definition: Scroll.h:82
Color
Pixel Color
Definition: CharRenderer.cpp:59
YModules.h
YSLib 用户界面模块配置文件。
YSLib::UI::HorizontalTrack::~HorizontalTrack
~HorizontalTrack() override
虚析构：类定义外默认实现。
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
YSLib::UI::UIEventArgs
用户界面事件参数基类。
Definition: YWidgetEvent.h:61
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:113
DefSetter
#define DefSetter(_q, _t, _n, _m)
Definition: YBaseMacro.h:252
YSLib::UI::ScrollCategory::LargeIncrement
@ LargeIncrement
滚动框大距离增量移动。
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:330
YSLib::UI::ScrollCategory::EndScroll
@ EndScroll
滚动框移动停止。
YSLib::UI::ScrollCategory::LargeDecrement
@ LargeDecrement
滚动框大距离减量移动。
YSLib::UI::ScrollCategory::SmallIncrement
@ SmallIncrement
滚动框小距离增量移动。
YSLib::UI::VerticalTrack::~VerticalTrack
~VerticalTrack() override
虚析构：类定义外默认实现。
YSLib::UI::ScrollBar
滚动条。
Definition: Scroll.h:315
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::DeclIEntry
YB_ATTR_nodiscard DeclIEntry(any Create(Creation, const any &) const) YB_ATTR_nodiscard YB_PURE DeclIEntry(bool Equals(const void *) const) YB_ATTR_nodiscard YB_PURE DeclIEntry(size_t OwnsCount() const ynothrow) YB_ATTR_nodiscard YB_PURE DeclIEntry(any Query(uintmax_t) const) template< typename _type > YB_ATTR_nodiscard static any CreateHolder(Creation
创建新的持有者。
YSLib::UI::GetLocationOf
YB_ATTR_nodiscard YB_PURE pt pt Y YB_ATTR_nodiscard YB_PURE const IWidget &wgt GetLocationOf
Definition: YWidget.h:157
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ystdex::subscriptive_iterator
成员下标迭代器。
Definition: iterator.hpp:1193
YSLib::UI::ATrack::DefPred
DefPred(const ynothrow, Horizontal, GetOrientation()==Horizontal) DefPred(const ynothrow
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) YB_ATTR_nodiscard YB_PURE bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
DefSetterMem
#define DefSetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:268
YSLib::UI::ScrollCategory::SmallDecrement
@ SmallDecrement
滚动框小距离减量移动。
YSLib::UI::ScrollableContainer::vsbVertical
ScrollBar vsbVertical
Definition: Scroll.h:415
YSLib::UI::ScrollEventArgs::DefGetter
DefGetter(const ynothrow, ValueType, Value, first) DefGetter(const ynothrow
取值。