| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- MODULE adw ;
- (*
- m2-GTK4 example - a libadwaita preferences application.
- AdwApplicationWindow > AdwToastOverlay > AdwToolbarView
- top bar - AdwHeaderBar (title + "About" button, packed end)
- content - AdwPreferencesPage >
- AdwPreferencesGroup >
- AdwActionRow (activatable -> toast)
- AdwSwitchRow
- AdwEntryRow
- AdwComboRow
- AdwExpanderRow (with a switch row inside)
- Build: make examples
- Run: ./build/examples/adw
- *)
- 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_pack_end,
- adw_header_bar_set_title_widget;
- FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar,
- adw_toolbar_view_set_content;
- FROM AdwPreferencesPage IMPORT adw_preferences_page_new,
- adw_preferences_page_add, adw_preferences_page_set_title;
- FROM AdwPreferencesGroup IMPORT adw_preferences_group_new,
- adw_preferences_group_add, adw_preferences_group_set_title,
- adw_preferences_group_set_description;
- FROM AdwPreferencesRow IMPORT adw_preferences_row_set_title;
- FROM AdwActionRow IMPORT adw_action_row_new, adw_action_row_set_subtitle,
- adw_action_row_set_icon_name;
- FROM AdwSwitchRow IMPORT adw_switch_row_new;
- FROM AdwEntryRow IMPORT adw_entry_row_new;
- FROM AdwComboRow IMPORT adw_combo_row_new, adw_combo_row_set_model,
- adw_combo_row_set_selected;
- FROM AdwExpanderRow IMPORT adw_expander_row_new, adw_expander_row_add_row;
- FROM AdwToast IMPORT adw_toast_new, adw_toast_set_timeout;
- FROM AdwToastOverlay IMPORT adw_toast_overlay_new,
- adw_toast_overlay_add_toast, adw_toast_overlay_set_child;
- FROM AdwAboutWindow IMPORT adw_about_window_new,
- adw_about_window_set_application_name,
- adw_about_window_set_application_icon, adw_about_window_set_version,
- adw_about_window_set_developer_name, adw_about_window_set_comments,
- adw_about_window_set_website;
- FROM GtkWindow IMPORT gtk_window_present;
- FROM GtkButton IMPORT gtk_button_new_with_label;
- FROM GtkLabel IMPORT gtk_label_new;
- FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append;
- FROM GtkClosures IMPORT Connect2;
- FROM SYSTEM IMPORT ADDRESS;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.Adw";
- VAR
- overlay: ADDRESS;
- PROCEDURE ShowToast (text: ARRAY OF CHAR);
- VAR
- toast: ADDRESS;
- BEGIN
- toast := adw_toast_new(text);
- adw_toast_set_timeout(toast, 2);
- adw_toast_overlay_add_toast(overlay, toast)
- END ShowToast;
- (* void activated(AdwActionRow *row, gpointer data) *)
- PROCEDURE OnRowActivated (row: ADDRESS; data: ADDRESS);
- BEGIN
- ShowToast("Row activated")
- END OnRowActivated;
- PROCEDURE OnAbout (button: ADDRESS; data: ADDRESS);
- VAR
- about: ADDRESS;
- BEGIN
- about := adw_about_window_new();
- adw_about_window_set_application_name(about, "m2-GTK4");
- adw_about_window_set_application_icon(about, "application-x-executable");
- adw_about_window_set_version(about, "0.1");
- adw_about_window_set_developer_name(about, "m2-GTK4");
- adw_about_window_set_comments(about, "libadwaita bindings for GNU Modula-2");
- adw_about_window_set_website(about, "https://example.org");
- gtk_window_present(about)
- END OnAbout;
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, toolbar, header, aboutButton, page, group, row, sw, er, combo,
- list, expander, inner: ADDRESS;
- BEGIN
- window := adw_application_window_new(application);
- aboutButton := gtk_button_new_with_label("About");
- Connect2(aboutButton, "clicked", OnAbout, NIL);
- header := adw_header_bar_new();
- adw_header_bar_set_title_widget(header, gtk_label_new("Preferences"));
- adw_header_bar_pack_end(header, aboutButton);
- toolbar := adw_toolbar_view_new();
- adw_toolbar_view_add_top_bar(toolbar, header);
- page := adw_preferences_page_new();
- adw_preferences_page_set_title(page, "Settings");
- group := adw_preferences_group_new();
- adw_preferences_group_set_title(group, "General");
- adw_preferences_group_set_description(group, "Example Adwaita rows");
- row := adw_action_row_new();
- adw_preferences_row_set_title(row, "Appearance");
- adw_action_row_set_subtitle(row, "Tap to show a toast");
- adw_action_row_set_icon_name(row, "applications-graphics");
- Connect2(row, "activated", OnRowActivated, NIL);
- adw_preferences_group_add(group, row);
- sw := adw_switch_row_new();
- adw_preferences_row_set_title(sw, "Enable notifications");
- adw_preferences_group_add(group, sw);
- er := adw_entry_row_new();
- adw_preferences_row_set_title(er, "Name");
- adw_preferences_group_add(group, er);
- list := gtk_string_list_new(NIL);
- gtk_string_list_append(list, "System");
- gtk_string_list_append(list, "Light");
- gtk_string_list_append(list, "Dark");
- combo := adw_combo_row_new();
- adw_preferences_row_set_title(combo, "Theme");
- adw_combo_row_set_model(combo, list);
- adw_combo_row_set_selected(combo, 0);
- adw_preferences_group_add(group, combo);
- expander := adw_expander_row_new();
- adw_preferences_row_set_title(expander, "Advanced");
- inner := adw_switch_row_new();
- adw_preferences_row_set_title(inner, "Developer mode");
- adw_expander_row_add_row(expander, inner);
- adw_preferences_group_add(group, expander);
- adw_preferences_page_add(page, group);
- adw_toolbar_view_set_content(toolbar, page);
- overlay := adw_toast_overlay_new();
- adw_toast_overlay_set_child(overlay, toolbar);
- adw_application_window_set_content(window, overlay);
- gtk_window_present(window)
- END OnActivate;
- VAR
- app: ADDRESS;
- BEGIN
- 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.
|