%rf (Edit Floating Point) creates an edit box and displays the value of the corresponding (DOUBLE PRECISION) argument. The number will be updated whenever the edit field is adjusted. The user will be prevented from creating an invalid or out of range number (see Floating point increase/decrease). Numbers are entered in decimal or exponent form. For example: -0.0748 or -7.48e-2.
By default the edit box will be made large enough to hold values in the current range, although the integer parameter n can be used to override this.
A call-back function is supplied using the caret (^) modifier. This function is called immediately a change is made.
For example, suppose you wanted to prompt for a complex number, and the user is allowed to supply this as an (x, y) pair or as an (r, θ) pair. The box should show the current number in both formats and any change in one format should be reflected in the other. Here is some sample code that has the desired effect.
WINAPP
DOUBLE PRECISION x,y,r,theta
COMMON x,y,r,theta
INTEGER i,winio@
EXTERNAL convert_to_xy,convert_to_polar
x=1.0D0
y=0.0D0
r=1.0D0
theta=0.0D0
i=winio@('%ca[Polar co-ordinates]%bg[grey]&')
i=winio@('%3tl&',5,15,21)
i=winio@(' %itx%`it=%ta&')
i=winio@('%^rf&',x,convert_to_polar)
i=winio@(' %ity%`it=%ta&')
i=winio@('%^rf&',y,convert_to_polar)
i=winio@('%ff %itr%`it=%ta&')
i=winio@('%^rf&',r,convert_to_xy)
i=winio@(' %fn[Symbol]%itq%sf =%ta&')
i=winio@('%^rf',theta,convert_to_xy)
END
c-----
INTEGER FUNCTION convert_to_polar()
DOUBLE PRECISION x,y,r,theta,tiny
COMMON x,y,r,theta
tiny=1.0D-6
r=SQRT(x*x+y*y)
IF(x.LT.tiny.AND.y.LT.tiny)THEN
theta=0.0
ELSE
theta=ATAN2(y,x)
ENDIF
convert_to_polar=1
END
c-----
INTEGER FUNCTION convert_to_xy()
DOUBLE PRECISION x,y,r,theta
COMMON x,y,r,theta
x=r*COS(theta)
y=r*SIN(theta)
convert_to_xy=1
END
A grave accent format modifier (`) is used to make the control read-only. In this form no surrounding box is supplied, and the value displayed can only be changed by the program, using WINDOW_UPDATE@ to reflect the changes.
The %co (Options for Edit) format is used to modify the way that %rf (Edit Floating Point) and %rd (Edit Integer) call-back functions behave.