The official µGFX library repository.

gwin_slider.h 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * This file is subject to the terms of the GFX License. If a copy of
  3. * the license was not distributed with this file, you can obtain one at:
  4. *
  5. * http://ugfx.org/license.html
  6. */
  7. /**
  8. * @file src/gwin/gwin_slider.h
  9. * @brief GWIN Graphic window subsystem header file.
  10. *
  11. * @defgroup Slider Slider
  12. * @ingroup Widgets
  13. *
  14. * @brief Slider widget.
  15. *
  16. * @details Extended events can be enabled using @p gwinSliderSendExtendedEvents().
  17. *
  18. * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
  19. * @pre GWIN_NEED_SLIDER must be set to TRUE in your gfxconf.h
  20. * @{
  21. */
  22. #ifndef _GWIN_SLIDER_H
  23. #define _GWIN_SLIDER_H
  24. /* This file is included within "src/gwin/gwin_widget.h" */
  25. #define GEVENT_GWIN_SLIDER (GEVENT_GWIN_CTRL_FIRST+1)
  26. typedef struct GEventGWinSlider {
  27. GEventType type; // The type of this event (GEVENT_GWIN_SLIDER)
  28. GHandle gwin; // The slider that is returning results
  29. #if GWIN_WIDGET_TAGS
  30. WidgetTag tag; // The slider tag
  31. #endif
  32. int position;
  33. uint8_t action;
  34. #define GSLIDER_EVENT_SET 4 /* Slider position is set. This is the only event returned by default */
  35. #define GSLIDER_EVENT_CANCEL 3 /* Slider position changing has been cancelled */
  36. #define GSLIDER_EVENT_START 2 /* Slider position has started changing */
  37. #define GSLIDER_EVENT_MOVE 1 /* Slider position has been moved */
  38. } GEventGWinSlider;
  39. // There are currently no GEventGWinSlider listening flags - use 0
  40. /**
  41. * @brief The internal slider object flags
  42. * @note Used only for writing a custom draw routine.
  43. * @{
  44. */
  45. #define GSLIDER_FLG_EXTENDED_EVENTS 0x01
  46. /** @} */
  47. // A slider window
  48. typedef struct GSliderObject {
  49. GWidgetObject w;
  50. #if GINPUT_NEED_TOGGLE
  51. uint16_t t_dn;
  52. uint16_t t_up;
  53. #endif
  54. #if GINPUT_NEED_DIAL
  55. uint16_t dial;
  56. #endif
  57. coord_t dpos;
  58. int min;
  59. int max;
  60. int pos;
  61. } GSliderObject;
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. /**
  66. * @brief Create a slider window.
  67. * @return NULL if there is no resultant drawing area, otherwise a window handle.
  68. *
  69. * @param[in] g The GDisplay to display this window on
  70. * @param[in] gb The GSliderObject structure to initialise. If this is NULL the structure is dynamically allocated.
  71. * @param[in] pInit The initialization parameters to use
  72. *
  73. * @note The drawing color and the background color get set to the current defaults. If you haven't called
  74. * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively.
  75. * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there
  76. * is no default font and text drawing operations will no nothing.
  77. * @note A slider remembers its normal drawing state. If there is a window manager then it is automatically
  78. * redrawn if the window is moved or its visibility state is changed.
  79. * @note The initial slider range is from 0 to 100 with an initial position of 0.
  80. * @note A slider supports mouse, toggle and dial input.
  81. * @note When assigning a toggle, only one toggle is supported per role. If you try to assign more than
  82. * one toggle to a role it will forget the previous toggle. Two roles are supported:
  83. * Role 0 = toggle for down, Role 1 = toggle for up.
  84. * @note When assigning a dial, only one dial is supported. If you try to assign more than one dial
  85. * it will forget the previous dial. Only dial role 0 is supported.
  86. *
  87. * @api
  88. */
  89. GHandle gwinGSliderCreate(GDisplay *g, GSliderObject *gb, const GWidgetInit *pInit);
  90. #define gwinSliderCreate(w, pInit) gwinGSliderCreate(GDISP, w, pInit)
  91. /**
  92. * @brief Set the slider range.
  93. *
  94. * @param[in] gh The window handle (must be a slider window)
  95. * @param[in] min The minimum value
  96. * @param[in] max The maximum value
  97. * @note Sets the position to the minimum value.
  98. * @note The slider is not automatically drawn. Call gwinRedraw() after changing the range.
  99. *
  100. * @api
  101. */
  102. void gwinSliderSetRange(GHandle gh, int min, int max);
  103. /**
  104. * @brief Set the slider position.
  105. *
  106. * @param[in] gh The window handle (must be a slider window)
  107. * @param[in] pos The new position
  108. * @note If the new position is outside the slider range then the position
  109. * is set to the closest end of the range.
  110. * @note The slider is not automatically drawn. Call gwinRedraw() after changing the position.
  111. *
  112. * @api
  113. */
  114. void gwinSliderSetPosition(GHandle gh, int pos);
  115. /**
  116. * @brief Get the current slider position.
  117. * @return The slider position
  118. *
  119. * @param[in] gh The window handle (must be a slider window)
  120. *
  121. * @note The use of a listener to get the slider position is recommended if you
  122. * want continuous updates on the slider position.
  123. *
  124. * @api
  125. */
  126. #define gwinSliderGetPosition(gh) (((GSliderObject *)(gh))->pos)
  127. /**
  128. * @brief Should the slider send extended events.
  129. *
  130. * @param[in] gh The window handle (must be a slider window)
  131. * @param[in] enabled TRUE to enable extended events, FALSE to disable them
  132. *
  133. * @note The slider by default will only send slider events with an action of GSLIDER_EVENT_SET.
  134. * This call can be used to enable other slider action's to be sent as events
  135. *
  136. * @api
  137. */
  138. void gwinSliderSendExtendedEvents(GHandle gh, bool_t enabled);
  139. /**
  140. * @defgroup Renderings_Slider Renderings
  141. *
  142. * @brief Built-in rendering functions for the slider widget.
  143. *
  144. * @details These function may be passed to @p gwinSetCustomDraw() to get different slider drawing styles.
  145. *
  146. * @note In your custom slider drawing function you may optionally call these
  147. * standard functions and then draw your extra details on top.
  148. * @note These custom drawing routines don't have to worry about setting clipping as the framework
  149. * sets clipping to the object window prior to calling these routines.
  150. *
  151. * @{
  152. */
  153. /**
  154. * @brief The default rendering function for the slider widget.
  155. *
  156. * @param[in] gw The widget object (must be a slider object).
  157. * @param[in] param A parameter passed in from the user. Ignored by this function.
  158. *
  159. * @api
  160. */
  161. void gwinSliderDraw_Std(GWidgetObject *gw, void *param);
  162. #if GDISP_NEED_IMAGE || defined(__DOXYGEN__)
  163. /**
  164. * @brief The default rendering function
  165. *
  166. * @param[in] gw The widget object (must be a slider object).
  167. * @param[in] param A parameter passed in from the user. Must be an image handle. See note below.
  168. *
  169. * @note The image must be already opened before calling @p gwinSetCustomDraw(). The image should be 3
  170. * times the height of the button. The button image is repeated 3 times vertically, the first (top) for
  171. * the "up" image, the 2nd for the "down" image, and the third (bottom) image for the disabled state. If
  172. * the disabled state is never going to be used then the image can be just 2 times the button height.
  173. * No checking is done to compare the size of the button to the size of the image.
  174. * No text is drawn on top of the image.
  175. *
  176. * @pre GDISP_NEED_IMAGE must be set to TRUE
  177. *
  178. * @api
  179. */
  180. void gwinSliderDraw_Image(GWidgetObject *gw, void *param);
  181. #endif /* GDISP_NEED_IMAGE */
  182. /** @} */
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif /* _GWIN_SLIDER_H */
  187. /** @} */