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
This commit is contained in:
Cosimo Cecchi 2015-06-29 15:25:44 -07:00
parent 6251b7bdb2
commit 9913b02e3b
6 changed files with 25 additions and 5 deletions

View 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.

View 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;

View 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;

View 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;

View 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 {

View 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 {