demo_tab.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "ftk.h"
  2. #include "ftk_tab.h"
  3. static Ret button_default_clicked(void* ctx, void* obj)
  4. {
  5. printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
  6. return RET_OK;
  7. }
  8. static Ret button_quit_clicked(void* ctx, void* obj)
  9. {
  10. ftk_widget_unref(ctx);
  11. return RET_OK;
  12. }
  13. #ifdef FTK_AS_PLUGIN
  14. #include "ftk_app_demo.h"
  15. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  16. FtkApp* ftk_app_demo_tab_create()
  17. {
  18. return ftk_app_demo_create(_("tab"), ftk_main);
  19. }
  20. #else
  21. #define FTK_HIDE extern
  22. #endif /*FTK_AS_PLUGIN*/
  23. static void add_page(FtkWidget* tab, const char* text, FtkBitmap* bitmap)
  24. {
  25. int width = 0;
  26. int height = 0;
  27. FtkWidget* page = NULL;
  28. FtkWidget* button = NULL;
  29. page = ftk_tab_add_page(tab, text, bitmap);
  30. width = ftk_widget_width(page);
  31. height = ftk_widget_height(page);
  32. button = ftk_button_create(page, 0, height/2-30, width/2, 60);
  33. ftk_widget_set_text(button, text);
  34. ftk_widget_show(button, 1);
  35. ftk_button_set_clicked_listener(button, button_default_clicked, tab);
  36. button = ftk_button_create(page, width/2, height/2-30, width/2, 60);
  37. ftk_widget_set_text(button, text);
  38. ftk_widget_show(button, 1);
  39. ftk_button_set_clicked_listener(button, button_default_clicked, tab);
  40. return;
  41. }
  42. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  43. {
  44. int width = 0;
  45. int height = 0;
  46. FtkWidget* win = NULL;
  47. FtkWidget* tab = NULL;
  48. FtkWidget* button = NULL;
  49. FtkBitmap* bitmap = NULL;
  50. FTK_INIT(argc, argv);
  51. bitmap = ftk_theme_load_image(ftk_default_theme(), "mime_audio"FTK_STOCK_IMG_SUFFIX);
  52. win = ftk_app_window_create();
  53. width = ftk_widget_width(win);
  54. height = ftk_widget_height(win);
  55. tab = ftk_tab_create(win, 0, 0, width, height - 50);
  56. add_page(tab, "General", bitmap);
  57. add_page(tab, "Graphic", bitmap);
  58. add_page(tab, "Audio", bitmap);
  59. ftk_tab_set_active_page(tab, 0);
  60. button = ftk_button_create(win, width/4, height - 50, width/2, 50);
  61. ftk_widget_set_text(button, _("Quit"));
  62. ftk_widget_show(button, 1);
  63. ftk_button_set_clicked_listener(button, button_quit_clicked, win);
  64. ftk_widget_show_all(win, 1);
  65. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  66. FTK_BITMAP_UNREF(bitmap);
  67. FTK_RUN();
  68. return 0;
  69. }