YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
scroll.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2011 - 2013.
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 "button.h"
32 #include "yuicont.h"
33 #include "WidgetIteration.h"
34 //#include <ystdex/rational.hpp>
35 //#include "../Core/yres.h"
36 //#include "ystyle.h"
37 
39 
41 
42 
46 enum class ScrollCategory
47 {
48  SmallDecrement = 0,
49  SmallIncrement = 1,
50  LargeDecrement = 2,
51  LargeIncrement = 3,
52  ThumbPosition = 4,
53  ThumbTrack = 5,
54  First = 6,
55  Last = 7,
56  EndScroll = 8
57 };
58 
59 
64 struct YF_API ScrollEventArgs : public UIEventArgs, protected pair<float, float>
65 {
66 public:
67  typedef float ValueType;
68 
74 
80  : UIEventArgs(wgt), pair<float, float>(val, float()),
81  Category(t)
82  {}
87  ValueType old_val)
88  : UIEventArgs(wgt), pair<float, float>(val, old_val),
89  Category(t)
90  {}
91 
101  DefGetter(const ynothrow, ValueType, OldValue, second)
102 
107  DefSetter(ValueType, Value, first)
112  DefSetter(ValueType, OldValue, first)
113 };
114 
116 
117 
122 class YF_API ATrack : public Control, public GMRange<ScrollEventArgs::ValueType>
123 {
124 public:
126  typedef enum
127  {
128  None = 0,
129  OnThumb = 1,
130  OnPrev = 2,
131  OnNext = 3
132  } Area;
133  //注意值类型需要和继承的 GMRange 的 ValueType 一致。
135 
137 
138 protected:
144 
145 private:
147  // MRange 实现滚动事件关联值操作。
148  ValueType large_delta; \
150  // MRange::value 实际最大取值为 MRange::max_value - large_delta 。
151  DeclEvent(HUIEvent, ThumbDrag)
152  DeclEvent(HScrollEvent, Scroll)
153 
154 public:
159  explicit
160  ATrack(const Rect& = {}, SDst = 8);
161  inline DefDeMoveCtor(ATrack)
162 
163  DefPred(const ynothrow, Horizontal, GetOrientation() == Horizontal)
164  DefPred(const ynothrow, Vertical, GetOrientation() == Vertical)
165 
168 
169  DefEventGetter(ynothrow, HUIEvent, ThumbDrag, ThumbDrag)
170  DefEventGetter(ynothrow, HScrollEvent, Scroll, Scroll)
171  DefGetter(const ynothrow, SDst, MinThumbLength, min_thumb_length)
172  DeclIEntry(Orientation GetOrientation() const)
173  DefGetter(const ynothrow, SDst, ScrollableLength,
174  GetTrackLength() - GetThumbLength())
175  DefGetter(const ynothrow, SDst, ThumbLength,
176  GetSizeOf(tmbScroll).GetRef(IsHorizontal()))
177  DefGetter(const ynothrow, SDst, ThumbPosition,
178  GetLocationOf(tmbScroll).GetRef(IsHorizontal()))
179  virtual DefGetter(const ynothrow, SDst, TrackLength,
180  GetSizeOf(*this).GetRef(IsHorizontal()))
181  DefGetter(const ynothrow, ValueType, LargeDelta, large_delta)
182 
186  virtual void
187  SetThumbLength(SDst);
191  void
192  SetThumbPosition(SPos);
198  void
199  SetMaxValue(ValueType);
204  void
205  SetValue(ValueType);
210  void
211  SetLargeDelta(ValueType);
212 
213 protected:
217  Area
218  CheckArea(SPos) const;
219 
220 public:
229  void
230  LocateThumb(ValueType, ScrollCategory = ScrollCategory::ThumbPosition);
231 };
232 
233 
238 YF_API void
240 
241 
246 class YF_API HorizontalTrack : public ATrack
247 {
248 public:
254  explicit
255  HorizontalTrack(const Rect& = {}, SDst = 8);
257 
258  ImplI(ATrack)
259  DefGetter(const ynothrow, Orientation, Orientation, Horizontal)
260 };
261 
262 
267 class YF_API VerticalTrack : public ATrack
268 {
269 public:
275  explicit
276  VerticalTrack(const Rect& = {}, SDst = 8);
278 
279  ImplI(ATrack)
280  DefGetter(const ynothrow, Orientation, Orientation, Vertical)
281 };
282 
283 
288 class YF_API AScrollBar : public Control
289 {
290 public:
292 
294 
295 private:
296  unique_ptr<ATrack> pTrack; //轨道。
297 
298 protected:
311 
312 private:
313  ValueType small_delta; \
315 
316 public:
321  explicit
322  AScrollBar(const Rect& = {}, SDst = 8, Orientation = Horizontal);
323  inline DefDeMoveCtor(AScrollBar)
324 
325 
326  DefWidgetMemberIteration(btnPrev, btnNext, *pTrack)
327 
332  ATrack&
333  GetTrack() const ynothrow
334  {
335  YAssert(bool(pTrack), "Null pointer found.");
336 
337  return *pTrack;
338  }
339  DefGetterMem(const ynothrow, ValueType, MaxValue, GetTrack())
340  DefGetterMem(const ynothrow, ValueType, Value, GetTrack())
341  DefGetterMem(const ynothrow, ValueType, LargeDelta, GetTrack())
342  DefGetter(const ynothrow, ValueType, SmallDelta, small_delta)
343 
344  DefSetterMem(ValueType, MaxValue, GetTrack())
345  DefSetterMem(ValueType, Value, GetTrack())
346  DefSetterMem(ValueType, LargeDelta, GetTrack())
347  DefSetter(ValueType, SmallDelta, small_delta)
348 
353  void
354  LocateThumb(ValueType val,
355  ScrollCategory t = ScrollCategory::ThumbPosition)
356  {
357  return GetTrack().LocateThumb(val, t);
358  }
359 };
360 
361 
367 {
368 public:
370  explicit
371  HorizontalScrollBar(const Rect& = {}, SDst = 8);
373 
374 public:
375  ImplI(ATrack) DefGetter(const ynothrow, Orientation, Orientation,
376  Horizontal)
377 
378 protected:
379  IWidget*
380  GetBoundControlPtr(const KeyInput&) override;
381 };
382 
383 
389 {
390 public:
392  explicit
393  VerticalScrollBar(const Rect& = {}, SDst = 8);
395 
396 public:
397  ImplI(ATrack) DefGetter(const ynothrow, Orientation, Orientation, Vertical)
398 
399 protected:
400  IWidget*
401  GetBoundControlPtr(const KeyInput&) override;
402 };
403 
404 
409 class YF_API ScrollableContainer : public Control
410 {
411 public:
415 
416 protected:
427 
428 public:
430  explicit
431  ScrollableContainer(const Rect& = {});
433 
434 
435  DefWidgetMemberIteration(hsbHorizontal, vsbVertical)
436 
437 protected:
442  Size
443  FixLayout(const Size&);
444 };
445 
447 
448 YSL_END
449 
450 #endif
451