Selaa lähdekoodia

refactor(demos): use the new bindings in four demos

- password_entry now uses GtkPasswordEntry instead of a hidden GtkEntry
- sizegroup now creates a GtkSizeGroup and adds the label widgets to it
- tabs now builds tab stops with PangoTabArray + gtk_text_view_set_tabs
- headerbar uses gtk_button_new_from_icon_name for its icon buttons
Eric Streit 3 päivää sitten
vanhempi
commit
d6bb082f8f
3 muutettua tiedostoa jossa 27 lisäystä ja 29 poistoa
  1. 3 8
      demos/DemosInput.mod
  2. 11 10
      demos/DemosLayout.mod
  3. 13 11
      demos/DemosWindows.mod

+ 3 - 8
demos/DemosInput.mod

@@ -34,8 +34,8 @@ FROM GtkEnums IMPORT GtkVertical, GtkHorizontal, GtkAlignCenter, GtkAlignEnd;
 FROM GtkBox IMPORT gtk_box_new, gtk_box_append, gtk_box_remove;
 FROM GtkHeaderBar IMPORT gtk_header_bar_new,
    gtk_header_bar_set_show_title_buttons, gtk_header_bar_pack_end;
-FROM GtkEntry IMPORT gtk_entry_new, gtk_entry_set_placeholder_text,
-   gtk_entry_set_visibility, gtk_entry_set_activates_default;
+FROM GtkEntry IMPORT gtk_entry_new, gtk_entry_set_placeholder_text;
+FROM GtkPasswordEntry IMPORT gtk_password_entry_new;
 FROM GtkEditable IMPORT gtk_editable_get_text;
 FROM GtkSearchEntry IMPORT gtk_search_entry_new;
 FROM GtkSearchBar IMPORT gtk_search_bar_new, gtk_search_bar_connect_entry,
@@ -104,12 +104,7 @@ PROCEDURE PasswordField (placeholder: ARRAY OF CHAR) : ADDRESS;
 VAR
    entry: ADDRESS;
 BEGIN
-   (* GtkPasswordEntry is not bound; a GtkEntry with the text hidden
-      behaves the same for this demo and is read via GtkEditable. *)
-   entry := gtk_entry_new();
-   gtk_entry_set_visibility(entry, 0);
-   gtk_entry_set_placeholder_text(entry, placeholder);
-   gtk_entry_set_activates_default(entry, 1);
+   entry := gtk_password_entry_new();
    g_signal_connect_data(entry, "notify::text", ADR(OnUpdateButton),
                          NIL, NIL, GConnectDefault);
    RETURN entry

+ 11 - 10
demos/DemosLayout.mod

@@ -25,6 +25,8 @@ FROM GtkFrame IMPORT gtk_frame_new, gtk_frame_set_child;
 FROM GtkLabel IMPORT gtk_label_new;
 FROM GtkDropDown IMPORT gtk_drop_down_new;
 FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append;
+FROM GtkSizeGroup IMPORT gtk_size_group_new, gtk_size_group_add_widget,
+   GtkSizeGroupHorizontal;
 FROM GtkCheckButton IMPORT gtk_check_button_new_with_label,
    gtk_check_button_set_active;
 FROM GtkScrolledWindow IMPORT gtk_scrolled_window_new,
@@ -59,7 +61,7 @@ END MakeDropDown;
    SIMPLIFIED: gtk_label_new_with_mnemonic() and
    gtk_label_set_mnemonic_widget() are not bound, so a plain label is
    used (the underscores are dropped rather than shown literally). *)
-PROCEDURE AddRow (table: ADDRESS; row: INTEGER;
+PROCEDURE AddRow (group, table: ADDRESS; row: INTEGER;
                   labelText, a, b, c: ARRAY OF CHAR);
 VAR
    label, dropdown: ADDRESS;
@@ -68,6 +70,7 @@ BEGIN
    gtk_widget_set_halign(label, GtkAlignStart);
    gtk_widget_set_valign(label, GtkAlignBaseline);
    gtk_widget_set_hexpand(label, 1);
+   IF group # NIL THEN gtk_size_group_add_widget(group, label) END;
    gtk_grid_attach(table, label, 0, row, 1, 1);
 
    dropdown := MakeDropDown(a, b, c);
@@ -78,7 +81,7 @@ END AddRow;
 
 PROCEDURE DoSizeGroup (doWidget: ADDRESS) : ADDRESS;
 VAR
-   vbox, frame, table, checkButton: ADDRESS;
+   vbox, frame, table, checkButton, group: ADDRESS;
 BEGIN
    IF sizeGroupWindow = NIL THEN
       sizeGroupWindow := gtk_window_new();
@@ -92,10 +95,8 @@ BEGIN
       gtk_widget_set_margin_bottom(vbox, 5);
       gtk_window_set_child(sizeGroupWindow, vbox);
 
-      (* SIMPLIFIED: GtkSizeGroup is not bound under src/, so the
-         gtk_size_group_new()/add_widget()/set_mode() machinery and the
-         "toggled" callback that switches it on and off are omitted.
-         The two grids below are otherwise identical to the C demo. *)
+      (* the labels in both grids share one horizontal size group *)
+      group := gtk_size_group_new(GtkSizeGroupHorizontal);
 
       (* Color options *)
       frame := gtk_frame_new("Color Options");
@@ -108,8 +109,8 @@ BEGIN
       gtk_grid_set_row_spacing(table, 5);
       gtk_grid_set_column_spacing(table, 10);
       gtk_frame_set_child(frame, table);
-      AddRow(table, 0, "Foreground", "Red", "Green", "Blue");
-      AddRow(table, 1, "Background", "Red", "Green", "Blue");
+      AddRow(group, table, 0, "Foreground", "Red", "Green", "Blue");
+      AddRow(group, table, 1, "Background", "Red", "Green", "Blue");
 
       (* Line options *)
       frame := gtk_frame_new("Line Options");
@@ -122,8 +123,8 @@ BEGIN
       gtk_grid_set_row_spacing(table, 5);
       gtk_grid_set_column_spacing(table, 10);
       gtk_frame_set_child(frame, table);
-      AddRow(table, 0, "Dashing", "Solid", "Dashed", "Dotted");
-      AddRow(table, 1, "Line ends", "Square", "Round", "Double Arrow");
+      AddRow(group, table, 0, "Dashing", "Solid", "Dashed", "Dotted");
+      AddRow(group, table, 1, "Line ends", "Square", "Round", "Double Arrow");
 
       checkButton := gtk_check_button_new_with_label("Enable grouping");
       gtk_box_append(vbox, checkButton);

+ 13 - 11
demos/DemosWindows.mod

@@ -35,14 +35,15 @@ FROM GtkEnums IMPORT GtkHorizontal, GtkVertical, GtkAlignCenter,
 FROM GtkHeaderBar IMPORT gtk_header_bar_new, gtk_header_bar_pack_start,
    gtk_header_bar_pack_end;
 FROM GtkBox IMPORT gtk_box_new, gtk_box_append;
-FROM GtkImage IMPORT gtk_image_new_from_icon_name;
-FROM GtkButton IMPORT gtk_button_new, gtk_button_set_child;
+FROM GtkButton IMPORT gtk_button_new_from_icon_name;
 FROM GtkSwitch IMPORT gtk_switch_new;
 FROM GtkTextView IMPORT gtk_text_view_new, gtk_text_view_get_buffer,
    gtk_text_view_set_wrap_mode, gtk_text_view_set_top_margin,
    gtk_text_view_set_bottom_margin, gtk_text_view_set_left_margin,
-   gtk_text_view_set_right_margin;
+   gtk_text_view_set_right_margin, gtk_text_view_set_tabs;
 FROM GtkTextBuffer IMPORT gtk_text_buffer_set_text;
+FROM PangoTabArray IMPORT pango_tab_array_new, pango_tab_array_set_tab,
+   pango_tab_array_free, PangoTabLeft, PangoTabDecimal;
 FROM GtkScrolledWindow IMPORT gtk_scrolled_window_new,
    gtk_scrolled_window_set_child, gtk_scrolled_window_set_policy,
    GtkPolicyNever, GtkPolicyAutomatic;
@@ -71,15 +72,10 @@ FROM GLib IMPORT g_timeout_add, GSourceContinue, GSourceRemove;
 VAR
    headerBarWindow: ADDRESS;
 
-(* gtk_button_new_from_icon_name() is not bound: build the equivalent
-   from an empty button and an icon-name GtkImage child. *)
+(* GtkWidget *gtk_button_new_from_icon_name(const char *icon_name) *)
 PROCEDURE IconButton (name: ARRAY OF CHAR) : ADDRESS;
-VAR
-   button: ADDRESS;
 BEGIN
-   button := gtk_button_new();
-   gtk_button_set_child(button, gtk_image_new_from_icon_name(name));
-   RETURN button
+   RETURN gtk_button_new_from_icon_name(name)
 END IconButton;
 
 PROCEDURE DoHeaderBar (doWidget: ADDRESS) : ADDRESS;
@@ -240,7 +236,7 @@ END SetTabsText;
 
 PROCEDURE DoTabs (doWidget: ADDRESS) : ADDRESS;
 VAR
-   view, sw, buffer: ADDRESS;
+   view, sw, buffer, tabs: ADDRESS;
 BEGIN
    IF tabsWindow = NIL THEN
       tabsWindow := gtk_window_new();
@@ -255,6 +251,12 @@ BEGIN
       gtk_text_view_set_left_margin(view, 20);
       gtk_text_view_set_right_margin(view, 20);
 
+      tabs := pango_tab_array_new(2, 1);
+      pango_tab_array_set_tab(tabs, 0, PangoTabLeft, 50);
+      pango_tab_array_set_tab(tabs, 1, PangoTabDecimal, 100);
+      gtk_text_view_set_tabs(view, tabs);
+      pango_tab_array_free(tabs);
+
       buffer := gtk_text_view_get_buffer(view);
       SetTabsText(buffer);