demo_fnview.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "demo_view.h"
  2. #include <rtgui/widgets/label.h>
  3. #include <rtgui/widgets/button.h>
  4. #include <rtgui/widgets/filelist_view.h>
  5. static rtgui_label_t* label;
  6. static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
  7. {
  8. /* create a file list view */
  9. rtgui_filelist_view_t *view;
  10. rtgui_workbench_t *workbench;
  11. rtgui_rect_t rect;
  12. workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
  13. rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
  14. view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
  15. if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
  16. {
  17. char path[32];
  18. /* set label */
  19. rtgui_filelist_get_fullpath(view, path, sizeof(path));
  20. rtgui_label_set_text(label, path);
  21. }
  22. /* ɾ³ý ÎļþÁбí ÊÓͼ */
  23. rtgui_view_destroy(RTGUI_VIEW(view));
  24. }
  25. rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
  26. {
  27. rtgui_rect_t rect;
  28. rtgui_view_t* view;
  29. rtgui_button_t* open_btn;
  30. rtgui_font_t* font;
  31. font = rtgui_font_refer("asc", 12);
  32. view = demo_view(workbench, "FileList View");
  33. demo_view_get_rect(view, &rect);
  34. rect.x1 += 5; rect.x2 -= 5;
  35. rect.y1 += 5; rect.y2 = rect.y1 + 20;
  36. label = rtgui_label_create("fn: ");
  37. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
  38. rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
  39. RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
  40. demo_view_get_rect(view, &rect);
  41. rect.x1 += 5; rect.x2 = rect.x1 + 80;
  42. rect.y1 += 30; rect.y2 = rect.y1 + 20;
  43. open_btn = rtgui_button_create("Open File");
  44. rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
  45. rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
  46. RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font;
  47. rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
  48. return view;
  49. }