staticline.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. DEFINE_CLASS_TYPE(staticline, "staticline",
  13. RTGUI_WIDGET_TYPE,
  14. _rtgui_staticline_constructor,
  15. RT_NULL,
  16. sizeof(struct rtgui_staticline));
  17. rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
  18. {
  19. struct rtgui_staticline* staticline;
  20. RT_ASSERT(widget != RT_NULL);
  21. staticline = (struct rtgui_staticline*) widget;
  22. switch (event->type)
  23. {
  24. case RTGUI_EVENT_PAINT:
  25. #ifndef RTGUI_USING_SMALL_SIZE
  26. if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
  27. else
  28. #endif
  29. rtgui_theme_draw_staticline(staticline);
  30. break;
  31. }
  32. return RT_FALSE;
  33. }
  34. rtgui_staticline_t * rtgui_staticline_create(int orientation)
  35. {
  36. rtgui_staticline_t* staticline;
  37. staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
  38. if (staticline!= RT_NULL)
  39. {
  40. rtgui_staticline_set_orientation(staticline, orientation);
  41. }
  42. return staticline;
  43. }
  44. void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
  45. {
  46. rtgui_widget_destroy(RTGUI_WIDGET(staticline));
  47. }
  48. void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
  49. {
  50. RT_ASSERT(staticline != RT_NULL);
  51. staticline->orient = orientation;
  52. #ifndef RTGUI_USING_SMALL_SIZE
  53. if (orientation == RTGUI_HORIZONTAL)
  54. {
  55. /* HORIZONTAL */
  56. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
  57. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
  58. }
  59. else
  60. {
  61. /* VERTICAL */
  62. rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
  63. rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
  64. }
  65. #endif
  66. }