Commit 2535a22d authored by Pat Brands's avatar Pat Brands

Made constraint of scale slider to step increments optional

* Use option '--enforce-step' to enable the feature
parent 6686e709
...@@ -923,6 +923,9 @@ Set maximum value. ...@@ -923,6 +923,9 @@ Set maximum value.
.B \-\-step=\fIVALUE\fP .B \-\-step=\fIVALUE\fP
Set step size. Set step size.
.TP .TP
.B \-\-enforce-step
Only allow values in step increments.
.TP
.B \-\-page=\fIVALUE\fP .B \-\-page=\fIVALUE\fP
Set paging size. By default page value is STEP*10. Set paging size. By default page value is STEP*10.
.TP .TP
......
...@@ -580,6 +580,8 @@ static GOptionEntry scale_options[] = { ...@@ -580,6 +580,8 @@ static GOptionEntry scale_options[] = {
N_("Set maximum value"), N_("VALUE") }, N_("Set maximum value"), N_("VALUE") },
{ "step", 0, 0, G_OPTION_ARG_INT, &options.scale_data.step, { "step", 0, 0, G_OPTION_ARG_INT, &options.scale_data.step,
N_("Set step size"), N_("VALUE") }, N_("Set step size"), N_("VALUE") },
{ "enforce-step", 0, 0, G_OPTION_ARG_NONE, &options.scale_data.enforce_step,
N_("Only allow values in step increments"), NULL },
{ "page", 0, 0, G_OPTION_ARG_INT, &options.scale_data.page, { "page", 0, 0, G_OPTION_ARG_INT, &options.scale_data.page,
N_("Set paging size"), N_("VALUE") }, N_("Set paging size"), N_("VALUE") },
{ "print-partial", 0, 0, G_OPTION_ARG_NONE, &options.scale_data.print_partial, { "print-partial", 0, 0, G_OPTION_ARG_NONE, &options.scale_data.print_partial,
......
...@@ -33,13 +33,13 @@ static GtkWidget *minus_btn = NULL; ...@@ -33,13 +33,13 @@ static GtkWidget *minus_btn = NULL;
static void static void
value_changed_cb (GtkWidget * w, gpointer data) value_changed_cb (GtkWidget * w, gpointer data)
{ {
/* Make sure the new value corresponds to a step in the range. This is needed if (options.scale_data.enforce_step)
* since the user can move the slider with the mouse which doesn't obey the {
* step constraint like the keyboard or buttons /* Make sure the new value corresponds to a step in the range. */
*/
gdouble value = gtk_adjustment_get_value ((GtkAdjustment *)adj); gdouble value = gtk_adjustment_get_value ((GtkAdjustment *)adj);
gdouble new_value = (gdouble) round(value/options.scale_data.step) * options.scale_data.step; gdouble new_value = (gdouble) round(value/options.scale_data.step) * options.scale_data.step;
gtk_adjustment_set_value ((GtkAdjustment *)adj, new_value); gtk_adjustment_set_value ((GtkAdjustment *)adj, new_value);
}
if (options.scale_data.print_partial) if (options.scale_data.print_partial)
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale))); g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
......
...@@ -432,6 +432,7 @@ typedef struct { ...@@ -432,6 +432,7 @@ typedef struct {
gboolean invert; gboolean invert;
gboolean buttons; gboolean buttons;
GSList *marks; GSList *marks;
gboolean enforce_step;
} YadScaleData; } YadScaleData;
typedef struct { typedef struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment