From d1c5ecfaefd045bdf4b46e12520899a7bd27002d Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sun, 21 Feb 2016 15:01:04 -0800 Subject: [PATCH] scale: deprecate slider-length style property This can be achieved using min-height/min-width CSS properties now. --- gtk/gtkrange.c | 6 ++++ gtk/gtkrangeprivate.h | 2 ++ gtk/gtkscale.c | 40 ++++++++++++++++-------- gtk/theme/Adwaita/_common.scss | 4 +-- gtk/theme/Adwaita/gtk-contained-dark.css | 5 +-- gtk/theme/Adwaita/gtk-contained.css | 5 +-- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c index 449e489f45..1ce190b137 100644 --- a/gtk/gtkrange.c +++ b/gtk/gtkrange.c @@ -3995,3 +3995,9 @@ gtk_range_get_trough_node (GtkRange *range) { return gtk_css_gadget_get_node (range->priv->trough_gadget); } + +GtkCssGadget * +gtk_range_get_slider_gadget (GtkRange *range) +{ + return range->priv->slider_gadget; +} diff --git a/gtk/gtkrangeprivate.h b/gtk/gtkrangeprivate.h index 1ce5219e5f..0b0a875cd2 100644 --- a/gtk/gtkrangeprivate.h +++ b/gtk/gtkrangeprivate.h @@ -27,6 +27,7 @@ #include +#include #include @@ -49,6 +50,7 @@ void _gtk_range_set_steppers (GtkRange *range gboolean has_d); GtkCssNode *gtk_range_get_trough_node (GtkRange *range); +GtkCssGadget *gtk_range_get_slider_gadget (GtkRange *range); G_END_DECLS diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 364b27f4c2..32e068505c 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -268,12 +268,14 @@ gtk_scale_update_style (GtkScale *scale) { gint slider_length; GtkRange *range; + GtkCssGadget *slider_gadget; range = GTK_RANGE (scale); - - gtk_widget_style_get (GTK_WIDGET (scale), - "slider-length", &slider_length, - NULL); + slider_gadget = gtk_range_get_slider_gadget (range); + gtk_css_gadget_get_preferred_size (slider_gadget, + gtk_orientable_get_orientation (GTK_ORIENTABLE (scale)), -1, + &slider_length, NULL, + NULL, NULL); gtk_range_set_min_slider_size (range, slider_length); gtk_scale_clear_layout (scale); @@ -376,12 +378,20 @@ gtk_scale_class_init (GtkScaleClass *class) g_object_class_install_properties (gobject_class, LAST_PROP, properties); + /** + * GtkScale:slider-length: + * + * Length of scale's slider. + * + * Deprecated: 3.20: Use min-height/min-width CSS properties on the slider + * element instead. The value of this style property is ignored. + */ gtk_widget_class_install_style_property (widget_class, g_param_spec_int ("slider-length", P_("Slider Length"), P_("Length of scale's slider"), 0, G_MAXINT, 31, - GTK_PARAM_READABLE)); + GTK_PARAM_READABLE|G_PARAM_DEPRECATED)); gtk_widget_class_install_style_property (widget_class, g_param_spec_int ("value-spacing", @@ -1086,7 +1096,7 @@ gtk_scale_get_preferred_width (GtkWidget *widget, gint slider_length; gint w; - gtk_widget_style_get (widget, "slider-length", &slider_length, NULL); + slider_length = gtk_range_get_min_slider_size (GTK_RANGE (widget)); gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2); @@ -1113,7 +1123,7 @@ gtk_scale_get_preferred_height (GtkWidget *widget, gint slider_length; gint h; - gtk_widget_style_get (widget, "slider-length", &slider_length, NULL); + slider_length = gtk_range_get_min_slider_size (GTK_RANGE (widget)); gtk_scale_get_mark_label_size (GTK_SCALE (widget), GTK_POS_TOP, &n1, &w1, &h1, &n2, &w2, &h2); h1 = (n1 - 1) * h1 + MAX (h1, slider_length); @@ -1159,13 +1169,17 @@ gtk_scale_draw (GtkWidget *widget, GtkRange *range = GTK_RANGE (scale); GtkStyleContext *context; gint *marks; - gint slider_width; gint value_spacing; gint min_sep = 4; + GtkCssGadget *slider_gadget; + GtkAllocation slider_alloc; context = gtk_widget_get_style_context (widget); + slider_gadget = gtk_range_get_slider_gadget (range); + gtk_css_gadget_get_content_allocation (slider_gadget, + &slider_alloc, NULL); + gtk_widget_style_get (widget, - "slider-width", &slider_width, "value-spacing", &value_spacing, NULL); @@ -1200,14 +1214,14 @@ gtk_scale_draw (GtkWidget *widget, x1 = marks[i]; if (mark->position == GTK_POS_TOP) { - y1 = range_rect.y + slider_width / 4; + y1 = range_rect.y + slider_alloc.height / 4; y2 = range_rect.y; min_pos = min_pos_before; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep; } else { - y1 = range_rect.y + range_rect.height - slider_width / 4; + y1 = range_rect.y + slider_alloc.height / 4; y2 = range_rect.y + range_rect.height; min_pos = min_pos_after; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep; @@ -1245,14 +1259,14 @@ gtk_scale_draw (GtkWidget *widget, { if (mark->position == GTK_POS_TOP) { - x1 = range_rect.x + slider_width / 4; + x1 = range_rect.x + slider_alloc.width / 4; x2 = range_rect.x; min_pos = min_pos_before; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_TOP) - min_sep; } else { - x1 = range_rect.x + range_rect.width - slider_width / 4; + x1 = range_rect.x + slider_alloc.width / 4; x2 = range_rect.x + range_rect.width; min_pos = min_pos_after; max_pos = find_next_pos (widget, m, marks + i, GTK_POS_BOTTOM) - min_sep; diff --git a/gtk/theme/Adwaita/_common.scss b/gtk/theme/Adwaita/_common.scss index 71d2a8abb6..2b3123465c 100644 --- a/gtk/theme/Adwaita/_common.scss +++ b/gtk/theme/Adwaita/_common.scss @@ -2483,8 +2483,6 @@ treeview.view radio { } scale { - -GtkScale-slider-length: 22; - outline-offset: -10px; -gtk-outline-radius: 7px; @@ -2496,6 +2494,7 @@ scale { slider { margin: 5px 1px; min-height: 22px; + min-width: 22px; } } @@ -2506,6 +2505,7 @@ scale { } slider { margin: 1px 5px; + min-height: 22px; min-width: 22px; } } diff --git a/gtk/theme/Adwaita/gtk-contained-dark.css b/gtk/theme/Adwaita/gtk-contained-dark.css index ed692598a9..2f9cf21fac 100644 --- a/gtk/theme/Adwaita/gtk-contained-dark.css +++ b/gtk/theme/Adwaita/gtk-contained-dark.css @@ -2645,7 +2645,6 @@ scale highlight, progressbar progress { border-color: transparent; } scale { - -GtkScale-slider-length: 22; outline-offset: -10px; -gtk-outline-radius: 7px; } scale.horizontal trough { @@ -2653,12 +2652,14 @@ scale { min-height: 3px; } scale.horizontal slider { margin: 5px 1px; - min-height: 22px; } + min-height: 22px; + min-width: 22px; } scale.vertical trough { margin: 12px 15px; min-width: 3px; } scale.vertical slider { margin: 1px 5px; + min-height: 22px; min-width: 22px; } scale.fine-tune { outline-offset: -8px; diff --git a/gtk/theme/Adwaita/gtk-contained.css b/gtk/theme/Adwaita/gtk-contained.css index d11d598ddb..7f9c287df4 100644 --- a/gtk/theme/Adwaita/gtk-contained.css +++ b/gtk/theme/Adwaita/gtk-contained.css @@ -2676,7 +2676,6 @@ scale highlight, progressbar progress { border-color: transparent; } scale { - -GtkScale-slider-length: 22; outline-offset: -10px; -gtk-outline-radius: 7px; } scale.horizontal trough { @@ -2684,12 +2683,14 @@ scale { min-height: 3px; } scale.horizontal slider { margin: 5px 1px; - min-height: 22px; } + min-height: 22px; + min-width: 22px; } scale.vertical trough { margin: 12px 15px; min-width: 3px; } scale.vertical slider { margin: 1px 5px; + min-height: 22px; min-width: 22px; } scale.fine-tune { outline-offset: -8px;