mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-06 00:30:08 +00:00
GtkScale: Add style classes for marks
This enables better styling of the slider in the presence of marks. Based on a patch by Bastien Nocera, https://bugzilla.gnome.org/show_bug.cgi?id=643685
This commit is contained in:
parent
2a9d130ed2
commit
77e46de0e1
@ -77,7 +77,6 @@
|
||||
* unrelated code portions otherwise
|
||||
*/
|
||||
|
||||
|
||||
typedef struct _GtkScaleMark GtkScaleMark;
|
||||
|
||||
struct _GtkScalePrivate
|
||||
@ -1459,6 +1458,7 @@ void
|
||||
gtk_scale_clear_marks (GtkScale *scale)
|
||||
{
|
||||
GtkScalePrivate *priv;
|
||||
GtkStyleContext *context;
|
||||
|
||||
g_return_if_fail (GTK_IS_SCALE (scale));
|
||||
|
||||
@ -1468,6 +1468,10 @@ gtk_scale_clear_marks (GtkScale *scale)
|
||||
g_slist_free (priv->marks);
|
||||
priv->marks = NULL;
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (scale));
|
||||
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
|
||||
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
|
||||
|
||||
_gtk_range_set_stop_values (GTK_RANGE (scale), NULL, 0);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (scale));
|
||||
@ -1518,6 +1522,8 @@ gtk_scale_add_mark (GtkScale *scale,
|
||||
GSList *m;
|
||||
gdouble *values;
|
||||
gint n, i;
|
||||
GtkStyleContext *context;
|
||||
int all_pos;
|
||||
|
||||
g_return_if_fail (GTK_IS_SCALE (scale));
|
||||
|
||||
@ -1535,18 +1541,40 @@ gtk_scale_add_mark (GtkScale *scale,
|
||||
priv->marks = g_slist_insert_sorted (priv->marks, mark,
|
||||
(GCompareFunc) compare_marks);
|
||||
|
||||
#define MARKS_ABOVE 1
|
||||
#define MARKS_BELOW 2
|
||||
|
||||
all_pos = 0;
|
||||
n = g_slist_length (priv->marks);
|
||||
values = g_new (gdouble, n);
|
||||
for (m = priv->marks, i = 0; m; m = m->next, i++)
|
||||
{
|
||||
mark = m->data;
|
||||
values[i] = mark->value;
|
||||
if (mark->position == GTK_POS_TOP)
|
||||
all_pos |= MARKS_ABOVE;
|
||||
else
|
||||
all_pos |= MARKS_BELOW;
|
||||
}
|
||||
|
||||
_gtk_range_set_stop_values (GTK_RANGE (scale), values, n);
|
||||
|
||||
g_free (values);
|
||||
|
||||
/* Set the style classes for the slider, so it could
|
||||
* point to the right direction when marks are present
|
||||
*/
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (scale));
|
||||
|
||||
if (all_pos & MARKS_ABOVE)
|
||||
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
|
||||
else
|
||||
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE);
|
||||
if (all_pos & MARKS_BELOW)
|
||||
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
|
||||
else
|
||||
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (scale));
|
||||
}
|
||||
|
||||
|
@ -276,6 +276,24 @@ struct _GtkStyleContextClass
|
||||
*/
|
||||
#define GTK_STYLE_CLASS_SCALE "scale"
|
||||
|
||||
/**
|
||||
* GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE:
|
||||
*
|
||||
* A CSS class to match scale widgets with marks attached,
|
||||
* all the marks are above for horizontal #GtkScale.
|
||||
* left for vertical #GtkScale.
|
||||
*/
|
||||
#define GTK_STYLE_CLASS_SCALE_HAS_MARKS_ABOVE "scale-has-marks-above"
|
||||
|
||||
/**
|
||||
* GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW:
|
||||
*
|
||||
* A CSS class to match scale widgets with marks attached,
|
||||
* all the marks are below for horizontal #GtkScale,
|
||||
* right for vertical #GtkScale.
|
||||
*/
|
||||
#define GTK_STYLE_CLASS_SCALE_HAS_MARKS_BELOW "scale-has-marks-below"
|
||||
|
||||
/**
|
||||
* GTK_STYLE_CLASS_HEADER:
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user