[gtk/fontconfig-speedup: 1/3] widget-factory: Improve the error states example
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/fontconfig-speedup: 1/3] widget-factory: Improve the error states example
- Date: Wed, 19 Aug 2020 18:22:34 +0000 (UTC)
commit 8acd60fda9948f5429f7aa6e46ee1dc7ecf3e047
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 15 08:26:28 2020 -0400
widget-factory: Improve the error states example
Elaborate the error state handling, and make it show
delayed states in GtkSwitch too.
demos/widget-factory/widget-factory.c | 51 ++++++++++++++++++++++++++++++++++
demos/widget-factory/widget-factory.ui | 7 +++--
2 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 0b17ed05d4..48329d4018 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -1896,6 +1896,48 @@ validate_more_details (GtkEntry *entry,
}
}
+static gboolean
+mode_switch_state_set (GtkSwitch *sw, gboolean state)
+{
+ GtkWidget *dialog = gtk_widget_get_ancestor (GTK_WIDGET (sw), GTK_TYPE_DIALOG);
+ GtkWidget *scale = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "level_scale"));
+ GtkWidget *label = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "error_label"));
+
+ if (!state ||
+ (gtk_range_get_value (GTK_RANGE (scale)) > 50))
+ {
+ gtk_widget_hide (label);
+ gtk_switch_set_state (sw, state);
+ }
+ else
+ {
+ gtk_widget_show (label);
+ }
+
+ return TRUE;
+}
+
+static void
+level_scale_value_changed (GtkRange *range)
+{
+ GtkWidget *dialog = gtk_widget_get_ancestor (GTK_WIDGET (range), GTK_TYPE_DIALOG);
+ GtkWidget *sw = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "mode_switch"));
+ GtkWidget *label = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "error_label"));
+
+ if (gtk_switch_get_active (GTK_SWITCH (sw)) &&
+ !gtk_switch_get_state (GTK_SWITCH (sw)) &&
+ (gtk_range_get_value (range) > 50))
+ {
+ gtk_widget_hide (label);
+ gtk_switch_set_state (GTK_SWITCH (sw), TRUE);
+ }
+ else if (gtk_switch_get_state (GTK_SWITCH (sw)) &&
+ (gtk_range_get_value (range) <= 50))
+ {
+ gtk_switch_set_state (GTK_SWITCH (sw), FALSE);
+ }
+}
+
static void
activate (GApplication *app)
{
@@ -1978,6 +2020,8 @@ activate (GApplication *app)
"osd_frame_pressed", (GCallback)osd_frame_pressed,
"age_entry_changed", (GCallback)age_entry_changed,
"validate_more_details", (GCallback)validate_more_details,
+ "mode_switch_state_set", (GCallback)mode_switch_state_set,
+ "level_scale_value_changed", (GCallback)level_scale_value_changed,
NULL);
gtk_builder_set_scope (builder, scope);
g_object_unref (scope);
@@ -2101,6 +2145,13 @@ activate (GApplication *app)
widget = (GtkWidget *)gtk_builder_get_object (builder, "circular_button");
g_signal_connect (widget, "clicked", G_CALLBACK (show_dialog), dialog);
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "level_scale");
+ g_object_set_data (G_OBJECT (dialog), "level_scale", widget);
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "mode_switch");
+ g_object_set_data (G_OBJECT (dialog), "mode_switch", widget);
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "error_label");
+ g_object_set_data (G_OBJECT (dialog), "error_label", widget);
+
dialog = (GtkWidget *)gtk_builder_get_object (builder, "selection_dialog");
g_object_set_data (G_OBJECT (window), "selection_dialog", dialog);
widget = (GtkWidget *)gtk_builder_get_object (builder, "text3");
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index fccbb520d9..b77fa7b2ca 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -3078,6 +3078,7 @@ bad things might happen.</property>
<property name="valign">baseline</property>
<property name="draw-value">0</property>
<property name="adjustment">adjustment1</property>
+ <signal name="value-changed" handler="level_scale_value_changed"/>
<layout>
<property name="column">1</property>
<property name="row">2</property>
@@ -3105,6 +3106,7 @@ bad things might happen.</property>
<object class="GtkSwitch" id="mode_switch">
<property name="halign">start</property>
<property name="valign">baseline</property>
+ <signal name="state-set" handler="mode_switch_state_set"/>
<layout>
<property name="column">1</property>
<property name="row">3</property>
@@ -3112,12 +3114,11 @@ bad things might happen.</property>
</object>
</child>
<child>
- <object class="GtkLabel" id="switch_error">
+ <object class="GtkLabel" id="error_label">
<property name="visible">0</property>
<property name="halign">start</property>
<property name="valign">baseline</property>
- <property name="label">Error!</property>
- <property name="visible" bind-source="mode_switch" bind-property="active"></property>
+ <property name="label">Level too low</property>
<style>
<class name="error"/>
</style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]