YSTest: Scroll.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

Scroll.h
浏览该文件的文档.
1 /*
2 © 2011-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_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 DefDeMoveCtor(ATrack)
176
177 DefPred(const ynothrow, Horizontal, GetOrientation() == Horizontal)
178 DefPred(const ynothrow, Vertical, GetOrientation() == Vertical)
179
181 DefWidgetMemberIteration(tmbScroll)
182
183 DefGetter(const ynothrow, SDst, MinThumbLength, min_thumb_length)
188 DeclIEntry(Orientation GetOrientation() const ynothrow)
189 DefGetter(const ynothrow, SDst, ScrollableLength,
190 GetTrackLength() - GetThumbLength())
191 DefGetter(const ynothrow, SDst, ThumbLength,
192 GetSizeOf(tmbScroll).GetRef(IsHorizontal()))
193
197 DefGetter(const ynothrow, SPos, ThumbPosition,
198 GetLocationOf(tmbScroll).GetRef(IsHorizontal()))
199 virtual DefGetter(const ynothrow, SDst, TrackLength,
200 GetSizeOf(*this).GetRef(IsHorizontal()))
201 DefGetter(const ynothrow, ValueType, LargeDelta, large_delta)
202
206 virtual void
207 SetThumbLength(SDst);
211 void
212 SetThumbPosition(SPos);
218 void
219 SetMaxValue(ValueType);
224 void
225 SetValue(ValueType);
230 void
231 SetLargeDelta(ValueType);
232
233 protected:
237 Area
238 CheckArea(SPos) const;
239
240 public:
249 void
250 LocateThumb(ValueType, ScrollCategory = ScrollCategory::ThumbPosition);
251 };
252
253
258 YF_API void
259 DrawTrackBackground(PaintEventArgs&& e, ATrack&);
260
261
266 class YF_API HorizontalTrack : public ATrack
267 {
268 public:
274 explicit
275 HorizontalTrack(const Rect& = {}, SDst = 8);
276 DefDeMoveCtor(HorizontalTrack)
281 ~HorizontalTrack() override;
282
283 DefGetter(const ynothrow ImplI(ATrack), Orientation, Orientation,
284 Horizontal)
285 };
286
287
292 class YF_API VerticalTrack : public ATrack
293 {
294 public:
300 explicit
301 VerticalTrack(const Rect& = {}, SDst = 8);
302 DefDeMoveCtor(VerticalTrack)
307 ~VerticalTrack() override;
308
309 DefGetter(const ynothrow ImplI(ATrack), Orientation, Orientation, Vertical)
310 };
311
312
317 class YF_API ScrollBar : public Control
318 {
319 public:
320 using ValueType = ATrack::ValueType;
321 using iterator = ystdex::subscriptive_iterator<ScrollBar, IWidget>;
323
328 Color ForeColor{Drawing::ColorSpace::Black};
329
330 private:
331 unique_ptr<ATrack> pTrack; //轨道。
332
333 protected:
339 Thumb btnPrev;
345 Thumb btnNext;
346
347 private:
348 ValueType small_delta; \
350
351 public:
356 explicit
357 ScrollBar(const Rect& = {}, Orientation = Horizontal, SDst = 8);
358 DefDeMoveCtor(ScrollBar)
359
360 protected:
362 void
363 InitializeArrowPainters(Rotation, Rotation);
364
365 public:
367 DefWidgetMemberIteration(btnPrev, btnNext, *pTrack)
368
369 protected:
371 observer_ptr<IWidget>
372 GetBoundControlPtr(const KeyInput&) override;
373
374 public:
376 DefGetterMem(const ynothrow, Orientation, Orientation, GetTrackRef())
381 DefGetter(const ynothrow, ATrack&, TrackRef, Deref(pTrack))
382 DefGetterMem(const ynothrow, ValueType, MaxValue, GetTrackRef())
383 DefGetterMem(const ynothrow, ValueType, Value, GetTrackRef())
384 DefGetterMem(const ynothrow, ValueType, LargeDelta, GetTrackRef())
385 DefGetter(const ynothrow, ValueType, SmallDelta, small_delta)
386
387 DefSetterMem(, ValueType, MaxValue, GetTrackRef())
388 DefSetterMem(, ValueType, Value, GetTrackRef())
389 DefSetterMem(, ValueType, LargeDelta, GetTrackRef())
390 DefSetter(, ValueType, SmallDelta, small_delta)
391
397 PDefH(void, LocateThumb, ValueType val,
398 ScrollCategory t = ScrollCategory::ThumbPosition)
399 ImplRet(GetTrackRef().LocateThumb(val, t))
400 };
401
402
407 class YF_API ScrollableContainer : public Control
408 {
409 public:
411 using iterator
412 = ystdex::subscriptive_iterator<ScrollableContainer, IWidget>;
413
414 protected:
419 ScrollBar hsbHorizontal, vsbVertical;
420
421 public:
423 explicit
424 ScrollableContainer(const Rect& = {});
425 DefDeMoveCtor(ScrollableContainer)
430 ~ScrollableContainer() override;
431
433 DefWidgetMemberIteration(hsbHorizontal, vsbVertical)
434
435 protected:
440 Size
441 FixLayout(const Size&);
442 };
443
444 } // namespace UI;
445
446 } // namespace YSLib;
447
448 #endif
449
YSLib::UI::ScrollCategory::ThumbTrack
滚动框当前正在移动。
YSLib::UI::ATrack::ThumbDrag
GEvent< void(UIEventArgs &&)> ThumbDrag
滑块拖动事件。
Definition: Scroll.h:165
ystdex::subscriptive_iterator
成员下标迭代器。
Definition: iterator.hpp:1247
YSLib::UI::PDefH
PDefH(void, DisplayFor, IWidget &wgt, Timers::TimeSpan delay) ImplExpr(Show(wgt)
在一定时间内显示部件。
DefWidgetMemberIteration
#define DefWidgetMemberIteration(...)
定义部件成员下标及部件成员迭代器起始、终止和范围操作。
Definition: WidgetIteration.h:131
YSLib::UI::ynothrow
AView &y ynothrow
Definition: YWidgetView.cpp:47
YSLib::UI::ScrollCategory::LargeDecrement
滚动框大距离减量移动。
DeclIEntry
#define DeclIEntry(_sig)
Definition: YBaseMacro.h:396
YSLib::UI::ScrollCategory::ThumbPosition
滚动框定位（通过直接设置位置）。
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
YSLib::GEvent
事件模板。
Definition: YEvent.hpp:306
DefSetterMem
#define DefSetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:268
YSLib::UI::HorizontalTrack
水平轨道。
Definition: Scroll.h:266
YSLib::UI::ScrollCategory::SmallDecrement
滚动框小距离减量移动。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::UI::VerticalTrack
竖直轨道。
Definition: Scroll.h:292
UI
YSLib::UI::ATrack::large_delta
ValueType large_delta
大距离滚动偏移量：滚动事件关联的滑块位置变化绝对值。
Definition: Scroll.h:159
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
YSLib::UI::ScrollBar
滚动条。
Definition: Scroll.h:317
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:388
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::ScrollCategory::First
滚动框移动至最小位置。
YSLib::UI::Thumb
基本按钮。
Definition: Button.h:46
YSLib::UI::ScrollBar::pTrack
unique_ptr< ATrack > pTrack
Definition: Scroll.h:331
YSLib::UI::ATrack::ValueType
ScrollEventArgs::ValueType ValueType
Definition: Scroll.h:145
YSLib::UI::ScrollEventArgs::ScrollEventArgs
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val, ValueType old_val)
构造：使用指定事件源、滚动事件类型、值和旧值。
Definition: Scroll.h:89
YSLib::UI::ATrack::Area
Area
轨道区域。
Definition: Scroll.h:137
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:44
YSLib::UI::ScrollCategory::Last
滚动框移动至最大位置。
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
YSLib::UI::ATrack
轨道。
Definition: Scroll.h:130
YSLib::UI::ScrollCategory::EndScroll
滚动框移动停止。
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::GetLocationOf
pt pt Y const IWidget &wgt GetLocationOf
Definition: YWidget.h:153
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: YWidgetEvent.h:323
YSLib::Drawing::Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: YGDIBase.h:895
platform::Color
颜色。
Definition: Video.h:416
platform::KeyInput
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:67
YSLib::UI::ScrollBar::btnPrev
Thumb btnPrev
前滚动条按钮。
Definition: Scroll.h:339
YSLib::UI::ScrollEventArgs
滚动事件参数类。
Definition: Scroll.h:67
YSLib::UI::e
void e
Definition: YWidget.h:352
YSLib::UI::ScrollCategory::LargeIncrement
滚动框大距离增量移动。
DefSetter
#define DefSetter(_q, _t, _n, _m)
Definition: YBaseMacro.h:252
YModules.h
YSLib::UI::ScrollableContainer::vsbVertical
ScrollBar vsbVertical
Definition: Scroll.h:419
YSLib::UI::ScrollCategory
ScrollCategory
滚动类别。
Definition: Scroll.h:49
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:540
YSLib::UI::ATrack::Scroll
GEvent< void(ScrollEventArgs &&)> Scroll
滚动事件。
Definition: Scroll.h:167
YSLib::UI::Control
控件。
Definition: YControl.h:275
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::UI::ScrollableContainer
带滚动条的容器。
Definition: Scroll.h:407
YSLib::UI::ATrack::tmbScroll
Thumb tmbScroll
滑块：轨道区域上的滚动框。
Definition: Scroll.h:154
YSLib::Consoles::Black
Definition: YConsole.h:53
YSLib::UI::ScrollBar::btnNext
Thumb btnNext
后滚动条按钮。
Definition: Scroll.h:345
YSLib::UI::ScrollEventArgs::ValueType
float ValueType
值类型。
Definition: Scroll.h:70
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::UI::ScrollBar::small_delta
ValueType small_delta
小距离滚动偏移量：滚动事件关联的滑块位置变化绝对值。
Definition: Scroll.h:348
YSLib::UI::UIEventArgs
用户界面事件参数基类。
Definition: YWidgetEvent.h:59
YSLib::UI::SPos
const IWidget &wgt SPos
Definition: YWidget.h:109
YSLib::UI::ScrollEventArgs::Category
ScrollCategory Category
滚动事件类别。
Definition: Scroll.h:76
YSLib::UI::ScrollEventArgs::ScrollEventArgs
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val)
构造：使用指定事件源、滚动事件类型和值。
Definition: Scroll.h:82
YSLib::UI::DrawTrackBackground
YF_API void DrawTrackBackground(PaintEventArgs &&e, ATrack &)
绘制指定色调的基本按钮背景。
Definition: Scroll.cpp:248
YSLib::GMRange
判断是否持有相同对象。
Definition: YObject.h:1066
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:161
YSLib::UI::ScrollCategory::SmallIncrement
滚动框小距离增量移动。
YSLib::UI::ATrack::min_thumb_length
SDst min_thumb_length
最小滑块长度。
Definition: Scroll.h:157