YSTest: scroll.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
scroll.h
浏览该文件的文档.
1 /*
2 © 2011-2014 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 {}
94
99 DefGetter(const ynothrow, ValueType, Value, first)
104 DefGetter(const ynothrow, ValueType, OldValue, second)
105
110 DefSetter(ValueType, Value, first)
115 DefSetter(ValueType, OldValue, first)
116 };
117
118 DeclDelegate(HScrollEvent, ScrollEventArgs)
119
120
125 class YF_API ATrack : public Control, public GMRange<ScrollEventArgs::ValueType>
126 {
127 public:
132 enum Area
133 {
134 None = 0,
135 OnThumb = 1,
136 OnPrev = 2,
137 OnNext = 3
138 };
139 //注意值类型需要和继承的 GMRange 的 ValueType 一致。
140 using ValueType = ScrollEventArgs::ValueType;
141 using iterator = ystdex::subscriptive_iterator<ATrack, IWidget>;
143
144 protected:
149 Thumb tmbScroll;
150
151 private:
152 SDst min_thumb_length;
153 // MRange 实现滚动事件关联值操作。
154 ValueType large_delta; \
156 // MRange::value 实际最大取值为 MRange::max_value - large_delta 。
157 DeclEvent(HUIEvent, ThumbDrag)
158 DeclEvent(HScrollEvent, Scroll)
159
160 public:
165 explicit
166 ATrack(const Rect& = {}, SDst = 8);
167 DefDeMoveCtor(ATrack)
168
169 DefPred(const ynothrow, Horizontal, GetOrientation() == Horizontal)
170 DefPred(const ynothrow, Vertical, GetOrientation() == Vertical)
171
172
173 DefWidgetMemberIteration(tmbScroll)
174
175 DefEventGetter(ynothrow, HUIEvent, ThumbDrag, ThumbDrag)
176 DefEventGetter(ynothrow, HScrollEvent, Scroll, Scroll)
177 DefGetter(const ynothrow, SDst, MinThumbLength, min_thumb_length)
178 DeclIEntry(Orientation GetOrientation() const)
179 DefGetter(const ynothrow, SDst, ScrollableLength,
180 GetTrackLength() - GetThumbLength())
181 DefGetter(const ynothrow, SDst, ThumbLength,
182 GetSizeOf(tmbScroll).GetRef(IsHorizontal()))
183 DefGetter(const ynothrow, SDst, ThumbPosition,
184 GetLocationOf(tmbScroll).GetRef(IsHorizontal()))
185 virtual DefGetter(const ynothrow, SDst, TrackLength,
186 GetSizeOf(*this).GetRef(IsHorizontal()))
187 DefGetter(const ynothrow, ValueType, LargeDelta, large_delta)
188
189
192 virtual void
193 SetThumbLength(SDst);
197 void
198 SetThumbPosition(SPos);
204 void
205 SetMaxValue(ValueType);
210 void
211 SetValue(ValueType);
216 void
217 SetLargeDelta(ValueType);
218
219 protected:
223 Area
224 CheckArea(SPos) const;
225
226 public:
235 void
236 LocateThumb(ValueType, ScrollCategory = ScrollCategory::ThumbPosition);
237 };
238
239
244 YF_API void
245 DrawTrackBackground(PaintEventArgs&& e, ATrack&);
246
247
252 class YF_API HorizontalTrack : public ATrack
253 {
254 public:
260 explicit
261 HorizontalTrack(const Rect& = {}, SDst = 8);
262 DefDeMoveCtor(HorizontalTrack)
263
264 ImplI(ATrack)
265 DefGetter(const ynothrow, Orientation, Orientation, Horizontal)
266 };
267
268
273 class YF_API VerticalTrack : public ATrack
274 {
275 public:
281 explicit
282 VerticalTrack(const Rect& = {}, SDst = 8);
283 DefDeMoveCtor(VerticalTrack)
284
285 ImplI(ATrack)
286 DefGetter(const ynothrow, Orientation, Orientation, Vertical)
287 };
288
289
294 class YF_API AScrollBar : public Control
295 {
296 public:
297 using ValueType = ATrack::ValueType;
298 using iterator = ystdex::subscriptive_iterator<AScrollBar, IWidget>;
300
301 private:
302 unique_ptr<ATrack> pTrack; //轨道。
303
304 protected:
310 Thumb btnPrev;
316 Thumb btnNext;
317
318 private:
319 ValueType small_delta; \
321
322 public:
327 explicit
328 AScrollBar(const Rect& = {}, SDst = 8, Orientation = Horizontal);
329 DefDeMoveCtor(AScrollBar)
330
331 protected:
333 void
334 InitializeArrowPainters(Rotation, Rotation);
335
336 public:
338 DefWidgetMemberIteration(btnPrev, btnNext, *pTrack)
339
344 DefGetter(const ynothrow, ATrack&, TrackRef,
345 (YAssertNonnull(pTrack), *pTrack))
346 DefGetterMem(const ynothrow, ValueType, MaxValue, GetTrackRef())
347 DefGetterMem(const ynothrow, ValueType, Value, GetTrackRef())
348 DefGetterMem(const ynothrow, ValueType, LargeDelta, GetTrackRef())
349 DefGetter(const ynothrow, ValueType, SmallDelta, small_delta)
350
351 DefSetterMem(ValueType, MaxValue, GetTrackRef())
352 DefSetterMem(ValueType, Value, GetTrackRef())
353 DefSetterMem(ValueType, LargeDelta, GetTrackRef())
354 DefSetter(ValueType, SmallDelta, small_delta)
355
361 PDefH(void, LocateThumb, ValueType val,
362 ScrollCategory t = ScrollCategory::ThumbPosition)
363 ImplRet(GetTrackRef().LocateThumb(val, t))
364 };
365
366
371 class YF_API HorizontalScrollBar : public AScrollBar
372 {
373 public:
375 explicit
376 HorizontalScrollBar(const Rect& = {}, SDst = 8);
377 DefDeMoveCtor(HorizontalScrollBar)
378
379 public:
380 ImplI(ATrack) DefGetter(const ynothrow, Orientation, Orientation,
381 Horizontal)
382
383 protected:
384 IWidget*
385 GetBoundControlPtr(const KeyInput&) override;
386 };
387
388
393 class YF_API VerticalScrollBar : public AScrollBar
394 {
395 public:
397 explicit
398 VerticalScrollBar(const Rect& = {}, SDst = 8);
399 DefDeMoveCtor(VerticalScrollBar)
400
401 public:
402 ImplI(ATrack) DefGetter(const ynothrow, Orientation, Orientation, Vertical)
403
404 protected:
405 IWidget*
406 GetBoundControlPtr(const KeyInput&) override;
407 };
408
409
414 class YF_API ScrollableContainer : public Control
415 {
416 public:
418 using iterator
419 = ystdex::subscriptive_iterator<ScrollableContainer, IWidget>;
420
421 protected:
426 HorizontalScrollBar hsbHorizontal;
431 VerticalScrollBar vsbVertical;
432
433 public:
435 explicit
436 ScrollableContainer(const Rect& = {});
437 DefDeMoveCtor(ScrollableContainer)
438
439
440 DefWidgetMemberIteration(hsbHorizontal, vsbVertical)
441
442 protected:
447 Size
448 FixLayout(const Size&);
449 };
450
451 } // namespace UI;
452
453 } // namespace YSLib;
454
455 #endif
456
DefEventGetter
#define DefEventGetter(_q, _tEventHandler, _name, _member)
定义事件访问器。
Definition: yevt.hpp:710
YSLib::GMRange
范围模块类。
Definition: yobject.h:532
YSLib::UI::ScrollCategory::ThumbTrack
滚动框当前正在移动。
YSLib::UI::ScrollCategory::First
滚动框移动至最小位置。
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
YSLib::UI::GetLocationOf
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
DefWidgetMemberIteration
#define DefWidgetMemberIteration(...)
定义部件成员下标及部件成员迭代器起始、终止和范围操作。
Definition: WidgetIteration.h:131
YModules.h
ystdex::iterator_transformation::first
static auto first(const _tIterator &i) -> decltype((i->first))
Definition: iterator.hpp:759
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:172
YSLib::UI::AScrollBar::ValueType
ATrack::ValueType ValueType
Definition: scroll.h:297
YSLib::UI::ScrollEventArgs
滚动事件参数类。
Definition: scroll.h:67
YSLib::Drawing::Vertical
Definition: ygdibase.h:883
YSLib::UI::DeclEvent
DeclEvent(HViewEvent, ViewChanged) DeclEvent(HIndexEvent
视图变更事件。
YSLib::UI::ScrollCategory::LargeDecrement
滚动框大距离减量移动。
YSLib::UI::PaintEventArgs
部件绘制参数。
Definition: ywgtevt.h:276
YF_API
#define YF_API
Definition: Platform.h:64
ystdex::subscriptive_iterator
成员下标迭代器。
Definition: iterator.hpp:1380
YSLib::UI::UIEventArgs
用户界面事件参数基类。
Definition: ywgtevt.h:59
YSLib::UI::Thumb
基本按钮。
Definition: button.h:46
YSLib::UI::ScrollCategory
ScrollCategory
滚动类别。
Definition: scroll.h:49
platform::SDst
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
YSLib::UI::HorizontalTrack
水平轨道。
Definition: scroll.h:252
YSLib::UI::ScrollCategory::EndScroll
滚动框移动停止。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
ImplI
#define ImplI(...)
Definition: YBaseMacro.h:308
YSLib::UI::Control
控件。
Definition: ycontrol.h:275
DefSetterMem
#define DefSetterMem(_t, _n, _m)
Definition: YBaseMacro.h:200
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:243
YSLib::UI::PDefH
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活：使用指定屏幕、有效性、前景色和默认背景色。
YSLib::UI::AScrollBar::small_delta
ValueType small_delta
小距离滚动偏移量：滚动事件关联的滑块位置变化绝对值。
Definition: scroll.h:319
YSLib::UI::ScrollableContainer::vsbVertical
VerticalScrollBar vsbVertical
控制竖直可视区域的竖直滚动条。
Definition: scroll.h:431
YSLib::UI::AScrollBar::pTrack
unique_ptr< ATrack > pTrack
Definition: scroll.h:302
YSLib::UI::AScrollBar::btnNext
Thumb btnNext
后滚动条按钮。
Definition: scroll.h:316
platform::KeyCategory::Category
Category
按键类别。
Definition: Keys.h:96
YSLib::Drawing::Horizontal
Definition: ygdibase.h:882
YSLib::UI::ScrollCategory::SmallDecrement
滚动框小距离减量移动。
YSLib::UI::ScrollableContainer
带滚动条的容器。
Definition: scroll.h:414
YSLib::UI::VerticalTrack
竖直轨道。
Definition: scroll.h:273
YSLib::UI::ScrollEventArgs::ScrollEventArgs
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val, ValueType old_val)
构造：使用指定事件源、滚动事件类型、值和旧值。
Definition: scroll.h:89
YSLib::UI::wgt
_tWidget & wgt
Definition: ywgtevt.h:596
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::UI::ScrollCategory::ThumbPosition
滚动框定位（通过直接设置位置）。
YSLib::UI::HorizontalScrollBar
水平滚动条。
Definition: scroll.h:371
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: ygdibase.h:416
YSLib::Drawing::Orientation
Orientation
二元方向。
Definition: ygdibase.h:880
YSLib::UI::DeclDelegate
DeclDelegate(HScrollEvent, ScrollEventArgs) class YF_API ATrack
轨道。
Definition: scroll.h:118
DefSetter
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
YSLib::UI::SPos
const IWidget &wgt SPos
Definition: ywidget.h:104
YSLib::UI::Styles::Area
Area
样式区域类型。
Definition: ystyle.h:177
YSLib::UI::AScrollBar::btnPrev
Thumb btnPrev
前滚动条按钮。
Definition: scroll.h:310
YAssertNonnull
#define YAssertNonnull(_expr)
Definition: cassert.h:81
platform::KeyCategory::None
表示未分配或保留的键。
Definition: Keys.h:99
YSLib::UI::ScrollableContainer::hsbHorizontal
HorizontalScrollBar hsbHorizontal
控制水平可视区域的水平滚动条。
Definition: scroll.h:426
YSLib::UI::VerticalScrollBar
竖直滚动条。
Definition: scroll.h:393
Rotation
Rotation
逆时针旋转角度指示输出指向。
Definition: ygdibase.h:868
YSLib::UI::ScrollEventArgs::Category
ScrollCategory Category
滚动事件类别。
Definition: scroll.h:76
YSLib::UI::ImplRet
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
YSLib::UI::DefGetterMem
DefGetterMem(const ynothrow, ListType::size_type, SelectedIndex, viewer) SDst GetFullViewHeight() const
取完整视图高。
YSLib::UI::DefDeMoveCtor
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
YSLib::UI::ScrollCategory::LargeIncrement
滚动框大距离增量移动。
DeclIEntry
#define DeclIEntry(_sig)
Definition: YBaseMacro.h:314
ystdex::iterator_transformation::second
static auto second(const _tIterator &i) -> decltype((i->second))
Definition: iterator.hpp:765
YSLib::Drawing::Size
屏幕区域大小。
Definition: ygdibase.h:249
platform::KeyInput
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:68
YSLib::UI::ScrollCategory::Last
滚动框移动至最大位置。
YSLib::UI::ScrollEventArgs::ValueType
float ValueType
值类型。
Definition: scroll.h:70
YSLib::UI::ScrollCategory::SmallIncrement
滚动框小距离增量移动。
YSLib::UI::AScrollBar
滚动条。
Definition: scroll.h:294