# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :
> I have to create many value slider with an input value field. The
> slider has to update the input field and the input field has to
> update the slider. I think it is the best way to create a new object
> as described in the manual, but I have no idea to handle a normal
> slider object and a normal input object as one object.
You could create this using the Free object and the tools provided
there, but I think it's probably easier to just create an Input object
and a Slider and then process the events with separate callbacks.
Here's a schematic of what you might do:
typedef struct { /* Define a bag to put things into */
FL_OBJECT *slider;
FL_OBJECT *input;
void (*action)( float value );
} Slider, *SliderP;
[...]
FD_form *form = create_form_form();
/*
* Set up the sliders.
*/
setup_slider( form->slider1, form->input1, handler1 );
[...]
setup_slider( form->sliderN, form->inputN, handlerN );
[...]
/*
* The setup.
*/
void setup_slider( FL_OBJECT *slider, FL_OBJECT *input,
void (*action)( float value ) )
{
SliderP slider_ptr = ( SliderP ) malloc( sizeof( Slider ) );
slider_ptr->slider = slider;
slider_ptr->input = input;
slider_ptr->handler = handler;
slider->u_vdata = input->u_vdata = slider_ptr;
}
[...]
/*
* The callbacks.
*/
void slider_callback( FL_OBJECT *obj, long parm )
{
char buffer[BUFSIZE];
SliderP slider_ptr = ( SliderP ) obj->u_vdata;
float value = fl_get_slider_value( obj );
sprintf( buffer, "%f", value ); /* Use your favorite format here */
fl_set_input( slider_ptr->input, buffer );
(*slider_ptr->action)( value );
}
void input_callback( FL_OBJECT *obj, long parm )
{
const char *input = fl_get_input( obj );
float value = atof( input );
SliderP slider_ptr = ( SliderP ) obj->u_vdata;
fl_set_slider_value( slider_ptr->slider, value );
(*slider_ptr->action)( value );
}
This is all off the top of my head. There's no range or error
checking here and I'm sure I've left a lot of details out but this
should give you an idea of how to go about it in a generalizable
manner.
spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Thu Jan 06 2000 - 13:40:16 EST