next up previous contents index
Next: The new_item Function Up: Interactive Elements Previous: What is Available

Creating Items

 

Items are created like all other instances by sending "new-instance" to their class. For items this method needs different parameters depending on the class, we will use a button which sends the method "show-send" to the current instance and a ruler which controls a double variable as examples:

BUTTON *button;
RULER *ruler;
static double *var = 0.5;

button = (BUTTON *)GRAPE(Button, "new-instance")("show-send", NULL, "show");
ruler = (RULER *)GRAPE(Ruler, "new-instance")(&var, "var", dfDouble);

The button is called ``show'', the NULL indicates that it has no special instance to send its method "show-send" to, therefore it will send it to the current instance.

The ruler is named ``var'' like the variable it controls, it has type dfDouble. The variable was declared static and it was initialized, you should be very careful when you are using local or uninitialized variables for rulers (see section 5.5.8 below).

Items have many different attributes that can be changed: name, label, size, position, color, method, instance, action, minimum, maximum, scale, fillmode etc. -- what is possible depends on the class. To set for example the width of the button to 6.0 and its height to 1.0 you have to send "set-pref-size" to the button:

GRAPE(button, "set-pref-size")(6.0, 1.0);
Sending the methods
GRAPE(ruler, "set-min-max")(0.0, 1.0);
GRAPE(ruler, "set-scale")(1.0);
GRAPE(ruler, "set-offset")(0.0);
restricts the ruler value to the interval [0.0, 1.0] and changes its layout so that the ruler value is 0.0 in the left and 1.0 in the right position. As mentioned before the documentation of all these methods can be found in chapter 9.1.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.