[gtk+/wip/matthiasc/font-variations: 12/13] gtk-demo: Revise the font features demo a bit
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/font-variations: 12/13] gtk-demo: Revise the font features demo a bit
- Date: Sun, 31 Dec 2017 02:50:10 +0000 (UTC)
commit 5625155755b46720e6dad7f949f43620595a2725
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Dec 30 09:02:47 2017 -0500
gtk-demo: Revise the font features demo a bit
Add an edit button. Clicking on the label is not very
obvious, and we want to make the label selectable in
the future.
demos/gtk-demo/font-features.ui | 30 ++++++++++++++++--------------
demos/gtk-demo/font_features.c | 24 +++++++++++++++++++++---
2 files changed, 37 insertions(+), 17 deletions(-)
---
diff --git a/demos/gtk-demo/font-features.ui b/demos/gtk-demo/font-features.ui
index 0c0cfc8..6ddd98f 100644
--- a/demos/gtk-demo/font-features.ui
+++ b/demos/gtk-demo/font-features.ui
@@ -120,13 +120,13 @@
<object class="GtkBox">
<property name="visible">1</property>
<property name="orientation">vertical</property>
+ <property name="hexpand">1</property>
+ <property name="vexpand">1</property>
+ <property name="margin">20</property>
+ <property name="spacing">20</property>
<child>
<object class="GtkStack" id="stack">
<property name="visible">1</property>
- <property name="margin-start">20</property>
- <property name="margin-end">20</property>
- <property name="margin-top">20</property>
- <property name="margin-bottom">20</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">1</property>
@@ -134,7 +134,6 @@
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="valign">start</property>
- <signal name="button-press-event" handler="switch_to_entry"/>
</object>
<packing>
<property name="name">label</property>
@@ -149,7 +148,7 @@
Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός</property>
<signal name="key-press-event" handler="entry_key_press"/>
- <signal name="activate" handler="switch_to_label"/>
+ <signal name="activate" handler="stop_edit"/>
<property name="valign">start</property>
<property name="width-chars">50</property>
</object>
@@ -163,9 +162,6 @@
<object class="GtkLabel" id="settings">
<property name="visible">1</property>
<property name="wrap">1</property>
- <property name="margin-start">20</property>
- <property name="margin-end">20</property>
- <property name="margin-bottom">20</property>
<property name="xalign">0</property>
<property name="valign">end</property>
<property name="width-chars">50</property>
@@ -178,12 +174,12 @@
</object>
</child>
<child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <child>
<object class="GtkLabel" id="description">
<property name="visible">1</property>
<property name="wrap">1</property>
- <property name="margin-start">20</property>
- <property name="margin-end">20</property>
- <property name="margin-bottom">20</property>
<property name="xalign">0</property>
<property name="valign">end</property>
<property name="width-chars">50</property>
@@ -194,8 +190,14 @@
</style>
</object>
</child>
- <property name="hexpand">1</property>
- <property name="vexpand">1</property>
+ <child>
+ <object class="GtkToggleButton" id="edit_toggle">
+ <property name="icon-name">document-edit-symbolic</property>
+ <signal name="toggled" handler="toggle_edit"/>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 56450f6..9b70f60 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -40,6 +40,7 @@ static GtkWidget *entry;
static GtkWidget *variations_heading;
static GtkWidget *variations_grid;
static GtkWidget *instance_combo;
+static GtkWidget *edit_toggle;
typedef struct {
unsigned int tag;
@@ -1512,6 +1513,7 @@ switch_to_entry (void)
{
text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
gtk_stack_set_visible_child_name (GTK_STACK (stack), "entry");
+ gtk_widget_grab_focus (entry);
}
static void
@@ -1523,6 +1525,21 @@ switch_to_label (void)
update_display ();
}
+static void
+toggle_edit (void)
+{
+ if (strcmp (gtk_stack_get_visible_child_name (GTK_STACK (stack)), "label") == 0)
+ switch_to_entry ();
+ else
+ switch_to_label ();
+}
+
+static void
+stop_edit (void)
+{
+ gtk_button_clicked (GTK_BUTTON (edit_toggle));
+}
+
static gboolean
entry_key_press (GtkEntry *entry, GdkEventKey *event)
{
@@ -1533,7 +1550,7 @@ entry_key_press (GtkEntry *entry, GdkEventKey *event)
if (keyval == GDK_KEY_Escape)
{
gtk_entry_set_text (GTK_ENTRY (entry), text);
- switch_to_label ();
+ stop_edit ();
return GDK_EVENT_STOP;
}
@@ -1556,8 +1573,8 @@ do_font_features (GtkWidget *do_widget)
gtk_builder_add_callback_symbol (builder, "font_changed", font_changed);
gtk_builder_add_callback_symbol (builder, "script_changed", script_changed);
gtk_builder_add_callback_symbol (builder, "reset", reset_features);
- gtk_builder_add_callback_symbol (builder, "switch_to_entry", switch_to_entry);
- gtk_builder_add_callback_symbol (builder, "switch_to_label", switch_to_label);
+ gtk_builder_add_callback_symbol (builder, "stop_edit", G_CALLBACK (stop_edit));
+ gtk_builder_add_callback_symbol (builder, "toggle_edit", G_CALLBACK (toggle_edit));
gtk_builder_add_callback_symbol (builder, "entry_key_press", G_CALLBACK (entry_key_press));
gtk_builder_connect_signals (builder, NULL);
@@ -1571,6 +1588,7 @@ do_font_features (GtkWidget *do_widget)
script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang"));
stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
+ edit_toggle = GTK_WIDGET (gtk_builder_get_object (builder, "edit_toggle"));
add_check_group (feature_list, _("Kerning"), (const char *[]){ "kern", NULL });
add_check_group (feature_list, _("Ligatures"), (const char *[]){ "liga",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]