range: Simplify compute_slider_position

This commit is contained in:
Timm Bäder 2018-02-22 17:56:49 +01:00
parent 4c952da6cb
commit 1fea980930

View File

@ -2570,6 +2570,9 @@ gtk_range_compute_slider_position (GtkRange *range,
GtkRangePrivate *priv = gtk_range_get_instance_private (range); GtkRangePrivate *priv = gtk_range_get_instance_private (range);
int trough_width, trough_height; int trough_width, trough_height;
int slider_width, slider_height, min_slider_size; int slider_width, slider_height, min_slider_size;
const double upper = gtk_adjustment_get_upper (priv->adjustment);
const double lower = gtk_adjustment_get_lower (priv->adjustment);
const double page_size = gtk_adjustment_get_page_size (priv->adjustment);
gtk_widget_measure (priv->slider_widget, gtk_widget_measure (priv->slider_widget,
GTK_ORIENTATION_HORIZONTAL, -1, GTK_ORIENTATION_HORIZONTAL, -1,
@ -2610,9 +2613,8 @@ gtk_range_compute_slider_position (GtkRange *range,
* total_adjustment_range) times the trough height in pixels * total_adjustment_range) times the trough height in pixels
*/ */
if (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) != 0) if (upper - lower != 0)
height = ((bottom - top) * (gtk_adjustment_get_page_size (priv->adjustment) / height = (bottom - top) * (page_size / (upper - lower));
(gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment))));
else else
height = min_slider_size; height = min_slider_size;
@ -2624,9 +2626,8 @@ gtk_range_compute_slider_position (GtkRange *range,
y = top; y = top;
if (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment) != 0) if (upper - lower - page_size != 0)
y += (bottom - top - height) * ((adjustment_value - gtk_adjustment_get_lower (priv->adjustment)) / y += (bottom - top - height) * ((adjustment_value - lower) / (upper - lower - page_size));
(gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment)));
y = CLAMP (y, top, bottom); y = CLAMP (y, top, bottom);
@ -2663,9 +2664,8 @@ gtk_range_compute_slider_position (GtkRange *range,
* total_adjustment_range) times the trough width in pixels * total_adjustment_range) times the trough width in pixels
*/ */
if (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) != 0) if (upper - lower != 0)
width = ((right - left) * (gtk_adjustment_get_page_size (priv->adjustment) / width = (right - left) * (page_size / (upper - lower));
(gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment))));
else else
width = min_slider_size; width = min_slider_size;
@ -2677,9 +2677,8 @@ gtk_range_compute_slider_position (GtkRange *range,
x = left; x = left;
if (gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment) != 0) if (upper - lower - page_size != 0)
x += (right - left - width) * ((adjustment_value - gtk_adjustment_get_lower (priv->adjustment)) / x += (right - left - width) * ((adjustment_value - lower) / (upper - lower - page_size));
(gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_lower (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment)));
x = CLAMP (x, left, right); x = CLAMP (x, left, right);