[Previous] [Contents] [Index] [Next]

PtToggleButton

A toggle switch that's either off or on

Class hierarchy:

PtWidget --> PtBasic --> PtLabel --> PtToggleButton

For more information, see the diagram of the widget hierarchy.

PhAB icon:

PtToggleButton button in PhAB

Public header:

<photon/PtToggleButton.h>

Description:

A PtToggleButton widget is like a toggle switch, although it behaves like a button. It has on and off states, and pressing the button inverts the current state of the button.


PtToggleButton


Various button styles supported by PtToggleButton.


Creating toggle buttons

Like PtButton pushbuttons, toggle buttons inherit resources from the PtLabel class. Therefore, you specify the label for toggle buttons the same way you do for label and button widget classes.

A toggle button is displayed as a button with its label beside it. The button is either set or unset. Normally the button will appear recessed when it's set. You can control this appearance with the Pt_ARG_SET_COLOR resource, which specifies the fill color for the button's interior when the button is set. This resource is ignored if the value of the Pt_ARG_SET_FILL resource isn't set to Pt_TRUE.

To determine whether or not the button is set, check the:

Grouping radio buttons

A group can control how several toggle buttons behave together. Toggles placed within a group can behave like the channel selector buttons on an analog car radio. Only one of the buttons can be set at any given time. Selecting any button to set it automatically clears the button that's currently set.

To make the group widget enforce radio button behavior in its toggle button children, you must set the Pt_GROUP_EXCLUSIVE bit within the Pt_ARG_GROUP_FLAGS resource of the group.

By default, a toggle button indicator displays the toggle's state as a raised or recessed square. When the toggle is set, the square is recessed. If you want a different appearance, consider a raised or recessed diamond. For this appearance, set the Pt_ARG_INDICATOR_TYPE resource to Pt_ONE_OF_MANY on each of the toggle buttons that are placed in the group with radio button behavior.

The following example shows how to create a group of three radio buttons, giving each the appropriate appearance:

PtSetArg ( &argt[n], Pt_ARG_GROUP_FLAGS, Pt_TRUE, Pt_GROUP_EXCLUSIVE ); 
n++;
PtSetArg ( &argt[n], Pt_ARG_GROUP_ORIENTATION, Pt_GROUP_VERTICAL, 0 ) ;
n++;
group = PtCreateWidget (PtGroup, parent, n, argt );
PtSetArg ( &argt[0], Pt_ARG_TEXT_STRING, "Button", 0 ) ;

PtCreateWidget ( PtButton, parent, 1, argt ) ;
PtCreateWidget ( PtButton, parent, 1, argt ) ;
PtCreateWidget ( PtButton, parent, 1, argt ) ;

PtRealizeWidget ( group ) ;

New resources:

Resource C type Pt type Default
Pt_ARG_INDICATOR_COLOR PgColor_t Scalar Pg_GRAY
Pt_ARG_INDICATOR_DEPTH unsigned short Scalar 2
Pt_ARG_INDICATOR_HEIGHT unsigned short Scalar See below
Pt_ARG_INDICATOR_TYPE unsigned char Scalar Pt_N_OF_MANY
Pt_ARG_INDICATOR_WIDTH unsigned short Scalar See below
Pt_ARG_SET_COLOR PgColor_t Scalar PgGray(170)
Pt_ARG_SET_FILL unsigned char Scalar Pt_TRUE
Pt_ARG_SPACING unsigned short Scalar 4

Pt_ARG_INDICATOR_COLOR

C type Pt type Default
PgColor_t Scalar Pg_GRAY

The default fill color for the toggle button's indicator.

Pt_ARG_INDICATOR_DEPTH

C type Pt type Default
unsigned short Scalar 2

The border width, in pixels, of the indicator box.

Pt_ARG_INDICATOR_HEIGHT

C type Pt type Default
unsigned short Scalar See below

The height of the indicator box. By default, the height is determined by the font size.

Pt_ARG_INDICATOR_TYPE

C type Pt type Default
unsigned char Scalar Pt_N_OF_MANY

Determines how the indicator is drawn. Possible values:

Here's how these types look, both set and unset: PtToggleButton

Pt_ARG_INDICATOR_WIDTH

C type Pt type Default
unsigned short Scalar See below

The width of the indicator box. By default, the width is determined by the font size.

Pt_ARG_SET_COLOR

C type Pt type Default
PgColor_t Scalar PgGray(170)

The background color used when the button is set (pressed in).

Pt_ARG_SET_FILL

C type Pt type Default
unsigned char Scalar Pt_TRUE

Indicates whether or not Pt_ARG_SET_COLOR will be used. Possible values:

Pt_ARG_SPACING

C type Pt type Default
unsigned short Scalar 4

The distance in pixels between the toggle indicator and the text label.

Inherited resources:

If the widget modifies an inherited resource, the "Default override" column indicates the new value. This modification affects any subclasses of the widget.

Resource Inherited from Default override
Pt_ARG_ACCEL_KEY PtLabel
Pt_ARG_AREA PtWidget
Pt_ARG_BALLOON_COLOR PtLabel
Pt_ARG_BALLOON_FILL_COLOR PtLabel
Pt_ARG_BALLOON_POSITION PtLabel
Pt_ARG_BANDWIDTH_THRESHOLD PtBasic Not used by this class.
Pt_ARG_BITMAP_CURSOR PtWidget
Pt_ARG_BORDER_WIDTH PtWidget 0
Pt_ARG_BOT_BORDER_COLOR PtBasic
Pt_ARG_COLOR PtBasic
Pt_ARG_CURSOR_COLOR PtWidget
Pt_ARG_CURSOR_TYPE PtWidget
Pt_ARG_DATA PtWidget
Pt_ARG_DIM PtWidget
Pt_ARG_EFLAGS PtWidget
Pt_ARG_FILL_COLOR PtBasic
Pt_ARG_FILL_PATTERN PtBasic
Pt_ARG_FLAGS PtWidget |=Pt_SELECTABLE|
Pt_TOGGLE
Pt_ARG_HELP_TOPIC PtWidget
Pt_ARG_HIGHLIGHT_ROUNDNESS PtBasic
Pt_ARG_HORIZONTAL_ALIGNMENT PtLabel
Pt_ARG_LABEL_BALLOON PtLabel
Pt_ARG_LABEL_DATA PtLabel
Pt_ARG_LABEL_FLAGS PtLabel
Pt_ARG_LABEL_TYPE PtLabel
Pt_ARG_LINE_SPACING PtLabel
Pt_ARG_MARGIN_BOTTOM PtLabel
Pt_ARG_MARGIN_HEIGHT PtBasic
Pt_ARG_MARGIN_LEFT PtLabel
Pt_ARG_MARGIN_RIGHT PtLabel
Pt_ARG_MARGIN_TOP PtLabel
Pt_ARG_MARGIN_WIDTH PtBasic
Pt_ARG_POS PtWidget
Pt_ARG_RESIZE_FLAGS PtWidget
Pt_ARG_TEXT_FONT PtLabel
Pt_ARG_TEXT_STRING PtLabel
Pt_ARG_TOP_BORDER_COLOR PtBasic
Pt_ARG_TRANS_PATTERN PtBasic
Pt_ARG_UNDERLINE_TYPE PtLabel
Pt_ARG_UNDERLINE1 PtLabel
Pt_ARG_UNDERLINE2 PtLabel
Pt_ARG_USER_DATA PtWidget
Pt_ARG_VERTICAL_ALIGNMENT PtLabel
Pt_CB_ACTIVATE PtBasic
Pt_CB_ARM PtBasic
Pt_CB_BLOCKED PtWidget
Pt_CB_DESTROYED PtWidget
Pt_CB_DISARM PtBasic
Pt_CB_GOT_FOCUS PtBasic
Pt_CB_HOTKEY PtWidget
Pt_CB_LOST_FOCUS PtBasic
Pt_CB_MENU PtBasic
Pt_CB_RAW PtWidget
Pt_CB_REALIZED PtWidget
Pt_CB_REPEAT PtBasic
Pt_CB_UNREALIZED PtWidget

[Previous] [Contents] [Index] [Next]