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 
77 
83  : UIEventArgs(wgt), pair<float, float>(val, float()),
84  Category(t)
85  {}
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 
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;
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);
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);
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;
300 
301 private:
302  unique_ptr<ATrack> pTrack; //轨道。
303 
304 protected:
317 
318 private:
321 
322 public:
327  explicit
328  AScrollBar(const Rect& = {}, SDst = 8, Orientation = Horizontal);
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,
363  ImplRet(GetTrackRef().LocateThumb(val, t))
364 };
365 
366 
372 {
373 public:
375  explicit
376  HorizontalScrollBar(const Rect& = {}, SDst = 8);
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 
394 {
395 public:
397  explicit
398  VerticalScrollBar(const Rect& = {}, SDst = 8);
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
420 
421 protected:
432 
433 public:
435  explicit
436  ScrollableContainer(const Rect& = {});
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 
#define DefEventGetter(_q, _tEventHandler, _name, _member)
定义事件访问器。
Definition: yevt.hpp:710
范围模块类。
Definition: yobject.h:532
滚动框当前正在移动。
滚动框移动至最小位置。
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
pt pt Y const IWidget &wgt GetLocationOf
Definition: ywidget.h:148
#define DefWidgetMemberIteration(...)
定义部件成员下标及部件成员迭代器起始、终止和范围操作。
static auto first(const _tIterator &i) -> decltype((i->first))
Definition: iterator.hpp:759
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:172
ATrack::ValueType ValueType
Definition: scroll.h:297
滚动事件参数类。
Definition: scroll.h:67
DeclEvent(HViewEvent, ViewChanged) DeclEvent(HIndexEvent
视图变更事件。
滚动框大距离减量移动。
部件绘制参数。
Definition: ywgtevt.h:276
#define YF_API
Definition: Platform.h:64
成员下标迭代器。
Definition: iterator.hpp:1380
用户界面事件参数基类。
Definition: ywgtevt.h:59
基本按钮。
Definition: button.h:46
ScrollCategory
滚动类别。
Definition: scroll.h:49
std::uint16_t SDst
屏幕坐标距离。
Definition: Video.h:39
水平轨道。
Definition: scroll.h:252
滚动框移动停止。
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
#define ImplI(...)
Definition: YBaseMacro.h:308
控件。
Definition: ycontrol.h:275
#define DefSetterMem(_t, _n, _m)
Definition: YBaseMacro.h:200
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val)
构造:使用指定事件源、滚动事件类型和值。
Definition: scroll.h:82
YF_API void DrawTrackBackground(PaintEventArgs &&e, ATrack &)
绘制指定色调的基本按钮背景。
Definition: scroll.cpp:243
PDefH(void, Activate, Console &console, Drawing::Color fc=Drawing::ColorSpace::White) ImplExpr(Activate(console
激活:使用指定屏幕、有效性、前景色和默认背景色。
ValueType small_delta
小距离滚动偏移量:滚动事件关联的滑块位置变化绝对值。
Definition: scroll.h:319
VerticalScrollBar vsbVertical
控制竖直可视区域的竖直滚动条。
Definition: scroll.h:431
unique_ptr< ATrack > pTrack
Definition: scroll.h:302
Thumb btnNext
后滚动条按钮。
Definition: scroll.h:316
Category
按键类别。
Definition: Keys.h:96
滚动框小距离减量移动。
带滚动条的容器。
Definition: scroll.h:414
竖直轨道。
Definition: scroll.h:273
ScrollEventArgs(IWidget &wgt, ScrollCategory t, ValueType val, ValueType old_val)
构造:使用指定事件源、滚动事件类型、值和旧值。
Definition: scroll.h:89
_tWidget & wgt
Definition: ywgtevt.h:596
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
滚动框定位(通过直接设置位置)。
水平滚动条。
Definition: scroll.h:371
屏幕标准矩形:表示屏幕矩形区域。
Definition: ygdibase.h:416
Orientation
二元方向。
Definition: ygdibase.h:880
DeclDelegate(HScrollEvent, ScrollEventArgs) class YF_API ATrack
轨道。
Definition: scroll.h:118
#define DefSetter(_t, _n, _m)
Definition: YBaseMacro.h:188
const IWidget &wgt SPos
Definition: ywidget.h:104
Area
样式区域类型。
Definition: ystyle.h:177
Thumb btnPrev
前滚动条按钮。
Definition: scroll.h:310
#define YAssertNonnull(_expr)
Definition: cassert.h:81
表示未分配或保留的键。
Definition: Keys.h:99
HorizontalScrollBar hsbHorizontal
控制水平可视区域的水平滚动条。
Definition: scroll.h:426
竖直滚动条。
Definition: scroll.h:393
Rotation
逆时针旋转角度指示输出指向。
Definition: ygdibase.h:868
ScrollCategory Category
滚动事件类别。
Definition: scroll.h:76
const IWidget &wgt ImplRet(wgt.GetView().IsVisible()) bool YF_API Contains(const IWidget &
判断点是否在部件的可视区域内。
DefGetterMem(const ynothrow, ListType::size_type, SelectedIndex, viewer) SDst GetFullViewHeight() const
取完整视图高。
Selected const shared_ptr< ListType > const pair< Color, Color > & DefDeMoveCtor(TextList) DefPredMem(const ynothrow
滚动框大距离增量移动。
#define DeclIEntry(_sig)
Definition: YBaseMacro.h:314
static auto second(const _tIterator &i) -> decltype((i->second))
Definition: iterator.hpp:765
屏幕区域大小。
Definition: ygdibase.h:249
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。
Definition: Keys.h:68
滚动框移动至最大位置。
float ValueType
值类型。
Definition: scroll.h:70
滚动框小距离增量移动。
滚动条。
Definition: scroll.h:294