[gtk+] switch: add a style property for the switch height



commit 9913b02e3bf81fe620a750c15fbcd2f154e53e4d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 29 15:25:44 2015 -0700

    switch: add a style property for the switch height
    
    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                          |   24 +++++++++++++++++++-----
 gtk/theme/Adwaita/_common.scss           |    2 ++
 gtk/theme/Adwaita/gtk-contained-dark.css |    1 +
 gtk/theme/Adwaita/gtk-contained.css      |    1 +
 gtk/theme/HighContrast/_common.scss      |    1 +
 gtk/theme/HighContrast/gtk.css           |    1 +
 6 files changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c
index fbce536..a2b10e1 100644
--- a/gtk/gtkswitch.c
+++ b/gtk/gtkswitch.c
@@ -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);
@@ -930,6 +929,21 @@ gtk_switch_class_init (GtkSwitchClass *klass)
                                                              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.
    *
diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss
index 097f1cd..e367672 100644
--- a/gtk/theme/Adwaita/_common.scss
+++ b/gtk/theme/Adwaita/_common.scss
@@ -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;
diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css
index 43a114e..4e338bb 100644
--- a/gtk/theme/Adwaita/gtk-contained-dark.css
+++ b/gtk/theme/Adwaita/gtk-contained-dark.css
@@ -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;
diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css
index 03311af..1d1a107 100644
--- a/gtk/theme/Adwaita/gtk-contained.css
+++ b/gtk/theme/Adwaita/gtk-contained.css
@@ -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;
diff --git a/gtk/theme/HighContrast/_common.scss b/gtk/theme/HighContrast/_common.scss
index a5e86d0..c7eef9d 100644
--- a/gtk/theme/HighContrast/_common.scss
+++ b/gtk/theme/HighContrast/_common.scss
@@ -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 {
diff --git a/gtk/theme/HighContrast/gtk.css b/gtk/theme/HighContrast/gtk.css
index e5093fd..534a218 100644
--- a/gtk/theme/HighContrast/gtk.css
+++ b/gtk/theme/HighContrast/gtk.css
@@ -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 {


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