Explore text-entry gadgets for simulation interfaces. Review the setup and input-handling details before adding a control.
User Text-Entry Gadget
This gadget places text-entry box on your diagrams. The text-box
becomes active during simulations. When text is entered in the box,
it calls your designated function which can access the entered data.
To place such a text-box in a diagram, instantiate a model that
contains the following function call:
user_text_field( label, x, y, your_function, id );
The label is a character string containing any initial text
you wish to appear in the text-field.
The x and y values are the floating-point coordinate
offsets where you want to place the text-box on your diagram relative
to the box under which it is instantiated. An x-y value of (0.0,0.0)
will place the text-box at the upper left corner of the box where it is
instantiated.
The your_function is the name of the function that you want
to be called when the text gets entered. You should define this
function within a DEFINE_GLOBAL: area.
The id is an arbitrary data item that you can use to identify
which of several text-fields the entry is coming from.
For example:
DEFINE_GLOBAL:
/* Prototype the standard function. */
void user_text_field( char *label, float x, float y,
void *u_func, int data_arg );
/* Define your (user) function. */
void user_texttest( Widget w, caddr_t client_data )
{
char *str1 = XmTextGetString(w);
printf("Form %d returned '%s'\n", client_data, str1);
}
END_DEFINE_GLOBAL.
/* Define your box-model that contains a text-entry form. */
DEFINE_DEVICE_TYPE: Form_Box
DEFINE_THREAD: start_up
{
user_text_field( "0.88", 0.1, 0.1, user_texttest, 101 );
}
END_DEFINE_THREAD.
END_DEFINE_DEVICE_TYPE.
To try this example, you would create a diagram that instantiates
a box of type Form_Box. If you built and ran the simulation
containing this example-model, you will see a text-box appear
on the box. The initial text in the box would be 0.88.
If you type some new text and press enter, it will call the function
user_textform which will print:
Form 101 returned 'whateveryoutyped'
in your terminal window.
You can establish any number of text-boxes, and they can call any number
of functions that you define.
This page is an editorial rewrite of source documentation. Historical status, availability, and platform notes are not independently verified for a current release. Technical examples are reference material, not a live simulator.