demo_wait_box.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "ftk.h"
  2. static Ret button_quit_clicked(void* ctx, void* obj)
  3. {
  4. ftk_widget_unref(ctx);
  5. return RET_OK;
  6. }
  7. static Ret button_start_clicked(void* ctx, void* obj)
  8. {
  9. ftk_widget_show(ctx, 1);
  10. ftk_wait_box_start_waiting(ctx);
  11. return RET_OK;
  12. }
  13. static Ret button_stop_clicked(void* ctx, void* obj)
  14. {
  15. ftk_wait_box_stop_waiting(ctx);
  16. return RET_OK;
  17. }
  18. #ifdef FTK_AS_PLUGIN
  19. #include "ftk_app_demo.h"
  20. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  21. FtkApp* ftk_app_demo_wait_box_create()
  22. {
  23. return ftk_app_demo_create(_("wait_box"), ftk_main);
  24. }
  25. #else
  26. #define FTK_HIDE extern
  27. #endif /*FTK_AS_PLUGIN*/
  28. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  29. {
  30. int width = 0;
  31. int height = 0;
  32. FtkWidget* win = NULL;
  33. FtkWidget* button = NULL;
  34. FtkWidget* wait_box = NULL;
  35. FTK_INIT(argc, argv);
  36. win = ftk_app_window_create();
  37. width = ftk_widget_width(win);
  38. height = ftk_widget_height(win);
  39. wait_box = ftk_wait_box_create(win, width/2 - 16, height/4);
  40. button = ftk_button_create(win, 0, height/2, width/3, 50);
  41. ftk_widget_set_text(button, "start");
  42. ftk_button_set_clicked_listener(button, button_start_clicked, wait_box);
  43. button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
  44. ftk_widget_set_text(button, "stop");
  45. ftk_button_set_clicked_listener(button, button_stop_clicked, wait_box);
  46. button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
  47. ftk_widget_set_text(button, "quit");
  48. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  49. ftk_window_set_focus(win, button);
  50. ftk_widget_set_text(win, "wait_box demo");
  51. ftk_widget_show_all(win, 1);
  52. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  53. FTK_RUN();
  54. return 0;
  55. }