]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkhscale.c
clamp the value to the range that was set
[~andy/gtk] / gtk / gtkhscale.c
index 4b6e34a4ccb0f6c48e7ca2d28f6b6778f5b069c4..ebd37861e46237407de665173dab7cca27f59aed 100644 (file)
@@ -102,6 +102,50 @@ gtk_hscale_new (GtkAdjustment *adjustment)
   return hscale;
 }
 
+/**
+ * gtk_hscale_new_with_range:
+ * @min: minimum value
+ * @max: maximum value
+ * @step: step increment (tick size) used with keyboard shortcuts
+ * 
+ * Creates a new horizontal scale widget that lets the user
+ * input a number between @min and @max with the increment @step.
+ * @step must be nonzero; it's the distance the slider moves when
+ * using the arrow keys to adjust the scale value.
+ * 
+ * Return value: a new #GtkHScale
+ **/
+GtkWidget*
+gtk_hscale_new_with_range (gdouble min,
+                           gdouble max,
+                           gdouble step)
+{
+  GtkObject *adj;
+  GtkScale *scale;
+  gint digits;
+
+  g_return_val_if_fail (min < max, NULL);
+  g_return_val_if_fail (step != 0.0, NULL);
+
+  adj = gtk_adjustment_new (min, min, max, step, 10 * step, step);
+  
+  scale = g_object_new (GTK_TYPE_HSCALE,
+                        "adjustment", adj,
+                        NULL);
+
+  if (fabs (step) >= 1.0 || step == 0.0)
+    digits = 0;
+  else {
+    digits = abs ((gint) floor (log10 (fabs (step))));
+    if (digits > 5)
+      digits = 5;
+  }
+
+  gtk_scale_set_digits (scale, digits);
+  
+  return GTK_WIDGET (scale);
+}
+
 static gboolean
 gtk_hscale_expose (GtkWidget      *widget,
                    GdkEventExpose *event)