Problem with precision on GtkAdjustment
- From: David O'Toole <dto gnu org>
- To: gtk-app-devel-list gnome org
- Subject: Problem with precision on GtkAdjustment
- Date: 23 Apr 2001 21:40:11 -0400
Hi folks. I've been unable to find the source of this problem, perhaps
someone on the list will know. I have an application that puts together
Adjustments and HScales for different value ranges. For instance, some
allow the user to edit a value between -1.0/+1.0, others are from zero
to 128. I'm putting these sliders together into "control boxes."
In the code excerpt below, "ps" points to a structure holding the
specification for the valid range of values for the GtkAdjustment.
------------------------
adj = gtk_adjustment_new (ps->start, ps->min, ps->max,
(float)((ps->max - ps->min) / 250.0), 1.0, 0);
// now print out these values to make sure numbers are sane
printf ("build_widget %p %f %f (%f) %f\n", adj, ps->min,
ps->max,(float)((ps->max -ps->min) / 250.0),
(GTK_ADJUSTMENT(adj))->step_increment);
-----------------------
The output produced for building one of the control boxes is as follows:
---------------
build_widget 0x817af18 1.000000 8.000000 (0.028000) 0.028000
build_widget 0x817b5d8 0.000000 1.000000 (0.004000) 0.004000
----------------
(That is, I've verified that the step-increment that I calculate in the
call to gtk_adjustment_new has not changed in the meantime.)
The problem occurs when dragging the little handle via the mouse. When
the value of step_increment is greater than 0.1, this seems to work
fine.
But when step_increment is smaller than 0.1 (as in the above calls,
where it is 0.004 and the whole value range is just 0.0 to 1.0) the
adjustment's value always changes in increments of 0.1, no matter what
step_increment is. I end up with sliders that, when dragged, only have
ten different effective values (0.1, 0.2, 0.3... etc). Resizing the
slider does not seem to change anything, I still get ten steps.
Now using the arrow keys actually gets the values to move by
step_increment. I can get that to work on all of them---the real problem
is that actual /dragging/ won't use any increment smaller than 0.1. I
don't care that the larger value ranges (0-128 etc) don't move in
exactly step_increment size steps when /dragged/. That's fine. But if
dragging won't produce tiny steps, that makes some of the sliders very
frustrating to use.
I examined the source code to GtkHScale and GtkAdjustment, but I wasn't
able to figure out where the problem might be.
Another explanation is that I'm using the Adjustment incorrectly. The
1.2 API documentation for GtkAdjustment documents the step_increment and
page_increment fields only in terms of what a GtkScrollbar is going to
do with them (for instance, step_increment is used when you click the
arrows at the ends of the scrollbar.) It says little about how to use
them with GtkHScale, so I may be doing it completely wrong. If this is
the case, I'd love it if someone could give me the correct information.
Thanks very much in advance.
-dave
--
@@@ david o'toole
@@@ dto gnu org
@@@ www.gnu.org/software/octal
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]