[gtk/matthiasc/for-main: 2/4] Font features demo improvements




commit 5d05daaed0c9251ed1e9961e7f0186348630e6e3
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 2 23:37:34 2022 -0400

    Font features demo improvements
    
    Add buttons to cycle through samples.

 demos/gtk-demo/font_features.c     | 36 +++++++++++++++++++++
 demos/gtk-demo/font_features.c.rej | 65 ++++++++++++++++++++++++++++++++++++++
 demos/gtk-demo/font_features.ui    | 40 +++++++++++++++--------
 3 files changed, 128 insertions(+), 13 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 3a5b50f1bb..c2e0e23d11 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -80,6 +80,7 @@ typedef struct {
   char *text;
   GtkWidget *swin;
   GtkCssProvider *provider;
+  int sample;
 } FontFeaturesDemo;
 
 static void
@@ -1574,6 +1575,39 @@ entry_key_press (GtkEventController *controller,
   return GDK_EVENT_PROPAGATE;
 }
 
+static const char *paragraphs[] = {
+  "Grumpy wizards make toxic brew for the evil Queen and Jack. A quick movement of the enemy will jeopardize 
six gunboats. The job of waxing linoleum frequently peeves chintzy kids. My girl wove six dozen plaid jackets 
before she quit. Twelve ziggurats quickly jumped a finch box.",
+  "Разъяренный чтец эгоистично бьёт пятью жердями шустрого фехтовальщика. Наш банк вчера же выплатил Ф.Я. 
Эйхгольду комиссию за ценные вещи. Эх, чужак, общий съём цен шляп (юфть) – вдрызг! В чащах юга жил бы цитрус? 
Да, но фальшивый экземпляр!",
+  "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός",
+};
+
+static const char *alphabets[] = {
+  "abcdefghijklmnopqrstuvwxzy",
+  "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
+  "0123456789",
+  "!@#$%^&*/?;",
+};
+
+static void
+set_text_alphabet (void)
+{
+  demo->sample++;
+  gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (demo->entry)),
+                            alphabets[demo->sample % G_N_ELEMENTS (alphabets)],
+                            -1);
+  update_display ();
+}
+
+static void
+set_text_paragraph (void)
+{
+  demo->sample++;
+  gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (demo->entry)),
+                            paragraphs[demo->sample % G_N_ELEMENTS (paragraphs)],
+                            -1);
+  update_display ();
+}
+
 GtkWidget *
 do_font_features (GtkWidget *do_widget)
 {
@@ -1601,6 +1635,8 @@ do_font_features (GtkWidget *do_widget)
       gtk_builder_cscope_add_callback (scope, font_features_font_changed);
       gtk_builder_cscope_add_callback (scope, font_features_script_changed);
       gtk_builder_cscope_add_callback (scope, font_features_notify_waterfall);
+      gtk_builder_cscope_add_callback (scope, set_text_alphabet);
+      gtk_builder_cscope_add_callback (scope, set_text_paragraph);
       gtk_builder_set_scope (builder, scope);
 
       demo = g_new0 (FontFeaturesDemo, 1);
diff --git a/demos/gtk-demo/font_features.c.rej b/demos/gtk-demo/font_features.c.rej
new file mode 100644
index 0000000000..2f1f325332
--- /dev/null
+++ b/demos/gtk-demo/font_features.c.rej
@@ -0,0 +1,65 @@
+--- demos/gtk-demo/font_features.c
++++ demos/gtk-demo/font_features.c
+@@ -434,7 +434,7 @@ static void
+ update_display (void)
+ {
+   GString *s;
+-  const char *text;
++  char *text;
+   gboolean has_feature;
+   GtkTreeIter iter;
+   GtkTreeModel *model;
+@@ -452,8 +452,12 @@ update_display (void)
+   gboolean do_waterfall;
+   GString *waterfall;
+   char *palette;
++  GtkTextBuffer *buffer;
++  GtkTextIter start_iter, end_iter;
+ 
+-  text = gtk_editable_get_text (GTK_EDITABLE (demo->the_entry));
++  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (demo->the_entry));
++  gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
++  text = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE);
+   text_len = strlen (text);
+ 
+   do_waterfall = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (demo->waterfall_toggle));
+@@ -631,6 +635,8 @@ update_display (void)
+   pango2_font_description_free (desc);
+   g_free (features);
+   pango2_attr_list_unref (attrs);
++
++  g_free (text);
+ }
+ 
+ static Pango2Font *
+@@ -1603,8 +1609,12 @@ font_features_toggle_edit (void)
+ {
+   if (strcmp (gtk_stack_get_visible_child_name (GTK_STACK (demo->stack)), "entry") != 0)
+     {
++      GtkTextBuffer *buffer;
++      GtkTextIter start, end;
+       g_free (demo->text);
+-      demo->text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (demo->the_entry)));
++      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (demo->the_entry));
++      gtk_text_buffer_get_bounds (buffer, &start, &end);
++      demo->text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+       gtk_stack_set_visible_child_name (GTK_STACK (demo->stack), "entry");
+       gtk_widget_grab_focus (demo->the_entry);
+       gtk_adjustment_set_value (gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (demo->swin)), 0);
+@@ -1632,7 +1642,7 @@ entry_key_press (GtkEventController *controller,
+ {
+   if (keyval == GDK_KEY_Escape)
+     {
+-      gtk_editable_set_text (GTK_EDITABLE (entry), demo->text);
++      gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (demo->the_entry)), demo->text, -1);
+       return GDK_EVENT_STOP;
+     }
+ 
+@@ -1701,7 +1711,6 @@ do_font_features (GtkWidget *do_widget)
+       basic_value_changed (demo->line_height_adjustment, demo->line_height_entry);
+ 
+       controller = gtk_event_controller_key_new ();
+-      g_object_set_data_full (G_OBJECT (demo->the_entry), "controller", g_object_ref (controller), 
g_object_unref);
+       g_signal_connect (controller, "key-pressed", G_CALLBACK (entry_key_press), demo->the_entry);
+       gtk_widget_add_controller (demo->the_entry, controller);
+ 
diff --git a/demos/gtk-demo/font_features.ui b/demos/gtk-demo/font_features.ui
index b3308f14c0..13985acb11 100644
--- a/demos/gtk-demo/font_features.ui
+++ b/demos/gtk-demo/font_features.ui
@@ -354,9 +354,6 @@
     Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός</property>
                               </object>
                             </property>
-<!--
-                            <signal name="activate" handler="font_features_stop_edit"/>
--->
                             <property name="valign">fill</property>
                           </object>
                         </property>
@@ -367,16 +364,33 @@
               </object>
             </child>
             <child>
-              <object class="GtkLabel" id="settings">
-                <property name="wrap">1</property>
-                <property name="xalign">0</property>
-                <property name="valign">end</property>
-                <property name="width-chars">50</property>
-                <property name="max-width-chars">50</property>
-                <property name="hexpand">1</property>
-                <style>
-                  <class name="monospace"/>
-                </style>
+              <object class="GtkBox">
+                <property name="spacing">10</property>
+                <child>
+                  <object class="GtkLabel" id="settings">
+                    <property name="wrap">1</property>
+                    <property name="xalign">0</property>
+                    <property name="valign">end</property>
+                    <property name="width-chars">50</property>
+                    <property name="max-width-chars">50</property>
+                    <property name="hexpand">1</property>
+                    <style>
+                      <class name="monospace"/>
+                    </style>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="label" translatable="yes">Alphabet</property>
+                    <signal name="clicked" handler="set_text_alphabet"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton">
+                    <property name="label" translatable="yes">Paragraph</property>
+                    <signal name="clicked" handler="set_text_paragraph"/>
+                  </object>
+                </child>
               </object>
             </child>
             <child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]