[gtk] inspector: Make rows activatable



commit 838b25177f54d2d8aabb4ec2a125d38513cd8488
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 11 22:06:16 2019 -0400

    inspector: Make rows activatable
    
    Rows containing just a switch should be activatable,
    and toggle the switch.

 gtk/inspector/visual.c  | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/inspector/visual.ui | 29 +++++++++++-----------
 2 files changed, 80 insertions(+), 14 deletions(-)
---
diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c
index 7abd300098..ce8f1dbe73 100644
--- a/gtk/inspector/visual.c
+++ b/gtk/inspector/visual.c
@@ -70,6 +70,11 @@ struct _GtkInspectorVisualPrivate
   GtkAdjustment *cursor_size_adjustment;
 
   GtkWidget *debug_box;
+  GtkWidget *fps_switch;
+  GtkWidget *updates_switch;
+  GtkWidget *baselines_switch;
+  GtkWidget *layout_switch;
+  GtkWidget *resize_switch;
 
   GtkWidget *misc_box;
   GtkWidget *touchscreen_switch;
@@ -839,6 +844,58 @@ keynav_failed (GtkWidget *widget, GtkDirectionType direction, GtkInspectorVisual
   return FALSE;
 }
 
+static void
+row_activated (GtkListBox         *box,
+               GtkListBoxRow      *row,
+               GtkInspectorVisual *vis)
+{
+  if (gtk_widget_is_ancestor (vis->priv->dark_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->dark_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->animation_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->animation_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->fps_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->fps_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->updates_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->updates_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->baselines_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->baselines_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->layout_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->layout_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->resize_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->resize_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->touchscreen_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->touchscreen_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+  else if (gtk_widget_is_ancestor (vis->priv->software_gl_switch, GTK_WIDGET (row)))
+    {
+      GtkSwitch *sw = GTK_SWITCH (vis->priv->software_gl_switch);
+      gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
+    }
+}
+
 static void
 init_gl (GtkInspectorVisual *vis)
 {
@@ -910,6 +967,9 @@ gtk_inspector_visual_constructed (GObject *object)
    g_signal_connect (vis->priv->visual_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
    g_signal_connect (vis->priv->debug_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
    g_signal_connect (vis->priv->misc_box, "keynav-failed", G_CALLBACK (keynav_failed), vis);
+   g_signal_connect (vis->priv->visual_box, "row-activated", G_CALLBACK (row_activated), vis);
+   g_signal_connect (vis->priv->debug_box, "row-activated", G_CALLBACK (row_activated), vis);
+   g_signal_connect (vis->priv->misc_box, "row-activated", G_CALLBACK (row_activated), vis);
 }
 
 static void
@@ -958,6 +1018,11 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, software_gl_switch);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, font_scale_entry);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, font_scale_adjustment);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, fps_switch);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, updates_switch);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, baselines_switch);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, layout_switch);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorVisual, resize_switch);
 
   gtk_widget_class_bind_template_callback (widget_class, fps_activate);
   gtk_widget_class_bind_template_callback (widget_class, updates_activate);
diff --git a/gtk/inspector/visual.ui b/gtk/inspector/visual.ui
index d86682a63d..c50163e353 100644
--- a/gtk/inspector/visual.ui
+++ b/gtk/inspector/visual.ui
@@ -67,7 +67,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -298,7 +298,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -373,7 +373,7 @@
                 <property name="selection-mode">none</property>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -400,7 +400,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -414,7 +414,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkSwitch">
+                          <object class="GtkSwitch" id="updates_switch">
                             <property name="halign">end</property>
                             <property name="valign">baseline</property>
                             <property name="hexpand">1</property>
@@ -427,7 +427,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -441,7 +441,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkSwitch">
+                          <object class="GtkSwitch" id="baselines_switch">
                             <property name="halign">end</property>
                             <property name="valign">baseline</property>
                             <property name="hexpand">1</property>
@@ -454,7 +454,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -468,7 +468,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkSwitch">
+                          <object class="GtkSwitch" id="layout_switch">
                             <property name="halign">end</property>
                             <property name="valign">baseline</property>
                             <property name="hexpand">1</property>
@@ -481,13 +481,13 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
                         <property name="spacing">40</property>
                         <child>
-                          <object class="GtkLabel">
+                          <object class="GtkLabel" id="resize_label">
                             <property name="label" translatable="yes">Show Widget Resizes</property>
                             <property name="halign">start</property>
                             <property name="valign">baseline</property>
@@ -495,7 +495,7 @@
                           </object>
                         </child>
                         <child>
-                          <object class="GtkSwitch" id="widget_resize_switch">
+                          <object class="GtkSwitch" id="resize_switch">
                             <property name="halign">end</property>
                             <property name="valign">baseline</property>
                             <property name="hexpand">1</property>
@@ -518,7 +518,7 @@
                 <property name="selection-mode">none</property>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -544,7 +544,7 @@
                 </child>
                 <child>
                   <object class="GtkListBoxRow">
-                    <property name="activatable">0</property>
+                    <property name="activatable">1</property>
                     <child>
                       <object class="GtkBox">
                         <property name="margin">10</property>
@@ -590,6 +590,7 @@
       <widget name="updates_label"/>
       <widget name="baselines_label"/>
       <widget name="layout_label"/>
+      <widget name="resize_label"/>
       <widget name="touchscreen_label"/>
       <widget name="software_gl_label"/>
     </widgets>


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