switch: add a style property for the switch height
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 29 Jun 2015 22:25:44 +0000 (15:25 -0700)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 30 Jun 2015 20:28:26 +0000 (13:28 -0700)
Instead of hardcoding an aspect ratio.
This will be replaced by min-height/max-height when we have them.

https://bugzilla.gnome.org/show_bug.cgi?id=751689

gtk/gtkswitch.c
gtk/theme/Adwaita/_common.scss
gtk/theme/Adwaita/gtk-contained-dark.css
gtk/theme/Adwaita/gtk-contained.css
gtk/theme/HighContrast/_common.scss
gtk/theme/HighContrast/gtk.css

index fbce53684644a55093d20555ee4b35a4b42c184a..a2b10e16fbb8028f2a663c8a268a2455fe171fb3 100644 (file)
@@ -56,6 +56,7 @@
 #include "fallback-c89.c"
 
 #define DEFAULT_SLIDER_WIDTH    (36)
+#define DEFAULT_SLIDER_HEIGHT   (22)
 
 struct _GtkSwitchPrivate
 {
@@ -403,7 +404,7 @@ gtk_switch_get_preferred_height (GtkWidget *widget,
   GtkStyleContext *context;
   GtkStateFlags state;
   GtkBorder padding;
-  gint height, slider_width, min_height;
+  gint height, slider_height;
   PangoLayout *layout;
   PangoRectangle logical_rect;
   gchar *str;
@@ -422,11 +423,9 @@ gtk_switch_get_preferred_height (GtkWidget *widget,
   gtk_style_context_restore (context);
 
   gtk_widget_style_get (widget,
-                        "slider-width", &slider_width,
+                        "slider-height", &slider_height,
                         NULL);
 
-  min_height = slider_width * 0.6;
-
   str = g_strdup_printf ("%s%s",
                          C_("switch", "ON"),
                          C_("switch", "OFF"));
@@ -434,7 +433,7 @@ gtk_switch_get_preferred_height (GtkWidget *widget,
   layout = gtk_widget_create_pango_layout (widget, str);
   pango_layout_get_extents (layout, NULL, &logical_rect);
   pango_extents_to_pixels (&logical_rect, NULL);
-  height += MAX (min_height, logical_rect.height);
+  height += MAX (slider_height, logical_rect.height);
 
   g_object_unref (layout);
   g_free (str);
@@ -929,6 +928,21 @@ gtk_switch_class_init (GtkSwitchClass *klass)
                                                              DEFAULT_SLIDER_WIDTH,
                                                              GTK_PARAM_READABLE));
 
+  /**
+   * GtkSwitch:slider-height:
+   *
+   * The minimum height of the #GtkSwitch handle, in pixels.
+   *
+   * Since: 3.18
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("slider-height",
+                                                             P_("Slider Height"),
+                                                             P_("The minimum height of the handle"),
+                                                             DEFAULT_SLIDER_HEIGHT, G_MAXINT,
+                                                             DEFAULT_SLIDER_HEIGHT,
+                                                             GTK_PARAM_READABLE));
+
   /**
    * GtkSwitch::activate:
    * @widget: the object which received the signal.
index 097f1cd2f117030434271a153be01a370cb4f534..e367672c413255d96d1c022606bb0a506ce373d6 100644 (file)
@@ -1988,6 +1988,8 @@ column-header.button.dnd { // for treeview-like derive widgets
 GtkSwitch {
   -GtkSwitch-slider-width: 45px; // 55px is the right value to make it as tall
                                  // as buttons, not doing that for now
+  -GtkSwitch-slider-height: 27px;
+
   font-weight: bold;
   font-size: smaller;
   outline-offset: -4px;
index 43a114e7e3b08bf310bcb93fa939a869e907c7d0..4e338bb2f0977291c923c77598dbed177852e93f 100644 (file)
@@ -2463,6 +2463,7 @@ column-header .titlebar .button.titlebutton,
  **********/
 GtkSwitch {
   -GtkSwitch-slider-width: 45px;
+  -GtkSwitch-slider-height: 27px;
   font-weight: bold;
   font-size: smaller;
   outline-offset: -4px;
index 03311afb73ccdd99b7e687e55b9a666d8e556461..1d1a1076c53dda0bd7bb340bb92eac764bfcc4e7 100644 (file)
@@ -2469,6 +2469,7 @@ column-header .titlebar .button.titlebutton,
  **********/
 GtkSwitch {
   -GtkSwitch-slider-width: 45px;
+  -GtkSwitch-slider-height: 27px;
   font-weight: bold;
   font-size: smaller;
   outline-offset: -4px;
index a5e86d0a6f6346ba0b73242f4a269e63342bb82b..c7eef9d6be6cdbaf5ecb7ccd23220432b15de670 100644 (file)
@@ -1442,6 +1442,7 @@ GtkTreeView.view.progressbar { //Progressbar in treeview cells
 
 GtkSwitch {
     -GtkSwitch-slider-width: 47px;
+    -GtkSwitch-slider-height: 28px;
     font: bold condensed 9;
     outline-offset: -4px;
     &.trough {
index e5093fd15a583c8b55830a071e467d5dfeb7e506..534a2186dde4bd84c1713c6d64d3f022ec133d70 100644 (file)
@@ -1629,6 +1629,7 @@ GtkTreeView.view.progressbar {
  **********/
 GtkSwitch {
   -GtkSwitch-slider-width: 47px;
+  -GtkSwitch-slider-height: 28px;
   font: bold condensed 9;
   outline-offset: -4px; }
   GtkSwitch.trough {