A text, bitmap, or image label
PtWidget --> PtBasic --> PtLabel
For more information, see the diagram of the widget hierarchy.
<photon/PtLabel.h>
The PtLabel class provides a text string, bitmap, or image for labeling other widgets. When you use PtLabel to display a bitmap or image, you can have text pop up in a balloon to provide further meaning to the image.
A text string in a PtLabel widget.
As their name implies, labels are tags attached to objects to identify their name or nature. Label widgets are usually positioned beside the other widget they're describing, although in some cases (e.g. lists), the label will appear above the object.
There's no limit to the number of places you may wish to use label objects, but the most frequent use is to identify the name of an input field. For example, a mail program must provide input fields for indicating the recipient and the subject of a mail message being composed. The label widget lets you attach "To:" and "Subject:" tags to those input fields.
Labels aren't restricted to textual tags either. If you want to put a graphical representation such as an icon beside an object, you may use an image as the label.
You create labels using the PtLabel widget class. You can use text and images for the label. The default label type is a null-terminated text string.
To specify the type of label you want, you must use the Pt_ARG_LABEL_TYPE resource. The possible values for this resource are:
The data for the label is specified in different ways for each type. Different resources are used for the label data for different label types. This is particularly useful when you wish to switch quickly between image labels and text labels, so you can give the user a choice between using icons and textual descriptions of operations.
At the push of a button, the user can switch your interface from an iconic representation of commands (like the palette in the Photon Application Builder) to a textual representation of the same labels. The label is switched from an icon to text simply by changing the label type resource.
When the label type is textual, the label widget gets the text to be displayed from the Pt_ARG_TEXT_STRING resource.
To specify the font the label should be drawn with when text labels are used, set the resource Pt_ARG_TEXT_FONT to the name of the font you want.
The label widget defines its own margins in addition to the margin width defined by the PtBasic widget class. There are separate left, right, top, and bottom margins, which are specified using these resources:
These margins are cumulative, so that the actual margin of one edge of the widget is the corresponding resource value added to the margin width.
The text label may be aligned independently to the left or right margin, or centered horizontally within the margins of the widget. The Pt_ARG_HORIZONTAL_ALIGNMENT resource controls this behavior. The values to specify for this horizontal alignment are:
You can also control the vertical alignment, i.e. whether the text is aligned to the widget's top or bottom margin, or centered vertically between the two margins. The Pt_ARG_VERTICAL_ALIGNMENT resource controls this behavior. The values to specify for the vertical alignment are:
Normally, the text displayed in the label widget will be aligned to the widget's top and left margins. The baseline is calculated by adding the ascender of the label font to the top margin. When text is aligned to the bottom of the widget, the baseline is calculated by subtracting the descender of the label font from the widget's bottom margin.
You can align the baselines of labels drawn with different fonts by selecting bottom alignment for each of the widgets and choosing appropriate margins for them. In this case, make sure you specify a widget height large enough to accommodate the height of the largest font used.
The desired baseline for your aligned widgets will be adjusted by the size of the maximum descender of all the fonts used. For each label, add the difference between this descender and the descender of that label's font, then add this difference to the widget's bottom margin. Keep track of this value so that you can recalculate the correct margin setting if you want to change the base margin or the font later on.
When the label is an image, the label widget gets the image from the Pt_ARG_LABEL_DATA resource, which contains a pointer to an image structure, of type PhImage_t, which is described in the Photon Library Reference.
The members of the image structure used by the label and button widgets are:
Images can be palette-based or raw. Palette-based images, including bitmaps, have a color palette that serves as a lookup table for determining what color should be displayed for each pixel. Each pixel in the image is encoded as an index into the lookup table, and the pixel is displayed using the color contained in the corresponding table entry.
Raw images have actual RGB color values encoded in the image data.
More than one pixel may be encoded in each byte of the image data, so image-scan lines are padded out to a byte boundary.
Bitmaps are encoded with 1 bit-per-pixel. The bit ordering is most significant bit first. The two types of bitmap are:
The other types of palette-based images are:
Raw images are all encoded using 16, 24, or 32 bits-per-pixel. The types of raw images are:
For more information about manipulating images and image data formats, see the Photon Programmer's Guide.
Balloons are a very handy feature of the PtLabel widget class. You use a balloon to display a line of text when the user's pointer pauses on top of a widget for more than a second.
This can be very useful in an application with a lot of labels or buttons containing iconic images. Whenever the user pauses on an icon, a little text box will pop up beside it to display the name or action the icon represents.
To use balloons with label class widgets:
The Pt_ARG_TEXT_STRING resource defines the text displayed in the balloon. If the entire string is visible within the widget, you probably don't need to set the Pt_SHOW_BALLOON flag. If the label has been truncated or is currently displaying an iconic image, you can set the flag and the balloon feature will be automatically enabled for the widget.
Resource | C type | Pt type | Default |
---|---|---|---|
Pt_ARG_ACCEL_KEY | char * | String | NULL |
Pt_ARG_BALLOON_COLOR | PgColor_t | Scalar | Pg_BLACK |
Pt_ARG_BALLOON_FILL_COLOR | PgColor_t | Scalar | Pt_BALLOONCOLOR |
Pt_ARG_BALLOON_POSITION | short | Scalar | Pt_BALLOON_RIGHT |
Pt_ARG_HORIZONTAL_ALIGNMENT | unsigned char | Scalar | Pt_LEFT |
Pt_ARG_LABEL_BALLOON | PtWidget_t * (*)() | Pointer | Pt_INFLATE_BALLOON |
Pt_ARG_LABEL_DATA | void * | Alloc | NULL |
Pt_ARG_LABEL_FLAGS | char | Flag | Pt_LABEL_SELECT_SHIFT |
Pt_ARG_LABEL_TYPE | char | Scalar | Pt_Z_STRING |
Pt_ARG_LINE_SPACING | ushort_t | Scalar | 0 |
Pt_ARG_MARGIN_BOTTOM | unsigned short | Scalar | 0 |
Pt_ARG_MARGIN_LEFT | unsigned short | Scalar | 0 |
Pt_ARG_MARGIN_RIGHT | unsigned short | Scalar | 0 |
Pt_ARG_MARGIN_TOP | unsigned short | Scalar | 0 |
Pt_ARG_TEXT_FONT | char * | String | "helv12" |
Pt_ARG_TEXT_STRING | char * | String | NULL |
Pt_ARG_UNDERLINE1 | unsigned short | Scalar | Pg_BLACK |
Pt_ARG_UNDERLINE2 | unsigned short | Scalar | Pg_TRANSPARENT |
Pt_ARG_UNDERLINE_TYPE | unsigned short | Scalar | Pt_NO_ULINE |
Pt_ARG_VERTICAL_ALIGNMENT | unsigned char | Scalar | Pt_CENTER |
C type | Pt type | Default |
---|---|---|
char * | String | NULL |
Lets you underline the accelerator key within the widget's text string. You typically use this resource for hotkeys.
C type | Pt type | Default |
---|---|---|
PgColor_t | Scalar | Pg_BLACK |
Defines the balloon's text color.
C type | Pt type | Default |
---|---|---|
PgColor_t | Scalar | Pt_BALLOONCOLOR |
Defines the balloon's fill color.
C type | Pt type | Default |
---|---|---|
short | Scalar | Pt_BALLOON_RIGHT |
Indicates where the label text will pop up. If Pt_ARG_LABEL_TYPE is Pt_TEXT_IMAGE, this reource controls the positioning of the text and image elements relative to each other. Possible values:
C type | Pt type | Default |
---|---|---|
unsigned char | Scalar | Pt_LEFT |
The horizontal alignment for the text string. Possible values:
C type | Pt type | Default |
---|---|---|
PtWidget_t * (*)() | Pointer | Pt_INFLATE_BALLOON |
By default, when a user pauses the pointer over this widget, the widget will display a small yellow balloon. If you want to change the look or default text of the balloon, you can use this resource to override the default inflate function.
Here's a prototype of the inflate function:
PtWidget_t * InflateBalloon( PtWidget_t *window, PtWidget_t *widget, int position, char *text, char *font, PgColor_t fill_color, PgColor_t text_color );
where:
You can use the supplied values in your inflate function or ignore them and use your own values.
C type | Pt type | Default |
---|---|---|
void * | Alloc | NULL |
A pointer. If the label type (see Pt_ARG_LABEL_TYPE, below) is Pt_IMAGE, this resource is used to pass data to the widget.
Remember that this is an Alloc resource. When you set this resource, the widget copies the PhImage_t structure but not the data pointed to by the members of the structure. After setting this resource, you can free() the PhImage_t if you don't need it, but don't free() the members of it. |
C type | Pt type | Default |
---|---|---|
char | Flag | Pt_LABEL_SELECT_SHIFT |
Possible values:
C type | Pt type | Default |
---|---|---|
char | Scalar | Pt_Z_STRING |
The type of information displayed by the label. Possible values:
Set the flags member of the PhImage_t structure to:
Ph_RELEASE_IMAGE | Ph_RELEASE_PALETTE | Ph_RELEASE_TRANSPARENCY_MASK | Ph_RELEASE_GHOST_BITMAP
before providing the image to the widget. If you do this, the memory used for the image is released when the widget is unrealized or destroyed.
C type | Pt type | Default |
---|---|---|
ushort_t | Scalar | 0 |
The space, in pixels, between the lines of text in the label.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The amount of space between the bottom of the label's canvas and the canvas defined by the basic widget.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The amount of space between the left side of the label's canvas and the canvas defined by the basic widget.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The amount of space between the right side of the label's canvas and the canvas defined by the basic widget.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | 0 |
The amount of space between the top of the label's canvas and the canvas defined by the basic widget.
C type | Pt type | Default |
---|---|---|
char * | String | "helv12" |
The font used for the label's text string; see PgSetFont().
C type | Pt type | Default |
---|---|---|
char * | String | NULL |
The text string to be displayed if Pt_ARG_LABEL_TYPE is Pt_Z_STRING or Pt_TEXT_IMAGE.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | Pg_BLACK |
The underline color for the first line.
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | Pg_TRANSPARENT |
The underline color for the second line (used to create thick or beveled underlines).
C type | Pt type | Default |
---|---|---|
unsigned short | Scalar | Pt_NO_ULINE |
The type of underline. Possible values:
C type | Pt type | Default |
---|---|---|
unsigned char | Scalar | Pt_CENTER |
The vertical alignment for the text string. Possible values:
If the widget modifies an inherited resource, the "Default override" column indicates the new value. This modification affects any subclasses of the widget.