[gtk+/gtk-3-22] testframe: Actually set the padding



commit ec30a03153adc4d86b02b7b995210b354b258b9e
Author: Daniel Boles <dboles src gnome org>
Date:   Mon Mar 6 23:44:07 2017 +0000

    testframe: Actually set the padding
    
    The CSS was targeting node GtkFrame, which is wrong: it is called frame.
    
    This commit also assumes the interesting padding is that between the
    border and the child widget, not the padding around the entire Frame.
    Some additional hoops must be jumped through to preserve padding values
    not being changed in either callback. However, the way this is done
    means I must set the initial paddings to 0, which simplifies main().

 tests/testframe.c |   28 ++++++++++------------------
 1 files changed, 10 insertions(+), 18 deletions(-)
---
diff --git a/tests/testframe.c b/tests/testframe.c
index 4f336ef..b0343b3 100644
--- a/tests/testframe.c
+++ b/tests/testframe.c
@@ -18,6 +18,8 @@
 #include <gtk/gtk.h>
 #include <math.h>
 
+static gint hpadding = 0, vpadding = 0;
+
 static void
 spin_hpadding_cb (GtkSpinButton *spin, gpointer user_data)
 {
@@ -43,10 +45,9 @@ spin_hpadding_cb (GtkSpinButton *spin, gpointer user_data)
   gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &pad);
   gtk_style_context_restore (context);
 
-
-  data = g_strdup_printf ("GtkFrame { padding: %dpx %dpx }",
-                          pad.top,
-                          (gint)gtk_spin_button_get_value (spin));
+  hpadding = (gint)gtk_spin_button_get_value (spin);
+  data = g_strdup_printf ("frame > border { padding: %dpx %dpx %dpx %dpx }",
+                          vpadding, hpadding, vpadding, hpadding);
 
   gtk_css_provider_load_from_data (provider, data, -1, NULL);
   g_free (data);
@@ -79,10 +80,9 @@ spin_vpadding_cb (GtkSpinButton *spin, gpointer user_data)
   gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &pad);
   gtk_style_context_restore (context);
 
-
-  data = g_strdup_printf ("GtkFrame { padding: %dpx %dpx }",
-                          (gint)gtk_spin_button_get_value (spin),
-                          pad.left);
+  vpadding = (gint)gtk_spin_button_get_value (spin);
+  data = g_strdup_printf ("frame > border { padding: %dpx %dpx %dpx %dpx }",
+                          vpadding, hpadding, vpadding, hpadding);
 
   gtk_css_provider_load_from_data (provider, data, -1, NULL);
   g_free (data);
@@ -139,8 +139,6 @@ draw_border_cb (GtkToggleButton *toggle_button, GtkFrame *frame)
 
 int main (int argc, char **argv)
 {
-  GtkStyleContext *context;
-  GtkBorder pad;
   GtkWidget *window, *widget;
   GtkBox *vbox;
   GtkFrame *frame;
@@ -171,12 +169,6 @@ int main (int argc, char **argv)
   gtk_grid_set_column_spacing (grid, 6);
   gtk_box_pack_start (vbox, GTK_WIDGET (grid), FALSE, FALSE, 0);
 
-  context = gtk_widget_get_style_context (GTK_WIDGET (frame));
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
-  gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &pad);
-  gtk_style_context_restore (context);
-
   gtk_frame_get_label_align (frame, &xalign, &yalign);
 
   /* Spin to control :label-xalign */
@@ -202,8 +194,8 @@ int main (int argc, char **argv)
   gtk_grid_attach (grid, widget, 0, 2, 1, 1);
 
   widget = gtk_spin_button_new_with_range (0, 250, 1);
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), pad.top);
   g_signal_connect (widget, "value-changed", G_CALLBACK (spin_vpadding_cb), frame);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), vpadding);
   gtk_grid_attach (grid, widget, 1, 2, 1, 1);
 
   /* Spin to control horizontal padding */
@@ -211,8 +203,8 @@ int main (int argc, char **argv)
   gtk_grid_attach (grid, widget, 0, 3, 1, 1);
 
   widget = gtk_spin_button_new_with_range (0, 250, 1);
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), pad.left);
   g_signal_connect (widget, "value-changed", G_CALLBACK (spin_hpadding_cb), frame);
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), hpadding);
   gtk_grid_attach (grid, widget, 1, 3, 1, 1);
 
   /* CheckButton to control whether to draw border */


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