staticline.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <rtgui/dc.h>
  2. #include <rtgui/rtgui_theme.h>
  3. #include <rtgui/widgets/staticline.h>
  4. static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
  5. {
  6. /* init widget and set event handler */
  7. rtgui_rect_t rect = {0, 0, 100, 2};
  8. rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
  9. staticline->orient= RTGUI_HORIZONTAL;
  10. rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
  11. }
  12. rtgui_type_t *rtgui_staticline_type_get(void)
  13. {
  14. static rtgui_type_t *staticline_type = RT_NULL;
  15. if (!staticline_type)
  16. {
  17. staticline_type = rtgui_type_create("staticline", RTGUI_WIDGET_TYPE,
  18. sizeof(rtgui_staticline_t), RTGUI_CONSTRUCTOR(_rtgui_staticline_constructor), RT_NULL);
  19. }
  20. return staticline_type;
  21. }
  22. rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  23. {
  24. struct rtgui_staticline* staticline;
  25. RT_ASSERT(widget != RT_NULL);
  26. staticline = (struct rtgui_staticline*) widget;
  27. switch (event->type)
  28. {
  29. case RTGUI_EVENT_PAINT:
  30. #ifndef RTGUI_USING_SMALL_SIZE
  31. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  32. else
  33. #endif
  34. rtgui_theme_draw_staticline(staticline);
  35. break;
  36. }
  37. return RT_FALSE;
  38. }
  39. rtgui_staticline_t * rtgui_staticline_create(int orientation)
  40. {
  41. rtgui_staticline_t* staticline;
  42. staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
  43. if (staticline!= RT_NULL)
  44. {
  45. rtgui_staticline_set_orientation(staticline, orientation);
  46. }
  47. return staticline;
  48. }
  49. void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
  50. {
  51. rtgui_widget_destroy(RTGUI_WIDGET(staticline));
  52. }
  53. void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
  54. {
  55. RT_ASSERT(staticline != RT_NULL);
  56. staticline->orient = orientation;
  57. #ifndef RTGUI_USING_SMALL_SIZE
  58. if (orientation == RTGUI_HORIZONTAL)
  59. {
  60. /* HORIZONTAL */
  61. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
  62. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
  63. }
  64. else
  65. {
  66. /* VERTICAL */
  67. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
  68. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
  69. }
  70. #endif
  71. }