[gtk/wip/baedert/for-master: 78/86] range: Clean up compute_slider_position()
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 78/86] range: Clean up compute_slider_position()
- Date: Sun, 23 Feb 2020 11:26:11 +0000 (UTC)
commit 5678c7b0d7238c283003b8901d9a54fea8fce8fe
Author: Timm Bäder <mail baedert org>
Date: Sat Feb 22 14:04:06 2020 +0100
range: Clean up compute_slider_position()
gtk/gtkrange.c | 76 ++++++++++++++++++++++------------------------------------
1 file changed, 29 insertions(+), 47 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index a09d8b6e8a..a57963b4c8 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -2546,11 +2546,11 @@ gtk_range_compute_slider_position (GtkRange *range,
GdkRectangle *slider_rect)
{
GtkRangePrivate *priv = gtk_range_get_instance_private (range);
- int trough_width, trough_height;
- 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);
+ int trough_width, trough_height;
+ int slider_width, slider_height;
gtk_widget_measure (priv->slider_widget,
GTK_ORIENTATION_HORIZONTAL, -1,
@@ -2566,89 +2566,71 @@ gtk_range_compute_slider_position (GtkRange *range,
if (priv->orientation == GTK_ORIENTATION_VERTICAL)
{
- gint y, bottom, top, height;
-
- /* Slider fits into the trough, with stepper_spacing on either side,
- * and the size/position based on the adjustment or fixed, depending.
- */
+ int y, height;
+
slider_rect->x = (int) floor ((trough_width - slider_width) / 2);
slider_rect->width = slider_width;
- min_slider_size = slider_height;
-
- /* Compute slider position/length */
- top = 0;
- bottom = top + trough_height;
-
/* slider height is the fraction (page_size /
* total_adjustment_range) times the trough height in pixels
*/
if (upper - lower != 0)
- height = (bottom - top) * (page_size / (upper - lower));
+ height = trough_height * (page_size / (upper - lower));
else
- height = min_slider_size;
+ height = slider_height;
- if (height < min_slider_size ||
+ if (height < slider_height ||
priv->slider_size_fixed)
- height = min_slider_size;
+ height = slider_height;
height = MIN (height, trough_height);
-
- y = top;
if (upper - lower - page_size != 0)
- y += (bottom - top - height) * ((adjustment_value - lower) / (upper - lower - page_size));
+ y = (trough_height - height) * ((adjustment_value - lower) / (upper - lower - page_size));
+ else
+ y = 0;
+
+ y = CLAMP (y, 0, trough_height);
- y = CLAMP (y, top, bottom);
-
if (should_invert (range))
- y = bottom - (y - top + height);
-
+ y = trough_height - y - height;
+
slider_rect->y = y;
slider_rect->height = height;
}
else
{
- gint x, left, right, width;
-
- /* Slider fits into the trough, with stepper_spacing on either side,
- * and the size/position based on the adjustment or fixed, depending.
- */
+ int x, width;
+
slider_rect->y = (int) floor ((trough_height - slider_height) / 2);
slider_rect->height = slider_height;
- min_slider_size = slider_width;
-
- /* Compute slider position/length */
- left = 0;
- right = left + trough_width;
-
/* slider width is the fraction (page_size /
* total_adjustment_range) times the trough width in pixels
*/
if (upper - lower != 0)
- width = (right - left) * (page_size / (upper - lower));
+ width = trough_width * (page_size / (upper - lower));
else
- width = min_slider_size;
+ width = slider_width;
- if (width < min_slider_size ||
+ if (width < slider_width ||
priv->slider_size_fixed)
- width = min_slider_size;
+ width = slider_width;
width = MIN (width, trough_width);
- x = left;
-
if (upper - lower - page_size != 0)
- x += (right - left - width) * ((adjustment_value - lower) / (upper - lower - page_size));
-
- x = CLAMP (x, left, right);
-
+ x = (trough_width - width) * ((adjustment_value - lower) / (upper - lower - page_size));
+ else
+ x = 0;
+
+ x = CLAMP (x, 0, trough_width);
+
if (should_invert (range))
- x = right - (x - left + width);
-
+ x = trough_width - x - width;
+
slider_rect->x = x;
slider_rect->width = width;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]