adw_views.mod 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. MODULE adw_views ;
  2. (*
  3. m2-GTK4 example - a tabbed window built from the GNOME (libadwaita)
  4. widgets:
  5. AdwApplicationWindow > AdwToolbarView
  6. top bar - AdwHeaderBar
  7. title widget: AdwTabBar
  8. packed start: AdwTabButton (opens AdwTabOverview)
  9. packed end: "+" button (adds a tab)
  10. content - AdwTabView
  11. Build: make examples
  12. Run: ./build/examples/adw_views
  13. *)
  14. FROM Gio IMPORT g_application_run;
  15. FROM AdwApplication IMPORT adw_application_new;
  16. FROM AdwApplicationWindow IMPORT adw_application_window_new,
  17. adw_application_window_set_content;
  18. FROM AdwHeaderBar IMPORT adw_header_bar_new, adw_header_bar_set_title_widget,
  19. adw_header_bar_pack_start, adw_header_bar_pack_end;
  20. FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar,
  21. adw_toolbar_view_set_content;
  22. FROM AdwTabView IMPORT adw_tab_view_new, adw_tab_view_append;
  23. FROM AdwTabBar IMPORT adw_tab_bar_new, adw_tab_bar_set_view;
  24. FROM AdwTabButton IMPORT adw_tab_button_new, adw_tab_button_set_view;
  25. FROM AdwTabOverview IMPORT adw_tab_overview_new, adw_tab_overview_set_view;
  26. FROM AdwTabPage IMPORT adw_tab_page_set_title;
  27. FROM GtkWindow IMPORT gtk_window_present, gtk_window_set_default_size;
  28. FROM GtkButton IMPORT gtk_button_new_with_label;
  29. FROM GtkLabel IMPORT gtk_label_new;
  30. FROM GtkClosures IMPORT Connect2;
  31. FROM GtkUtils IMPORT IntToStr, StrAppend;
  32. FROM SYSTEM IMPORT ADDRESS;
  33. FROM libc IMPORT printf;
  34. CONST
  35. AppId = "org.example.m2gtk4.AdwViews";
  36. VAR
  37. counter: INTEGER;
  38. PROCEDURE AddTab (view: ADDRESS; title: ARRAY OF CHAR);
  39. VAR
  40. page: ADDRESS;
  41. BEGIN
  42. page := adw_tab_view_append (view, gtk_label_new(title));
  43. adw_tab_page_set_title (page, title)
  44. END AddTab;
  45. PROCEDURE OnNewTab (button: ADDRESS; data: ADDRESS);
  46. VAR
  47. view: ADDRESS;
  48. num: ARRAY [0..15] OF CHAR;
  49. text: ARRAY [0..31] OF CHAR;
  50. BEGIN
  51. view := data;
  52. INC(counter);
  53. IntToStr(counter, num);
  54. text := "Tab ";
  55. StrAppend(text, num);
  56. AddTab(view, text)
  57. END OnNewTab;
  58. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  59. VAR
  60. window, toolbar, header, tabview, tabbar, tabbutton, overview,
  61. newbutton: ADDRESS;
  62. BEGIN
  63. tabview := adw_tab_view_new();
  64. AddTab(tabview, "Home");
  65. AddTab(tabview, "About");
  66. tabbar := adw_tab_bar_new();
  67. adw_tab_bar_set_view(tabbar, tabview);
  68. tabbutton := adw_tab_button_new();
  69. adw_tab_button_set_view(tabbutton, tabview);
  70. overview := adw_tab_overview_new();
  71. adw_tab_overview_set_view(overview, tabview);
  72. newbutton := gtk_button_new_with_label("+");
  73. Connect2(newbutton, "clicked", OnNewTab, tabview);
  74. header := adw_header_bar_new();
  75. adw_header_bar_set_title_widget(header, tabbar);
  76. adw_header_bar_pack_start(header, tabbutton);
  77. adw_header_bar_pack_end(header, newbutton);
  78. toolbar := adw_toolbar_view_new();
  79. adw_toolbar_view_add_top_bar(toolbar, header);
  80. adw_toolbar_view_set_content(toolbar, tabview);
  81. window := adw_application_window_new(application);
  82. gtk_window_set_default_size(window, 560, 400);
  83. adw_application_window_set_content(window, toolbar);
  84. gtk_window_present(window)
  85. END OnActivate;
  86. VAR
  87. app: ADDRESS;
  88. BEGIN
  89. counter := 2;
  90. app := adw_application_new(AppId, 0);
  91. IF app = NIL THEN
  92. printf("adw_application_new failed\n");
  93. HALT(1)
  94. END;
  95. Connect2(app, "activate", OnActivate, NIL);
  96. g_application_run(app, 0, NIL)
  97. END adw_views.