demo_listview.c 2.2 KB

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