adw_widgets.mod 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. MODULE adw_widgets ;
  2. (*
  3. m2-GTK4 example - a showcase of the GNOME (libadwaita) widgets bound
  4. in this slice:
  5. AdwApplicationWindow > AdwToolbarView
  6. top bar - AdwHeaderBar with an AdwViewSwitcherTitle
  7. content - GtkBox >
  8. AdwBanner
  9. AdwSqueezer (two labels; shows the one that fits)
  10. AdwWrapBox (wrapping labels)
  11. AdwViewStack > page "Home" - AdwAvatar
  12. > page "About" - AdwSpinner + button
  13. with AdwButtonContent
  14. Build: make examples
  15. Run: ./build/examples/adw_widgets
  16. *)
  17. FROM Gio IMPORT g_application_run;
  18. FROM AdwApplication IMPORT adw_application_new;
  19. FROM AdwApplicationWindow IMPORT adw_application_window_new,
  20. adw_application_window_set_content;
  21. FROM AdwHeaderBar IMPORT adw_header_bar_new,
  22. adw_header_bar_set_title_widget;
  23. FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar,
  24. adw_toolbar_view_set_content;
  25. FROM AdwViewSwitcherTitle IMPORT adw_view_switcher_title_new,
  26. adw_view_switcher_title_set_title, adw_view_switcher_title_set_subtitle,
  27. adw_view_switcher_title_set_stack;
  28. FROM AdwViewStack IMPORT adw_view_stack_new, adw_view_stack_add_titled,
  29. adw_view_stack_add_titled_with_icon;
  30. FROM AdwBanner IMPORT adw_banner_new, adw_banner_set_revealed;
  31. FROM AdwSqueezer IMPORT adw_squeezer_new, adw_squeezer_add;
  32. FROM AdwWrapBox IMPORT adw_wrap_box_new, adw_wrap_box_append;
  33. FROM AdwAvatar IMPORT adw_avatar_new;
  34. FROM AdwSpinner IMPORT adw_spinner_new;
  35. FROM AdwButtonContent IMPORT adw_button_content_new,
  36. adw_button_content_set_label, adw_button_content_set_icon_name;
  37. FROM GtkWindow IMPORT gtk_window_present, gtk_window_set_default_size;
  38. FROM GtkBox IMPORT gtk_box_new, gtk_box_append, gtk_box_set_spacing;
  39. FROM GtkButton IMPORT gtk_button_new, gtk_button_set_child;
  40. FROM GtkLabel IMPORT gtk_label_new;
  41. FROM GtkEnums IMPORT GtkVertical;
  42. FROM GtkClosures IMPORT Connect2;
  43. FROM SYSTEM IMPORT ADDRESS;
  44. FROM libc IMPORT printf;
  45. CONST
  46. AppId = "org.example.m2gtk4.AdwWidgets";
  47. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  48. VAR
  49. window, toolbar, header, switcherTitle, stack, home, about: ADDRESS;
  50. box, banner, squeezer, wrap, avatar, spinner, button: ADDRESS;
  51. content: ADDRESS;
  52. BEGIN
  53. window := adw_application_window_new(application);
  54. gtk_window_set_default_size(window, 420, 420);
  55. stack := adw_view_stack_new();
  56. (* page: Home *)
  57. home := gtk_box_new(GtkVertical, 18);
  58. gtk_box_set_spacing(home, 18);
  59. avatar := adw_avatar_new(64, "Eric", 1);
  60. gtk_box_append(home, avatar);
  61. gtk_box_append(home, gtk_label_new("Welcome to the GNOME widgets demo."));
  62. content := adw_view_stack_add_titled(stack, home, "home", "Home");
  63. (* page: About *)
  64. about := gtk_box_new(GtkVertical, 18);
  65. gtk_box_set_spacing(about, 18);
  66. spinner := adw_spinner_new();
  67. gtk_box_append(about, spinner);
  68. button := gtk_button_new();
  69. content := adw_button_content_new();
  70. adw_button_content_set_icon_name(content, "emblem-system-symbolic");
  71. adw_button_content_set_label(content, "Preferences");
  72. gtk_button_set_child(button, content);
  73. gtk_box_append(about, button);
  74. content := adw_view_stack_add_titled_with_icon(stack, about, "about",
  75. "About",
  76. "help-about-symbolic");
  77. (* title that becomes a switcher when the window is wide *)
  78. switcherTitle := adw_view_switcher_title_new();
  79. adw_view_switcher_title_set_title(switcherTitle, "m2-GTK4");
  80. adw_view_switcher_title_set_subtitle(switcherTitle, "GNOME widgets");
  81. adw_view_switcher_title_set_stack(switcherTitle, stack);
  82. header := adw_header_bar_new();
  83. adw_header_bar_set_title_widget(header, switcherTitle);
  84. toolbar := adw_toolbar_view_new();
  85. adw_toolbar_view_add_top_bar(toolbar, header);
  86. (* content: banner + squeezer + wrapbox + the stack *)
  87. box := gtk_box_new(GtkVertical, 12);
  88. gtk_box_set_spacing(box, 12);
  89. banner := adw_banner_new("This is an AdwBanner");
  90. adw_banner_set_revealed(banner, 1);
  91. gtk_box_append(box, banner);
  92. squeezer := adw_squeezer_new();
  93. content := adw_squeezer_add(squeezer, gtk_label_new("Wide layout"));
  94. content := adw_squeezer_add(squeezer, gtk_label_new("Narrow"));
  95. gtk_box_append(box, squeezer);
  96. wrap := adw_wrap_box_new();
  97. adw_wrap_box_append(wrap, gtk_label_new("one"));
  98. adw_wrap_box_append(wrap, gtk_label_new("two"));
  99. adw_wrap_box_append(wrap, gtk_label_new("three"));
  100. adw_wrap_box_append(wrap, gtk_label_new("four"));
  101. gtk_box_append(box, wrap);
  102. gtk_box_append(box, stack);
  103. adw_toolbar_view_set_content(toolbar, box);
  104. adw_application_window_set_content(window, toolbar);
  105. gtk_window_present(window)
  106. END OnActivate;
  107. VAR
  108. app: ADDRESS;
  109. BEGIN
  110. app := adw_application_new(AppId, 0);
  111. IF app = NIL THEN
  112. printf("adw_application_new failed\n");
  113. HALT(1)
  114. END;
  115. Connect2(app, "activate", OnActivate, NIL);
  116. g_application_run(app, 0, NIL)
  117. END adw_widgets.