To be able to manage many items mixing geometric parts and non-geometric parts, TkZinc introduces the concepts of label, labelformat, fields and fields attributes.
A label is a set of rectangular fields attached to the following item types : track , waypoint and tabular . The fields of a label may contain either text or bitmaps or images. A label cannot be identified or manipulated by itself; There is no function nor method to get or manipulate a label as an object or an item. A label is always associated to an item and is manipulated through this item.
Some label global characteristics are set/get at the item level:
$track = $zinc->add('track',1, 4, ....);
# this creates a track item in root group with 4 fields, indexed from 0 to 3 |
$zinc->itemconfigure($track, -labelformat => 'a12a0+0+0 x20x10^0>0 a2a0>1>0');
# ^ ^ ^ # field0 field1 field2 # the labelformat indicates that only the first 3 fields will be displayed: # field 0 expands for the size of the text + 12 pixels. # It starts at the top left point # field 1 has a size of 20x10 pixels. # It is left aligned with field 0, just under field 0 # field 2 expands for the size of the text + 2 pixels. # It is adjacent to the right of field 1, just under field 0 |
Characteristics of each individual field are called field attributes. They are all described in next section Attributes for fields . They may be set or get with the itemcget and itemconfigure command. These commands require as a second argument the field number. By configuring field attributes you can modify :
As an example:
# this should display "Hello World" in white on black in field 0
$zinc->itemconfigure($track, 0, -text => 'Hello World', -color => 'white', -backcolor => 'black', -filled => 1); |
It is possible to bind callbacks to fields, with the command bind and special tags (described Tags and bindings ). As an example:
# this binds &acallback to field 1
$zinc->bind("$track:1", '<1>', \&acallback); |
Inside a callback function, it is possible to know which field the mouse cursor is over with the command currentpart .
A Perl module, called Tk::Zinc::Text (see the section Tk::Zinc::Text ) is provided for easing text input in text fields (it can also be used for easing text input in text item).
Fields are item parts of items supporting labelformat (i.e. track , waypoint and tabular ). They can be
configured in a similar way of items themselves, with the command itemconfigure , but this
command requires an additionnal parameter (in second position) the fieldId. To get the value of a
field attribute, you can use the command itemcget with the fieldId as an additionnal second
parameter.
NB: Field attributes cannot be configured at item creation with the command add .
Applicable attributes for fields are:
-alignment alignment
The horizontal alignment of both the text and the image. The default value is left.
-autoalignment autoalignment
The dynamic horizontal alignments used depending on the label orientation. The default value is "-" which means do not use dynamic alignment.
-backcolor gradient
The field background color. The default value is the current value of the widget option -backcolor .
-border edgelist
The border description edge by edge. The border is a one pixel wide outline that is drawn around the field outside the relief. Some border edges can be omitted, this attribute describes the edges that should be displayed as part of the border. The default value is "".
-bordercolor gradient
The border uniform (possibly transparent) color. The first color of a real gradient color will be used. The default value is the current value of the widget option -forecolor .
-color gradient
The text uniform (possibly transparent) color. The first color of a real gradient color will be used. The default value is the current value of the widget option -forecolor .
-filled boolean
Specifies if the field background should be filled. The default value is false.
-fillpattern bitmap
The fill pattern used when filling the background. This attribute is overrided by the tile attribute. The default value is "".
-font font
The text font. The default value is the current value of the widget option -font .
-image image
An image to be displayed in the field. The image will be centered vertically in the field. The default value is "".
-relief relief
Specifies the relief to be drawn around the field, inside the border. The color of the relief is derived from the color in -backcolor . The default value is flat.
-reliefthickness dimension
Width of the relief drawn around the field. The default value is 0 which means that no relief should be drawn around the field.
-sensitive boolean
Specifies if the field should react to input events. The default value is true.
-text string
A line of text to be displayed in the field. The text will be centered vertically in the field. The default value is "".
-tile image
Specifies an image that will be tiled over the field background is the field is filled. This attribute has precedence over the -fillpattern attribute. The default value is "".
-visible boolean
Specifies if the field is displayed. The default value is true.
[front]