MODULE adw_views ; (* m2-GTK4 example - a tabbed window built from the GNOME (libadwaita) widgets: AdwApplicationWindow > AdwToolbarView top bar - AdwHeaderBar title widget: AdwTabBar packed start: AdwTabButton (opens AdwTabOverview) packed end: "+" button (adds a tab) content - AdwTabView Build: make examples Run: ./build/examples/adw_views *) FROM Gio IMPORT g_application_run; FROM AdwApplication IMPORT adw_application_new; FROM AdwApplicationWindow IMPORT adw_application_window_new, adw_application_window_set_content; FROM AdwHeaderBar IMPORT adw_header_bar_new, adw_header_bar_set_title_widget, adw_header_bar_pack_start, adw_header_bar_pack_end; FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar, adw_toolbar_view_set_content; FROM AdwTabView IMPORT adw_tab_view_new, adw_tab_view_append; FROM AdwTabBar IMPORT adw_tab_bar_new, adw_tab_bar_set_view; FROM AdwTabButton IMPORT adw_tab_button_new, adw_tab_button_set_view; FROM AdwTabOverview IMPORT adw_tab_overview_new, adw_tab_overview_set_view; FROM AdwTabPage IMPORT adw_tab_page_set_title; FROM GtkWindow IMPORT gtk_window_present, gtk_window_set_default_size; FROM GtkButton IMPORT gtk_button_new_with_label; FROM GtkLabel IMPORT gtk_label_new; FROM GtkClosures IMPORT Connect2; FROM GtkUtils IMPORT IntToStr, StrAppend; FROM SYSTEM IMPORT ADDRESS; FROM libc IMPORT printf; CONST AppId = "org.example.m2gtk4.AdwViews"; VAR counter: INTEGER; PROCEDURE AddTab (view: ADDRESS; title: ARRAY OF CHAR); VAR page: ADDRESS; BEGIN page := adw_tab_view_append (view, gtk_label_new(title)); adw_tab_page_set_title (page, title) END AddTab; PROCEDURE OnNewTab (button: ADDRESS; data: ADDRESS); VAR view: ADDRESS; num: ARRAY [0..15] OF CHAR; text: ARRAY [0..31] OF CHAR; BEGIN view := data; INC(counter); IntToStr(counter, num); text := "Tab "; StrAppend(text, num); AddTab(view, text) END OnNewTab; PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS); VAR window, toolbar, header, tabview, tabbar, tabbutton, overview, newbutton: ADDRESS; BEGIN tabview := adw_tab_view_new(); AddTab(tabview, "Home"); AddTab(tabview, "About"); tabbar := adw_tab_bar_new(); adw_tab_bar_set_view(tabbar, tabview); tabbutton := adw_tab_button_new(); adw_tab_button_set_view(tabbutton, tabview); overview := adw_tab_overview_new(); adw_tab_overview_set_view(overview, tabview); newbutton := gtk_button_new_with_label("+"); Connect2(newbutton, "clicked", OnNewTab, tabview); header := adw_header_bar_new(); adw_header_bar_set_title_widget(header, tabbar); adw_header_bar_pack_start(header, tabbutton); adw_header_bar_pack_end(header, newbutton); toolbar := adw_toolbar_view_new(); adw_toolbar_view_add_top_bar(toolbar, header); adw_toolbar_view_set_content(toolbar, tabview); window := adw_application_window_new(application); gtk_window_set_default_size(window, 560, 400); adw_application_window_set_content(window, toolbar); gtk_window_present(window) END OnActivate; VAR app: ADDRESS; BEGIN counter := 2; app := adw_application_new(AppId, 0); IF app = NIL THEN printf("adw_application_new failed\n"); HALT(1) END; Connect2(app, "activate", OnActivate, NIL); g_application_run(app, 0, NIL) END adw_views.