scale: Rearrange child widgets

Always keep the order:

 - [value]
 - [marks.top]
 - [marks.bottom]
 - trough

Which makes sense given the rendering order. Slider should be drawn
after the marks.

Makes it possible to simply remove the custom snapshot implementations
in scale and range. And Adwaita does not depend on the node order
anyway.
This commit is contained in:
Timm Bäder 2020-06-26 08:00:04 +02:00
parent c41b4130c6
commit 20935f678b
3 changed files with 20 additions and 61 deletions

View File

@ -250,16 +250,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkRange, gtk_range, GTK_TYPE_WIDGET,
static guint signals[LAST_SIGNAL];
static GParamSpec *properties[LAST_PROP];
static void
gtk_range_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkRange *range = GTK_RANGE (widget);
GtkRangePrivate *priv = gtk_range_get_instance_private (range);
gtk_widget_snapshot_child (widget, priv->trough_widget, snapshot);
}
static void
gtk_range_class_init (GtkRangeClass *class)
{
@ -275,7 +265,6 @@ gtk_range_class_init (GtkRangeClass *class)
gobject_class->dispose = gtk_range_dispose;
widget_class->measure = gtk_range_measure;
widget_class->snapshot = gtk_range_snapshot;
widget_class->size_allocate = gtk_range_size_allocate;
widget_class->unmap = gtk_range_unmap;
widget_class->direction_changed = gtk_range_direction_changed;

View File

@ -79,22 +79,23 @@
*
* |[<!-- language="plain" -->
* scale[.fine-tune][.marks-before][.marks-after]
* [value][.top][.right][.bottom][.left]
* marks.top
* mark
* [label]
* indicator
*
* mark
* [value][.top][.right][.bottom][.left]
* trough
* [fill]
* [highlight]
* slider
* marks.bottom
* mark
* indicator
* [label]
* mark
* marks.bottom
* mark
* indicator
* [label]
*
* mark
* trough
* [fill]
* [highlight]
* slider
* ]|
*
* GtkScale has a main CSS node with name scale and a subnode for its contents,
@ -197,8 +198,6 @@ static void gtk_scale_measure (GtkWidget *widget,
static void gtk_scale_get_range_border (GtkRange *range,
GtkBorder *border);
static void gtk_scale_finalize (GObject *object);
static void gtk_scale_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
static void gtk_scale_real_get_layout_offsets (GtkScale *scale,
gint *x,
gint *y);
@ -661,7 +660,6 @@ gtk_scale_class_init (GtkScaleClass *class)
gobject_class->notify = gtk_scale_notify;
gobject_class->finalize = gtk_scale_finalize;
widget_class->snapshot = gtk_scale_snapshot;
widget_class->size_allocate = gtk_scale_size_allocate;
widget_class->measure = gtk_scale_measure;
widget_class->grab_focus = gtk_widget_grab_focus_self;
@ -1093,14 +1091,9 @@ gtk_scale_set_draw_value (GtkScale *scale,
"css-name", "value",
"label", txt,
NULL);
g_free (txt);
if (priv->value_pos == GTK_POS_TOP || priv->value_pos == GTK_POS_LEFT)
gtk_widget_insert_after (priv->value_widget, GTK_WIDGET (scale), NULL);
else
gtk_widget_insert_before (priv->value_widget, GTK_WIDGET (scale), NULL);
gtk_widget_insert_after (priv->value_widget, GTK_WIDGET (scale), NULL);
gtk_range_set_round_digits (GTK_RANGE (scale), priv->digits);
update_value_position (scale);
update_label_request (scale);
@ -1469,25 +1462,6 @@ gtk_scale_measure (GtkWidget *widget,
}
}
static void
gtk_scale_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkScale *scale = GTK_SCALE (widget);
GtkScalePrivate *priv = gtk_scale_get_instance_private (scale);
if (priv->top_marks_widget)
gtk_widget_snapshot_child (widget, priv->top_marks_widget, snapshot);
if (priv->bottom_marks_widget)
gtk_widget_snapshot_child (widget, priv->bottom_marks_widget, snapshot);
if (priv->value_widget)
gtk_widget_snapshot_child (widget, priv->value_widget, snapshot);
GTK_WIDGET_CLASS (gtk_scale_parent_class)->snapshot (widget, snapshot);
}
static void
gtk_scale_real_get_layout_offsets (GtkScale *scale,
gint *x,
@ -1722,9 +1696,7 @@ gtk_scale_add_mark (GtkScale *scale,
gtk_widget_insert_after (priv->top_marks_widget,
GTK_WIDGET (scale),
(priv->value_widget &&
(priv->value_pos == GTK_POS_TOP || priv->value_pos == GTK_POS_LEFT)) ?
priv->value_widget : NULL);
priv->value_widget);
gtk_widget_add_css_class (priv->top_marks_widget, GTK_STYLE_CLASS_TOP);
}
marks_widget = priv->top_marks_widget;
@ -1742,9 +1714,7 @@ gtk_scale_add_mark (GtkScale *scale,
gtk_widget_insert_before (priv->bottom_marks_widget,
GTK_WIDGET (scale),
(priv->value_widget &&
(priv->value_pos == GTK_POS_BOTTOM || priv->value_pos == GTK_POS_RIGHT)) ?
priv->value_widget: NULL);
gtk_range_get_trough_widget (GTK_RANGE (scale)));
gtk_widget_add_css_class (priv->bottom_marks_widget, GTK_STYLE_CLASS_BOTTOM);
}
marks_widget = priv->bottom_marks_widget;

View File

@ -35,17 +35,14 @@ window.background:dir(ltr)
mark:dir(ltr)
label:dir(ltr)
indicator:dir(ltr)
trough:dir(ltr)
highlight.top:dir(ltr)
slider:dir(ltr)
marks.bottom:dir(ltr)
mark:dir(ltr)
indicator:dir(ltr)
label:dir(ltr)
trough:dir(ltr)
highlight.top:dir(ltr)
slider:dir(ltr)
scale.horizontal.marks-after:dir(ltr)
trough:dir(ltr)
highlight.top:dir(ltr)
slider:dir(ltr)
marks.bottom:dir(ltr)
mark:dir(ltr)
indicator:dir(ltr)
@ -53,3 +50,6 @@ window.background:dir(ltr)
mark:dir(ltr)
indicator:dir(ltr)
label:dir(ltr)
trough:dir(ltr)
highlight.top:dir(ltr)
slider:dir(ltr)