pm_widgetwheel.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * File : pm_widgetwheel.h
  3. * COPYRIGHT (C) 2012-2017, Shanghai Real-Thread Technology Co., Ltd
  4. *
  5. * Change Logs:
  6. * Date Author Notes
  7. * 2017-11-05 realthread the first version
  8. */
  9. #pragma once
  10. #include <vector>
  11. #include <pm_container.h>
  12. #include <sigslot.h>
  13. #include <pm_timer.h>
  14. namespace Persimmon
  15. {
  16. class WidgetWheel : public Container
  17. {
  18. public:
  19. enum type
  20. {
  21. HORIZONTAL = 1 << 0,
  22. VERTICAL = 1 << 1,
  23. CYCLE = 1 << 2,
  24. };
  25. DEFINE_CLASS_ENUM_FLAG_OPERATORS(type);
  26. WidgetWheel(const Rect& rect, int norSize, int selSize);
  27. virtual ~WidgetWheel();
  28. void addItem(Widget* widget);
  29. void emptyItem(void);
  30. void setSlideType(enum type tp = HORIZONTAL)
  31. {
  32. mtype = tp;
  33. }
  34. void fixItemExtent(int itemNum, bool ref);
  35. int getSelItemNum(void)
  36. {
  37. return selItemNum;
  38. }
  39. Widget* getSelItem(void)
  40. {
  41. return item[selItemNum];
  42. }
  43. Widget* getItem(int value)
  44. {
  45. if (value < 0 || value >= item.size())
  46. return RT_NULL;
  47. return item[value];
  48. }
  49. void setAdjustSpeed(int value) //调整滑动手势结束后,控件继续滑动的速度,即距离
  50. {
  51. if (value >= 0)
  52. adjustSpeed = value;
  53. }
  54. void animationEnable(bool enable = true)
  55. {
  56. animEnable = enable;
  57. }
  58. void tapSelEnable(bool enable = true)
  59. {
  60. tapEnable = enable;
  61. }
  62. Signal<int> clicked;
  63. virtual void act(int itemNum, int progress);
  64. virtual bool handleGestureEvent(struct rtgui_event_gesture *gev, const struct rtgui_gesture *gest);
  65. protected:
  66. std::vector<Widget*> item;
  67. std::vector<int> item_num;
  68. int norExtentSize;
  69. enum type mtype; //滑动类型 水平或垂直
  70. private:
  71. void moveItem(bool ref);
  72. void filterSelItem(void); //筛选出当前选中项
  73. void animationStart(void); //开始动画
  74. void onAnimation(void); //动画刷新
  75. int selItemNum, oldSelItemNum, selExtentSize;
  76. int itemMovePitch, oldPitch, adjustSpeed;
  77. Timer *animationTimer; //动画效果使用的定时器
  78. bool animationMoving, animEnable, tapEnable; //true 则为动画进行时 false 则否
  79. int animationMovePitch, _progress; //分别为未选中项和选中项动画需移动的总距离
  80. int animationPitch, animationProgress; //分别为未选中项和选中项动画中当前移动的距离,以及 animationProgress 动画进度
  81. };
  82. }