Re: Feedback updating scrollbar



Dear Paul!

I fear the problem remains. To stay with your pseudo code: when
"adjustment_changed_handler" fires, all goes well and we jump to the new
position in the file. When the file position changes due to, say, passage
of time, "other_file_position_changed_handler" fires, which eventually
calls "gtk_adjustment_set_value". Here lies my problem, because
"gtk_adjustment_set_value" effectively rounds off 'float argument' and
creates a callback to "adjustment_changed_handler", which changes the
position again, ever so slightly.

I.e. even if the user never touches the mouse, 
"adjustment_changed_handler" periodically messes up the file position by
tiny amounts.

See what I mean?

Mark


> >I have a scrollbar that represents the position in a file. When the
> >user changes the position, the program reacts via the callback. Easy. 

> >But when the position in the file changes for other reasons, and the
> >program therefore sets the value of the scrollbar accordingly (using
> >gtk_adjustment_set_value), the callback is also called. What with rounding
> >errors, this means that the position is changed yet again, but not quite
> >to the right value. 

> Standard Model-View-Controller-meets-GTK question. Maintain an
> independent variable indicating position in the file. Keep the
> adjustment and this other value in sync. Some pseudo-code:
> 
> gfloat file_position;
> GtkAdjustment *scrollbar_adjustment;
> 
> gint
> adjustment_changed_handler (GtkAdjustment *adj, GtkEventFoobar *ev)
> 
> {
>   gfloat adjustment_value = gtk_adjustment_get_value (adj);
>    
>   if (adjustment_value != file_position) {
>        ... adjust the file position ...
>   }
> 
>   return TRUE;
> }
> 
> void
> other_file_position_changed_handler (...)
> {
>   gfloat adjustment_value = gtk_adjustment_get_value (scrollbar_adjustment);
> 
>   if (adjustment_value != file_position) {
>        gtk_adjustment_set_value (scrollbar_adjustment, file_position);
>   }
> }    






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]