Reference for the Mosaic class WidgetSet::ToggleButton

WidgetSet::ToggleButton
Appearance
Checked
Icon
IconFrame
IconOffFrame
IconOffFrameActive
IconOffFrameDefault
IconOffFrameDisabled
IconOffFrameFocused
IconOnFrame
IconOnFrameActive
IconOnFrameDefault
IconOnFrameDisabled
IconOnFrameFocused
Label
LabelOff
LabelOn
OnEnter
OnLeave
OnPress
OnRelease
OnSwitchOff
OnSwitchOn
Outlet
ResignAfterHorizontalWipe
ResignAfterVerticalWipe
Core::Group
AlphaBlended
Buffered
Embedded
Enabled
Focus
Opacity
Visible
Add()
AddBehind()
BroadcastEvent()
BroadcastEventAtPosition()
CountDialogs()
CountViews()
DismissDialog()
DispatchEvent()
FadeGroup()
FindActiveDialogByClass()
FindCurrentDialog()
FindDialogByClass()
FindNextView()
FindPrevView()
FindSiblingView()
FindViewAtPosition()
FindViewInDirection()
FindViewWithinArea()
GetContentArea()
GetDialogAtIndex()
GetIndexOfDialog()
GetIndexOfView()
GetViewAtIndex()
GlobalPosition()
HasViewState()
Init()
InvalidateArea()
InvalidateViewState()
IsActiveDialog()
IsCurrentDialog()
IsDialog()
LocalPosition()
ObtainFocus()
PresentDialog()
Remove()
Restack()
RestackBack()
RestackBehind()
RestackTop()
SwitchToDialog()
UpdateLayout()
UpdateViewState()
Core::RectView
Bounds
Core::View
Layout
Owner
StackingPriority
ArrangeView()
ChangeViewState()
CursorHitTest()
Draw()
GetExtent()
GetRoot()
HandleEvent()
MoveView()

SEE ALSO

Using and customizing the Toggle Button (check box) widget.

This class implements a bistable 'toggle button' widget (a switch). When the user taps the button, the current state of the button represented by the boolean property Checked is toggled and signal is sent to one of the slot methods stored in the properties OnSwitchOff or OnSwitchOn. By connecting further slot methods to the properties OnPress, OnRelease, OnEnter and OnLeave you can react to other events triggered while the user interacts with the button.

Alternatively the property Outlet can refer to any other 'bool' property the widget should remain synchronized with. When the user toggles the button, the affected property is automatically updated to reflect the button's current state. On the other hand, when the referred property is modified by another one, the toggle button is automatically notified to remain in sync with the property.

This approach follows the Controller-View programming paradigm. Here the toggle button represents the 'View' and the property referred via 'Outlet' can be seen as a part of the 'Controller'.

During its lifetime the button remains always in one of the four states: 'disabled', 'default', 'focused' and 'active'. The state 'disabled' is true for every not available button (the property Enabled of the button is 'false'). Such buttons will ignore all user inputs. The state 'default' determines a button, which is ready to be touched by the user or ready to become focused. As soon as the button becomes focused, it switches in the state 'focused'. In this state the user can activate the button by pressing a key on the keyboard. Finally, the state 'active' is true, if the user actually interacts with the button (the button is pressed).

The exact look and feel of the toggle button is determined by the 'Toggle Button Configuration' object assigned to the property Appearance. The configuration object provides bitmaps, colors, fonts and other configuration parameters needed to construct and display the toggle button. Usually, you will manage in your project your own configuration objects and customize the toggle buttons according to your design expectations. Depending on the information provided in the associated configuration object, the toggle button will be composed of following views:

In particular application cases you can instruct the button to automatically resign and retarget the actual touch interaction to another touch handler (e.g. another widget) after the user has performed a horizontal wipe gesture (ResignAfterHorizontalWipe) or vertical wipe gesture (ResignAfterVerticalWipe). Using these properties several widgets can cooperate during an active user interaction even if these handler overlap each other.

If the button is actually focused, it can also be activated by pressing the keyboard key Core::KeyCode.Enter. In the configuration object you can specify another key code, if desired. To prevent the button from being able to be focused, specify in the configuration object the Core::KeyCode.NoKey as the code to activate the button.

For more details regarding the customization of the button see the description of WidgetSet::ToggleButtonConfig class.

property WidgetSet::ToggleButtonConfig Appearance = null;

The property 'Appearance' refers to a 'Toggle Button Config' object containing bitmaps, colors, fonts and further configuration attributes to customize this toggle button widget. By assigning a configuration object to the property 'Appearance', the toggle button automatically assumes the look and feel as determined in the properties of the configuration object.

If there is no configuration object associated to the toggle button (the property 'Appearance' is 'null') the toggle button limits to display the bitmap specified in the property Icon.

Please note, configuration objects can be shared among multiple toggle button widgets. When the properties of the configuration object change, all toggle buttons (connected actually to it) are notified and updated to assume the new appearance.

property bool Checked = false;

The property 'Checked' stores the current state of the toggle button. As long as the property is 'false', the widget is in switched-off state. In turn, initializing the property with the value 'true' causes the button to change in the switched-on state.

property Resources::Bitmap Icon = null;

The property 'Icon' refers to the bitmap object to display as icon in this toggle button widget. If the bitmap consists of more than one frame, the desired frame number can be determined by using the property IconFrame or individually for every button state by using the properties IconOffFrame, IconOnFrame, IconOffFrameDefault, IconOffFrameFocused, IconOffFrameActive, IconOffFrameDisabled, IconOnFrameDefault, IconOnFrameFocused, IconOnFrameActive and IconOnFrameDisabled.

If the bitmap is animated and the property IconOffFrameDefault, IconOffFrameFocused, IconOffFrameActive, IconOffFrameDisabled, IconOnFrameDefault, IconOnFrameFocused, IconOnFrameActive or IconOnFrameDisabled is initialized with the value -1, the animation will start automatically as soon as the button enters the corresponding state.

Per default, the icon is displayed centered within the toggle button area. You can modify the alignment of the icon, its margins, its opacity as well as its colors (if the specified bitmap is Alpha8) in the configuration object assigned to the property Appearance.

property int32 IconFrame = -1;

The property 'IconFrame' determines the frame number within the bitmap Icon to be displayed. Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

This property determines the icon frame number to be used regardless of the actual state of the button. By using the properties IconOffFrame, IconOffFrameActive, IconOffFrameDefault, IconOffFrameDisabled, IconOffFrameFocused, IconOnFrame, IconOnFrameActive, IconOnFrameDefault, IconOnFrameDisabled and IconOnFrameFocused you can specify different frame number for every button state.

property int32 IconOffFrame = -1;

The property 'IconOffFrame' determines the frame number within the bitmap Icon to be displayed when the button is actually switched-off (property Checked is 'false'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

This property determines the icon frame number to be used when the button is actually switched-off (property Checked is 'false') regardless of other button states. By using the properties IconOffFrameActive, IconOffFrameDefault, IconOffFrameDisabled, IconOffFrameFocused, IconOnFrame, IconOnFrameActive, IconOnFrameDefault, IconOnFrameDisabled and IconOnFrameFocused you can specify different frame number for every button state.

property int32 IconOffFrameActive = -1;

The property 'IconOffFrameActive' determines the frame number within the bitmap Icon to be displayed when the button is in the 'active' state (the user is actually touching the button or pressing a key on the keyboard the toggle button should react on) and it is actually switched-off (property Checked is 'false'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'active/switched-off' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOffFrameDefault = -1;

The property 'IconOffFrameDefault' determines the frame number within the bitmap Icon to be displayed when the button is in the 'default' state and it is actually switched-off (property Checked is 'false'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'default/switched-off' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOffFrameDisabled = -1;

The property 'IconOffFrameDisabled' determines the frame number within the bitmap Icon to be displayed when the button is in the 'disabled' state (its property Enabled is 'false') and it is actually switched-off (property Checked is 'false'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'disabled/switched-off' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOffFrameFocused = -1;

The property 'IconOffFrameFocused' determines the frame number within the bitmap Icon to be displayed when the button is in the 'focused' state (the button can react to keyboard events) and it is actually switched-off (property Checked is 'false'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'focused/switched-off' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOnFrame = -1;

The property 'IconOnFrame' determines the frame number within the bitmap Icon to be displayed when the button is actually switched-on (property Checked is 'true'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

This property determines the icon frame number to be used when the button is actually switched-on (property Checked is 'true') regardless of other button states. By using the properties IconOffFrame, IconOffFrameActive, IconOffFrameDefault, IconOffFrameDisabled, IconOffFrameFocused, IconOnFrameActive, IconOnFrameDefault, IconOnFrameDisabled and IconOnFrameFocused you can specify different frame number for every button state.

property int32 IconOnFrameActive = -1;

The property 'IconOnFrameActive' determines the frame number within the bitmap Icon to be displayed when the button is in the 'active' state (the user is actually touching the button or pressing a key on the keyboard the toggle button should react on) and it is actually switched-on (property Checked is 'true'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'active/switched-on' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOnFrameDefault = -1;

The property 'IconOnFrameDefault' determines the frame number within the bitmap Icon to be displayed when the button is in the 'default' state and it is actually switched-on (property Checked is 'true'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'default/switched-on' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOnFrameDisabled = -1;

The property 'IconOnFrameDisabled' determines the frame number within the bitmap Icon to be displayed when the button is in the 'disabled' state (its property Enabled is 'false') and it is actually switched-on (property Checked is 'true'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'disabled/switched-on' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property int32 IconOnFrameFocused = -1;

The property 'IconOnFrameFocused' determines the frame number within the bitmap Icon to be displayed when the button is in the 'focused' state (the button can react to keyboard events) and it is actually switched-on (property Checked is 'true'). Thus this property is applicable for multi-frame bitmaps only (see also Resources::Bitmap). If the desired frame is not available in the bitmap, no icon is shown.

If the property is initialized with the value -1 and the Icon bitmap is animated, the animation is automatically started as soon as the button enters the 'focused/switched-on' state. If the bitmap is not animated and the property is -1, the frame with number 0 is displayed.

property string Label = "";

The property 'Label' specifies the text to display as label in this toggle button widget. The desired font as well as the colors for all individual button states have to be specified in the configuration object assigned to the property Appearance. If there is no configuration object associated to this toggle button widget (the property Appearance is 'null'), no label is displayed.

Per default, the label is displayed centered within the toggle button area. You can modify the alignment of the label as well as its margins by specifying them in the configuration object.

This property determines the label to be used regardless of the actual state of the button. By using the properties LabelOff and LabelOn you can specify different labels for every button state.

property string LabelOff = "";

The property 'LabelOff' specifies the text to display as label in this toggle button widget when it is in the switched-off state (property Checked is 'false'). The desired font as well as the colors for all individual button states have to be specified in the configuration object assigned to the property Appearance. If there is no configuration object associated to this toggle button widget (the property Appearance is 'null'), no label is displayed.

Per default, the label is displayed centered within the toggle button area. You can modify the alignment of the label as well as its margins by specifying them in the configuration object.

property string LabelOn = "";

The property 'LabelOn' specifies the text to display as label in this toggle button widget when it is in the switched-on state (property Checked is 'true'). The desired font as well as the colors for all individual button states have to be specified in the configuration object assigned to the property Appearance. If there is no configuration object associated to this toggle button widget (the property Appearance is 'null'), no label is displayed.

Per default, the label is displayed centered within the toggle button area. You can modify the alignment of the label as well as its margins by specifying them in the configuration object.

property slot OnEnter = null;

The property 'OnEnter' can refer to a slot method, which will receive signals when while pressing the toggle button the user drags the finger so it leaves and enters the button area. Accordingly, the button assumes the 'active' state again (it is 'armed' now). In the associated slot method the implementation can handle the event.

This event is also triggered, if the button is focused and the user presses the key on the keyboard to activate the button.

property slot OnLeave = null;

The property 'OnLeave' can refer to a slot method, which will receive signals when while pressing the toggle button the user drags the finger so it leaves the button area. Accordingly, the button assumes the 'default' or 'focused' state again (it is not 'armed' anymore). In the associated slot method the implementation can handle the event.

This event is also triggered, if the button is focused and the user (after pressing a key on the keyboard to activate the button) releases this key again terminating so the interaction.

property slot OnPress = null;

The property 'OnPress' can refer to a slot method, which will receive a signal as soon as the user touches the toggle button or, if the button is focused, presses the key on the keyboard to activate the toggle button. Thereupon the method's logic will be executed.

In other words, this event is triggered at the beginning of the interaction between user and the button.

property slot OnRelease = null;

The property 'OnRelease' can refer to a slot method, which will receive a signal as soon as the user lifts the finger from the toggle button or, if the button was activated by preceding keyboard event, the user releases the key again. Thereupon the method's logic will be executed.

In other words, this event is triggered at the end of the interaction between user and the button.

property slot OnSwitchOff = null;

The property 'OnSwitchOff' can refer to a slot method, which will receive a signal as soon as the user has activated the button causing the button to change its state from switched-on to switched-off. Thereupon the method's logic will be executed. In the associated slot method you can evaluate the property Checked as reflecting the current switched-off/on state of the button.

The button is activated when the user (after touching the button) releases the button again while the finger was still within the button area. If the toggle button is controlled by keyboard events, the button is activated when the user (after pressing the corresponding key) releases it again.

property slot OnSwitchOn = null;

The property 'OnSwitchOn' can refer to a slot method, which will receive a signal as soon as the user has activated the button causing the button to change its state from switched-off to switched-on. Thereupon the method's logic will be executed. In the associated slot method you can evaluate the property Checked as reflecting the current switched-off/on state of the button.

The button is activated when the user (after touching the button) releases the button again while the finger was still within the button area. If the toggle button is controlled by keyboard events, the button is activated when the user (after pressing the corresponding key) releases it again.

property ^bool Outlet = null;

The property 'Outlet' can refer to any other 'bool' property the widget should remain synchronized with. When the user toggles the button, the affected property is automatically updated to reflect the button's current state. On the other hand, when the referred property is modified by another one, the toggle button is automatically notified to remain in sync with the property (the property Checked is updated to the value of the property referred in Outlet).

This approach follows the Controller-View programming paradigm. Here the toggle button represents the 'View' and the property referred via 'Outlet' can be seen as a part of the 'Controller'.

property bool ResignAfterHorizontalWipe = false;

The property 'ResignAfterHorizontalWipe' determines whether while interacting with the toggle button, the button may automatically resign and deflect the current processing of touch events (the current grab cycle) to another touch handler.

If this property is 'true' and the user performs a horizontal wipe gesture within the button area, the button searches for another touch handler (e.g. another widget) willing to take over the further event processing of the actual interaction. In other words, you use this property to specify that the toggle button is NOT interested to process the horizontal wipe gestures and thus other handler should take over.

property bool ResignAfterVerticalWipe = false;

The property 'ResignAfterVerticalWipe' determines whether while interacting with the toggle button, the button may automatically resign and deflect the current processing of touch events (the current grab cycle) to another touch handler.

If this property is 'true' and the user performs a vertical wipe gesture within the button area, the button searches for another touch handler (e.g. another widget) willing to take over the further event processing of the actual interaction. In other words, you use this property to specify that the toggle button is NOT interested to process the vertical wipe gestures and thus other handler should take over.