/* TEACH GO_LABELLED                           Ben Rabau, 27th Aug 1993

This file shows a few examples of labelled objects.
The objects can be simple labels, text-inputs or labelled objects.

For more general detailed information see

HELP * GO
REF * GO

         CONTENTS - (Use <ENTER> g to access required sections)

 -- go_text class
 -- go_text_input class
 -- go_labelled mixin example
 -- label offset

 */

;;; Requires the following files to be loaded:
uses go;
uses go_labelled;
uses go_text;
uses go_text_input;
uses go_rectangle;

;;; It also requires the GO window to be active:
go_init_rc();

/*
-- go_text class -----------------------------------------------------
 */
;;; To create a fixed text do:
vars a_text = instance go_text;
                  go_xcentre = 100; go_ycentre =  100;
              endinstance;
go_add_to( a_text , go_default_pane );

;;; The label can be interrogated or changed with the go_label() method:
go_label( a_text ) =>
'Hello World' -> go_label( a_text );

/*
-- go_text_input class ------------------------------------------------
 */
;;; A go_text_input object is a go_key_sensitive label (TEACH * GO_SENSITIVE).
;;; If the object is in live mode then text can be entered and edited
;;; (TEACH * GO_LIVE). These go_text_input objects have a fixed length...

;;; To create a label do:
vars a_text_input = newgo_text_input();
go_add_to( a_text_input , go_default_pane );

;;; If you are in edit mode you can move it...
;;; To make the object live without all objects in the pane to go live do:
true -> go_live_object( a_text_input );

;;; Now you can type in some text by pointing the mouse in the object's area.
;;; A message is printed out if the keystroke is not handled by the default
;;; mechanism it is mentioned too (e.g. holding the shift key down does not
;;; result in any immediate action, nor does Function Key F12).
;;; Note that some keys like the function keys do not result in characters in
;;; the label.

;;; Let us now type in a very long string (or simulate this with:)
'This is a very long string for the text input' -> go_label( a_text_input );

;;; This string will be cut of at the maximum width allowed by it's width.
;;; The real length of the string is:
go_label_width( a_text_input ) =>
;;; Whereas the maximum length is the length of the object:
go_bounding_width ( a_text_input ) =>

;;; We can extend this by doing:
go_label_width( a_text_input ) -> go_bounding_width ( a_text_input );


/*
-- go_labelled mixin example ------------------------------------------
 */
;;; The mixin go_labelled can be used in conjunction with any other screen object.
;;; As an example we use an oblong.
uses go_oblong;
define :class lab_oblong;
    isa go_labelled go_oblong;
enddefine;

;;; Let us create one object of this new class (note that this compiles the
;;; ObjectClass first).
vars a_button = newlab_oblong(); go_centre_to(50, 50, a_button);
go_add_to(a_button, go_default_pane );

;;; The first thing you might want to do is to reset the label
'Hello Again World!' -> go_label( a_button );

;;; As you can see the label is limited by the size of the oblong...
;;; If the height is insufficient then the string is not printed and
;;; a warning message is printed. The elaborate and slow algorithm to
;;; nicely truncate the string at a character should be avoided where
;;; possible.
;;; To set the minimum size:
go_label_width( a_button ) -> go_bounding_width ( a_button );

;;; Then you can also edit the oblong, i.e. stretch or move the corners:
;;; (See also: TEACH * GO_MAKE_EDITABLE).
go_make_editable( a_button );

;;; Let us make it a lot bigger (higher and wider) for a moment. As
;;; You can see the label remains in the bottom left hand corner.
;;; To move it to the centre we will use offsets.

;;; Before we do that we can make it slightly easier by removing the editors:
go_make_uneditable( a_button );


/*
-- label offset -------------------------------------------------------
 */

;;; The label will be printed from the left hand bottom corner and it
;;; will take the go_label_x_offset() and go_label_y_offset() into account
;;; on either side of the label (both top&bottom and left&right).
30 -> go_label_x_offset( a_button );
10 -> go_label_y_offset( a_button );

;;; The following centres the label by using the offsets on both sides:
go_label_width( a_button ) -> go_width ( a_button );
go_label_height( a_button ) -> go_height( a_button );

;;; If the oblong is put upside down with scaling (go_xscale/go_yscale) or
;;; rotation (go_angle) then the label will not be rotated:
;;; The offsets will however always remain calculated from the bottom left.
go_yscale( go_default_pane ) * -1 -> go_yscale( go_default_pane );
5 -> go_label_x_offset( a_button );
5 -> go_label_y_offset( a_button );

;;; Rotation is worse than scaling because the X11R4 does not have a lot
;;; of support for scalable and rotatable fonts. The following is very
;;; unsatisfactory:
45 -> go_angle( a_button );


;;; eof

--- C.all/lib/proto/go/teach/go_labelled
--- Copyright University of Sussex 1993. All rights reserved.
