1
0

demo_listview.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "demo_view.h"
  2. #include <rtgui/widgets/label.h>
  3. #include <rtgui/widgets/button.h>
  4. #include <rtgui/widgets/window.h>
  5. #include <rtgui/widgets/list_view.h>
  6. static rtgui_workbench_t* workbench = RT_NULL;
  7. static rtgui_view_t* _view = RT_NULL;
  8. static rtgui_image_t* return_image = RT_NULL;
  9. static void listitem_action(void* parameter)
  10. {
  11. char label_text[32];
  12. rtgui_win_t *win;
  13. rtgui_label_t *label;
  14. rtgui_rect_t rect = {0, 0, 150, 80};
  15. int no = (int)parameter;
  16. rtgui_rect_moveto(&rect, 20, 50);
  17. /* 显示消息窗口 */
  18. win = rtgui_win_create(RTGUI_TOPLEVEL(workbench),
  19. "窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
  20. rect.x1 += 20; rect.x2 -= 5;
  21. rect.y1 += 5; rect.y2 = rect.y1 + 20;
  22. rt_sprintf(label_text, "动作 %d", no);
  23. label = rtgui_label_create(label_text);
  24. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  25. rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
  26. /* 非模态显示窗口 */
  27. rtgui_win_show(win, RT_FALSE);
  28. }
  29. static void return_action(void* parameter)
  30. {
  31. if (_view != RT_NULL)
  32. {
  33. rtgui_view_destroy(_view);
  34. _view = RT_NULL;
  35. }
  36. }
  37. static const struct rtgui_list_item items[] =
  38. {
  39. {"列表项1", RT_NULL, listitem_action, (void*)1},
  40. {"列表项2", RT_NULL, listitem_action, (void*)2},
  41. {"列表项3", RT_NULL, listitem_action, (void*)3},
  42. {"列表项4", RT_NULL, listitem_action, (void*)4},
  43. {"列表项5", RT_NULL, listitem_action, (void*)5},
  44. {"返回", RT_NULL, return_action, RT_NULL},
  45. };
  46. static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
  47. {
  48. /* create a file list view */
  49. rtgui_rect_t rect;
  50. workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
  51. rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
  52. _view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item), &rect);
  53. rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));
  54. /* 模式显示视图 */
  55. rtgui_view_show(RTGUI_VIEW(_view), RT_FALSE);
  56. }
  57. rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench)
  58. {
  59. rtgui_rect_t rect;
  60. rtgui_list_view_t *view;
  61. rtgui_button_t* open_btn;
  62. view = demo_view(workbench, "列表视图演示");
  63. demo_view_get_rect(view, &rect);
  64. rect.x1 += 5; rect.x2 = rect.x1 + 80;
  65. rect.y1 += 30; rect.y2 = rect.y1 + 20;
  66. open_btn = rtgui_button_create("打开列表");
  67. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
  68. rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
  69. rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
  70. return view;
  71. }