libgimpwidgets: better algorithm for GimpScaleEntry default increments.

For very small ranges, just dividing by 10 and 100 is not very good. You
could end up with weird step values. It is often better to use 10^(-x)
values just below your range.
I.e for a 0.5 range, a step of 0.1 and page of 0.01 are probably fine
(better than 0.05 and 0.005).

Of course as usual these are default values only and setting custom
increments is possible through available API.

Also fixing a small bug in gimp_scale_entry_set_increments() added in
commit 0f05825a29.
This commit is contained in:
Jehan 2020-10-30 17:33:53 +01:00
parent 99193230b3
commit ad8b417871
1 changed files with 25 additions and 3 deletions

View File

@ -445,9 +445,31 @@ gimp_scale_entry_update_steps (GimpScaleEntry *entry)
range = upper - lower;
if (range <= 1.0)
if (range > 0 && range <= 1.0)
{
gimp_scale_entry_set_increments (entry, range / 10.0, range / 100.0);
gdouble places = 10.0;
gdouble step;
gdouble page;
/* Compute some acceptable step and page increments always in the
* format `10**-X` where X is the rounded precision.
* So for instance:
* 0.8 will have increments 0.01 and 0.1.
* 0.3 will have increments 0.001 and 0.01.
* 0.06 will also have increments 0.001 and 0.01.
*/
while (range * places < 5.0)
places *= 10.0;
step = 0.1 / places;
page = 1.0 / places;
gimp_scale_entry_set_increments (entry, step, page);
}
else if (range <= 2.0)
{
gimp_scale_entry_set_increments (entry, 0.01, 0.1);
}
else if (range <= 40.0)
{
@ -917,7 +939,7 @@ gimp_scale_entry_set_increments (GimpScaleEntry *entry,
gtk_adjustment_set_page_increment (gtk_range_get_adjustment (scale), page);
gtk_adjustment_set_page_increment (gtk_spin_button_get_adjustment (spinbutton), page);
g_object_set (entry,
g_object_set (entry->priv->spinbutton,
"climb-rate", step,
NULL);
}