scrollbar.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. #include <rtgui/dc.h>
  2. #include <rtgui/widgets/scrollbar.h>
  3. static void _rtgui_scrollbar_constructor(rtgui_scrollbar_t *bar)
  4. {
  5. struct rtgui_rect rect = {0, 0, RTGUI_DEFAULT_SB_WIDTH, RTGUI_DEFAULT_SB_HEIGHT};
  6. /* set event handler */
  7. rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_scrollbar_event_handler);
  8. rtgui_scrollbar_set_range(bar, 0, 100);
  9. rtgui_scrollbar_set_page_step(bar, 20);
  10. rtgui_scrollbar_set_line_step(bar, 10);
  11. bar->thumb_position = 0;
  12. bar->thumb_size = 16;
  13. bar->on_scroll = RT_NULL;
  14. bar->orient = RTGUI_HORIZONTAL;
  15. bar->bar_width = RTGUI_DEFAULT_SB_HEIGHT;
  16. rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
  17. /* set gc */
  18. RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
  19. }
  20. rt_inline rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
  21. {
  22. struct rtgui_rect rect;
  23. rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
  24. if (bar->orient & RTGUI_VERTICAL)
  25. return rect.y2 - 2 * (rect.x2 - rect.x1);
  26. return rect.x2 - 2 * (rect.y2 - rect.y1);
  27. }
  28. rt_inline rt_uint32_t _rtgui_scrollbar_get_thumb_position(rtgui_scrollbar_t* bar)
  29. {
  30. rt_uint32_t thumb_position;
  31. /* calculate thumb position */
  32. thumb_position = (rtgui_scrollbar_get_value(bar) - bar->min_position) * _rtgui_scrollbar_get_length(bar) /
  33. (bar->max_position - bar->min_position);
  34. return thumb_position;
  35. }
  36. rt_inline void _rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect)
  37. {
  38. struct rtgui_rect scrollbar_rect;
  39. rtgui_widget_get_rect(RTGUI_WIDGET(bar), &scrollbar_rect);
  40. if (bar->orient & RTGUI_VERTICAL)
  41. {
  42. rt_uint32_t btn_width = scrollbar_rect.x2 - scrollbar_rect.x1;
  43. /* vertical scroll bar */
  44. rect->x1 = scrollbar_rect.x1;
  45. rect->x2 = scrollbar_rect.x2;
  46. rect->y1 = scrollbar_rect.y1 + btn_width + _rtgui_scrollbar_get_thumb_position(bar);
  47. rect->y2 = rect->y1 + btn_width;
  48. }
  49. else
  50. {
  51. rt_uint32_t btn_height = scrollbar_rect.y2 - scrollbar_rect.y1;
  52. /* horizontal scroll bar */
  53. rect->x1 = scrollbar_rect.x1 + btn_height + _rtgui_scrollbar_get_thumb_position(bar);
  54. rect->x2 = rect->x1 + btn_height;
  55. rect->y1 = scrollbar_rect.y1;
  56. rect->y2 = scrollbar_rect.y2;
  57. }
  58. }
  59. rtgui_type_t *rtgui_scrollbar_type_get(void)
  60. {
  61. static rtgui_type_t *scrollbar_type = RT_NULL;
  62. if (!scrollbar_type)
  63. {
  64. scrollbar_type = rtgui_type_create("scrollbar", RTGUI_WIDGET_TYPE,
  65. sizeof(rtgui_scrollbar_t), RTGUI_CONSTRUCTOR(_rtgui_scrollbar_constructor), RT_NULL);
  66. }
  67. return scrollbar_type;
  68. }
  69. static void _rtgui_scrollbar_ondraw(struct rtgui_scrollbar* bar);
  70. static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event);
  71. rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_widget * widget,
  72. struct rtgui_event * event)
  73. {
  74. struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
  75. switch (event->type)
  76. {
  77. case RTGUI_EVENT_PAINT:
  78. #ifndef RTGUI_USING_SMALL_SIZE
  79. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  80. else
  81. #endif
  82. {
  83. _rtgui_scrollbar_ondraw(bar);
  84. }
  85. break;
  86. case RTGUI_EVENT_MOUSE_BUTTON:
  87. if (RTGUI_WIDGET_IS_ENABLE(widget))
  88. {
  89. #ifndef RTGUI_USING_SMALL_SIZE
  90. if (widget->on_mouseclick != RT_NULL)
  91. {
  92. widget->on_mouseclick(widget, event);
  93. }
  94. else
  95. #endif
  96. {
  97. _rtgui_scrollbar_on_mouseclick(widget, event);
  98. }
  99. }
  100. break;
  101. default:
  102. break;
  103. }
  104. return RT_FALSE;
  105. }
  106. static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
  107. {
  108. rtgui_rect_t btn_rect, bar_rect;
  109. rt_uint32_t thumb_size, thumb_position;
  110. struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
  111. struct rtgui_event_mouse* mouse = (struct rtgui_event_mouse*)event;
  112. /* get the thumb size and position */
  113. thumb_size = bar->thumb_size * (bar->max_position - bar->min_position) / _rtgui_scrollbar_get_length(bar);
  114. thumb_position = _rtgui_scrollbar_get_thumb_position(bar);
  115. if (bar->orient == RTGUI_VERTICAL)
  116. {
  117. /* get up arrow button rect */
  118. btn_rect.x1 = widget->extent.x1;
  119. btn_rect.x2 = widget->extent.x2;
  120. btn_rect.y1 = widget->extent.y1;
  121. btn_rect.y2 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
  122. if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
  123. {
  124. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  125. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  126. {
  127. bar->status |= SBS_UPARROW;
  128. /* line step */
  129. bar->thumb_position -= bar->line_step;
  130. if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
  131. }
  132. else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
  133. {
  134. bar->status = 0;
  135. }
  136. goto __exit;
  137. }
  138. /* get bar rect */
  139. bar_rect.x1 = widget->extent.x1;
  140. bar_rect.x2 = widget->extent.x2;
  141. bar_rect.y1 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
  142. bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
  143. if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
  144. {
  145. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  146. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  147. {
  148. /* page step */
  149. if (mouse->y < bar_rect.y1 + thumb_position)
  150. {
  151. bar->thumb_position -= bar->page_step;
  152. if (bar->thumb_position < bar->min_position)
  153. bar->thumb_position = bar->min_position;
  154. }
  155. else if (mouse->y > thumb_position + bar->thumb_size)
  156. {
  157. bar->thumb_position += bar->page_step;
  158. if (bar->thumb_position > bar->max_position - thumb_size)
  159. bar->thumb_position = bar->max_position - thumb_size;
  160. }
  161. }
  162. goto __exit;
  163. }
  164. /* get down arrow button rect */
  165. btn_rect.y1 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
  166. btn_rect.y2 = widget->extent.y2;
  167. bar_rect.y1 = widget->extent.y1 + ((widget->extent.y2 - widget->extent.y1)/2);
  168. bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
  169. if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
  170. {
  171. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  172. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  173. {
  174. bar->status |= SBS_DOWNARROW;
  175. /* line step */
  176. bar->thumb_position += bar->line_step;
  177. if (bar->thumb_position > bar->max_position - thumb_size)
  178. bar->thumb_position = bar->max_position - thumb_size;
  179. }
  180. else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
  181. bar->status = 0;
  182. }
  183. }
  184. else
  185. {
  186. /* get left arrow button rect */
  187. btn_rect.x1 = widget->extent.x1;
  188. btn_rect.x2 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
  189. btn_rect.y1 = widget->extent.y1;
  190. btn_rect.y2 = widget->extent.y2;
  191. if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
  192. {
  193. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  194. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  195. {
  196. bar->status |= SBS_LEFTARROW;
  197. /* line step */
  198. bar->thumb_position -= bar->line_step;
  199. if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
  200. }
  201. else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
  202. bar->status = 0;
  203. goto __exit;
  204. }
  205. /* get bar rect */
  206. bar_rect.x1 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
  207. bar_rect.x2 = widget->extent.x2 - (widget->extent.x2 - widget->extent.x1);
  208. bar_rect.y1 = widget->extent.y1;
  209. bar_rect.y2 = widget->extent.y2;
  210. if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
  211. {
  212. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  213. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  214. {
  215. /* page step */
  216. if (mouse->x < bar_rect.x1 + thumb_position)
  217. {
  218. bar->thumb_position -= bar->page_step;
  219. if (bar->thumb_position < bar->min_position)
  220. bar->thumb_position = bar->min_position;
  221. }
  222. else if (mouse->x > thumb_position + bar->thumb_size)
  223. {
  224. bar->thumb_position += bar->page_step;
  225. if (bar->thumb_position > bar->max_position - thumb_size)
  226. bar->thumb_position = bar->max_position - thumb_size;
  227. }
  228. }
  229. goto __exit;
  230. }
  231. /* get right arrow button rect */
  232. btn_rect.x1 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
  233. btn_rect.x2 = widget->extent.x2;
  234. bar_rect.x1 = widget->extent.x1 + ((widget->extent.x2 - widget->extent.x1)/2);
  235. bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
  236. if (rtgui_rect_contains_point(&btn_rect,
  237. mouse->x, mouse->y) == RT_EOK)
  238. {
  239. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  240. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  241. {
  242. bar->status |= SBS_RIGHTARROW;
  243. /* line step */
  244. bar->thumb_position += bar->line_step;
  245. if (bar->thumb_position > bar->max_position - bar->line_step)
  246. bar->thumb_position = bar->max_position - bar->line_step;
  247. }
  248. else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
  249. bar->status = 0;
  250. }
  251. }
  252. __exit:
  253. _rtgui_scrollbar_ondraw(bar);
  254. if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
  255. (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
  256. {
  257. if (bar->on_scroll != RT_NULL) bar->on_scroll(widget, RT_NULL);
  258. }
  259. }
  260. static void _rtgui_scrollbar_ondraw(struct rtgui_scrollbar* bar)
  261. {
  262. /* draw scroll bar */
  263. struct rtgui_dc* dc;
  264. struct rtgui_rect rect;
  265. int vx[4], vy[4];
  266. /* begin drawing */
  267. dc = rtgui_dc_begin_drawing(&(bar->parent));
  268. if (dc == RT_NULL) return;
  269. rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
  270. /* draw background */
  271. RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(236, 236, 229);
  272. rtgui_dc_fill_rect(dc, &rect);
  273. if (bar->orient == RTGUI_VERTICAL)
  274. {
  275. rtgui_rect_t btn_rect, thum_rect;
  276. btn_rect = rect;
  277. btn_rect.y2 = btn_rect.y1 + rect.x2 - rect.x1;
  278. /* draw up button */
  279. if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
  280. else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
  281. /* draw arrow */
  282. if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  283. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
  284. vx[0] = 0; vy[0] = 0;
  285. vx[1] = rtgui_rect_width(rect); vy[1] = 0;
  286. vx[2] = vx[1] / 2; vy[2] = 8;
  287. vx[3] = 0; vy[3] = 0;
  288. rtgui_dc_fill_polygon(dc, vx, vy, 4);
  289. // rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_UP);
  290. /* draw thumb */
  291. if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  292. {
  293. _rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
  294. rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
  295. }
  296. /* draw down button */
  297. btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
  298. btn_rect.y2 = rect.y2;
  299. if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
  300. else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
  301. if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  302. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
  303. vx[0] = 0; vy[0] = rtgui_rect_height(rect);
  304. vx[1] = rtgui_rect_width(rect); vy[1] = rtgui_rect_height(rect);
  305. vx[2] = vx[1] / 2; vy[2] = rtgui_rect_height(rect) - 8;
  306. vx[0] = 0; vy[0] = rtgui_rect_height(rect);
  307. rtgui_dc_fill_polygon(dc, vx, vy, 4);
  308. // rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_DOWN);
  309. }
  310. else
  311. {
  312. rtgui_rect_t btn_rect, thum_rect;
  313. btn_rect.x1 = rect.x1;
  314. btn_rect.x2 = rect.y2;
  315. btn_rect.y1 = rect.y1;
  316. btn_rect.y2 = rect.y2;
  317. /* draw left button */
  318. if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
  319. else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
  320. if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  321. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
  322. vx[0] = 0; vy[0] = 0;
  323. vx[1] = 0; vy[1] = rtgui_rect_height(rect);
  324. vx[2] = 8; vy[2] = rtgui_rect_height(rect)/2;
  325. vx[3] = 0; vy[3] = 0;
  326. rtgui_dc_fill_polygon(dc, vx, vy, 4);
  327. // rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_LEFT);
  328. /* draw thumb */
  329. if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  330. {
  331. _rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
  332. rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
  333. }
  334. btn_rect.x1 = rect.x2 - rect.y2;
  335. btn_rect.x2 = rect.x2;
  336. /* draw right button */
  337. if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
  338. else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
  339. if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
  340. RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
  341. vx[0] = rtgui_rect_width(rect); vy[0] = 0;
  342. vx[1] = rtgui_rect_width(rect) - 8; vy[1] = rtgui_rect_height(rect)/2;
  343. vx[2] = rtgui_rect_width(rect); vy[2] = rtgui_rect_height(rect);
  344. vx[0] = rtgui_rect_width(rect); vy[0] = 0;
  345. rtgui_dc_fill_polygon(dc, vx, vy, 4);
  346. // rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_RIGHT);
  347. }
  348. /* end drawing */
  349. rtgui_dc_end_drawing(dc);
  350. return;
  351. }
  352. struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r)
  353. {
  354. struct rtgui_scrollbar* bar;
  355. bar = (struct rtgui_scrollbar*) rtgui_widget_create (RTGUI_SCROLLBAR_TYPE);
  356. if (bar != RT_NULL)
  357. {
  358. if (r != RT_NULL)
  359. rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
  360. bar->orient = orient;
  361. }
  362. return bar;
  363. }
  364. void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar)
  365. {
  366. rtgui_widget_destroy(RTGUI_WIDGET(bar));
  367. }
  368. void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orientation)
  369. {
  370. RT_ASSERT(bar != RT_NULL);
  371. bar->orient = orientation;
  372. bar->bar_width = RTGUI_DEFAULT_SB_HEIGHT;
  373. #ifndef RTGUI_USING_SMALL_SIZE
  374. if (bar->orient == RTGUI_HORIZONTAL)
  375. {
  376. /* horizontal */
  377. rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
  378. rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
  379. }
  380. else
  381. {
  382. /* vertical */
  383. rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
  384. rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
  385. }
  386. #endif
  387. }
  388. void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max)
  389. {
  390. RT_ASSERT(bar != RT_NULL);
  391. if (min >= max )
  392. {
  393. RTGUI_WIDGET_DISABLE(RTGUI_WIDGET(bar));
  394. return;
  395. }
  396. bar->min_position = (rt_int16_t)min;
  397. bar->max_position = (rt_int16_t)max;
  398. }
  399. void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
  400. {
  401. RT_ASSERT(bar != RT_NULL);
  402. bar->page_step = step;
  403. /* disable or enable scrollbar */
  404. if (bar->page_step > (bar->max_position - bar->min_position))
  405. {
  406. /* disable bar */
  407. RTGUI_WIDGET_DISABLE(RTGUI_WIDGET(bar));
  408. }
  409. else
  410. {
  411. /* enable bar */
  412. RTGUI_WIDGET_ENABLE(RTGUI_WIDGET(bar));
  413. }
  414. }
  415. void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step)
  416. {
  417. RT_ASSERT(bar != RT_NULL);
  418. bar->line_step = step;
  419. }
  420. rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar)
  421. {
  422. RT_ASSERT(bar != RT_NULL);
  423. return bar->thumb_position;
  424. }
  425. void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position)
  426. {
  427. RT_ASSERT(bar != RT_NULL);
  428. bar->thumb_position = position;
  429. rtgui_widget_update(RTGUI_WIDGET(bar));
  430. }
  431. void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar,
  432. rtgui_event_handler_ptr handler)
  433. {
  434. if (bar == RT_NULL || handler == RT_NULL) return;
  435. bar->on_scroll = handler;
  436. }