[gtk+/wip/cosimoc/range-gadget] scale: port marks size request to gadgets
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cosimoc/range-gadget] scale: port marks size request to gadgets
- Date: Sat, 27 Feb 2016 23:46:39 +0000 (UTC)
commit a227d4a7c9e8e80ab93da4d83056f6e7249858af
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Feb 27 15:24:32 2016 -0800
scale: port marks size request to gadgets
gtk/gtkscale.c | 127 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 83 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 166a366..10c55fa 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -1066,35 +1066,75 @@ gtk_scale_screen_changed (GtkWidget *widget,
}
static void
+gtk_scale_measure_marks (GtkCssGadget *gadget,
+ GtkOrientation orientation,
+ gint for_size,
+ gint *minimum,
+ gint *natural,
+ gint *minimum_baseline,
+ gint *natural_baseline,
+ gpointer user_data)
+{
+ GtkWidget *widget = gtk_css_gadget_get_owner (gadget);
+ GtkScale *scale = GTK_SCALE (widget);
+ GtkScalePrivate *priv = scale->priv;
+ GtkCssGadget *slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (scale));
+ int n_top, w_top, h_top, n_bottom, w_bottom, h_bottom;
+ int slider_length;
+
+ gtk_scale_get_mark_label_size (scale,
+ &n_top, &w_top, &h_top,
+ &n_bottom, &w_bottom, &h_bottom);
+ gtk_css_gadget_get_preferred_size (slider_gadget,
+ orientation, -1,
+ &slider_length, NULL,
+ NULL, NULL);
+
+ if (gadget == priv->top_marks_gadget)
+ {
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ *minimum = *natural = (n_top - 1) * w_top + MAX (w_top, slider_length);
+ else
+ *minimum = *natural = (n_top - 1) * h_top + MAX (h_top, slider_length);
+ }
+ else
+ {
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ *minimum = *natural = (n_bottom - 1) * w_bottom + MAX (w_bottom, slider_length);
+ else
+ *minimum = *natural = (n_bottom - 1) * h_bottom + MAX (h_bottom, slider_length);
+ }
+}
+
+static void
gtk_scale_get_preferred_width (GtkWidget *widget,
gint *minimum,
gint *natural)
{
+ GtkScale *scale = GTK_SCALE (widget);
+ GtkScalePrivate *priv = scale->priv;
+
GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_width (widget, minimum, natural);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
{
- gint n_top, w_top, h_top, n_bottom, w_bottom, h_bottom;
- GtkCssGadget *slider_gadget;
- gint slider_length;
- gint w;
-
- slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget));
- gtk_css_gadget_get_preferred_size (slider_gadget,
- GTK_ORIENTATION_HORIZONTAL, -1,
- &slider_length, NULL,
- NULL, NULL);
-
- gtk_scale_get_mark_label_size (GTK_SCALE (widget),
- &n_top, &w_top, &h_top,
- &n_bottom, &w_bottom, &h_bottom);
-
- w_top = (n_top - 1) * w_top + MAX (w_top, slider_length);
- w_bottom = (n_bottom - 1) * w_bottom + MAX (w_bottom, slider_length);
- w = MAX (w_top, w_bottom);
-
- *minimum = MAX (*minimum, w);
- *natural = MAX (*natural, w);
+ int top_marks_width = 0, bottom_marks_width = 0, marks_width;
+
+ if (priv->top_marks_gadget)
+ gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
+ GTK_ORIENTATION_HORIZONTAL, -1,
+ &top_marks_width, NULL,
+ NULL, NULL);
+ if (priv->bottom_marks_gadget)
+ gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget,
+ GTK_ORIENTATION_HORIZONTAL, -1,
+ &bottom_marks_width, NULL,
+ NULL, NULL);
+
+ marks_width = MAX (top_marks_width, bottom_marks_width);
+
+ *minimum = MAX (*minimum, marks_width);
+ *natural = MAX (*natural, marks_width);
}
}
@@ -1103,31 +1143,30 @@ gtk_scale_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural)
{
- GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural);
+ GtkScale *scale = GTK_SCALE (widget);
+ GtkScalePrivate *priv = scale->priv;
+ GTK_WIDGET_CLASS (gtk_scale_parent_class)->get_preferred_height (widget, minimum, natural);
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL)
{
- gint n_top, w_top, h_top, n_bottom, w_bottom, h_bottom;
- GtkCssGadget *slider_gadget;
- gint slider_length;
- gint h;
-
- slider_gadget = gtk_range_get_slider_gadget (GTK_RANGE (widget));
- gtk_css_gadget_get_preferred_size (slider_gadget,
- GTK_ORIENTATION_VERTICAL, -1,
- &slider_length, NULL,
- NULL, NULL);
-
- gtk_scale_get_mark_label_size (GTK_SCALE (widget),
- &n_top, &w_top, &h_top,
- &n_bottom, &w_bottom, &h_bottom);
- h_top = (n_top - 1) * h_top + MAX (h_top, slider_length);
- h_bottom = (n_bottom - 1) * h_top + MAX (h_bottom, slider_length);
- h = MAX (h_top, h_bottom);
-
- *minimum = MAX (*minimum, h);
- *natural = MAX (*natural, h);
+ int top_marks_height = 0, bottom_marks_height = 0, marks_height;
+
+ if (priv->top_marks_gadget)
+ gtk_css_gadget_get_preferred_size (priv->top_marks_gadget,
+ GTK_ORIENTATION_VERTICAL, -1,
+ &top_marks_height, NULL,
+ NULL, NULL);
+ if (priv->bottom_marks_gadget)
+ gtk_css_gadget_get_preferred_size (priv->bottom_marks_gadget,
+ GTK_ORIENTATION_VERTICAL, -1,
+ &bottom_marks_height, NULL,
+ NULL, NULL);
+
+ marks_height = MAX (top_marks_height, bottom_marks_height);
+
+ *minimum = MAX (*minimum, marks_height);
+ *natural = MAX (*natural, marks_height);
}
}
@@ -1645,7 +1684,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->top_marks_gadget =
gtk_css_custom_gadget_new ("marks",
GTK_WIDGET (scale), NULL, NULL,
- NULL,
+ gtk_scale_measure_marks,
NULL,
NULL,
NULL, NULL);
@@ -1662,7 +1701,7 @@ gtk_scale_add_mark (GtkScale *scale,
priv->bottom_marks_gadget =
gtk_css_custom_gadget_new ("marks",
GTK_WIDGET (scale), NULL, NULL,
- NULL,
+ gtk_scale_measure_marks,
NULL,
NULL,
NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]