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
OnUpdate
Outlet
ResignAfterHorizontalWipe
ResignAfterVerticalWipe
GetCurrentState()
GetTransitionEndState()
GetTransitionProgress()
GetTransitionStartState()
Core::Group
AlphaBlended
Buffered
ClipViews
DeriveEnabledState
Embedded
Enabled
Focus
Opacity
Visible
Add()
AddBehind()
BroadcastEvent()
BroadcastEventAtPosition()
CountDialogs()
CountViews()
DismissDialog()
DispatchEvent()
DrawBackground()
DrawForeground()
ExtendClipping()
FadeGroup()
FindActiveDialogByClass()
FindCurrentDialog()
FindDialogByClass()
FindNextView()
FindPrevView()
FindSiblingView()
FindViewAtPosition()
FindViewInDirection()
FindViewWithStackingPriority()
FindViewWithinArea()
GetContentArea()
GetDialogAtIndex()
GetIndexOfDialog()
GetIndexOfView()
GetMaximalSize()
GetMinimalSize()
GetViewAtIndex()
GlobalPosition()
HasViewState()
Init()
InvalidateArea()
InvalidateLayout()
InvalidateViewState()
IsActiveDialog()
IsCurrentDialog()
IsDialog()
LocalPosition()
ObtainFocus()
PresentDialog()
Remove()
RemoveAll()
Restack()
RestackBack()
RestackBehind()
RestackTop()
SwitchToDialog()
UpdateLayout()
UpdateViewState()
Core::RectView
Bounds
Core::View
Layout
Owner
StackingPriority
AdjustDrawingArea()
ArrangeView()
ChangeViewState()
CursorHitTest()
Draw()
GetClipping()
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 Model-View-Controller (MVC) programming paradigm. Here the toggle button represents the 'View' and 'Controller' and the property referred via 'Outlet' can be seen as a part of the 'Model'.

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.

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.

The toggle button widget provides an additional set of methods useful to query the actual state of the widget (GetCurrentState(), GetTransitionStartState(), GetTransitionEndState(), GetTransitionProgress()). These methods can be invoked from a slot method assigned to the property OnUpdate. In this manner you can automatically arrange and updated additional decoration according to the actual state of the widget.

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.

method WidgetSet::CommonState GetCurrentState();

The method GetCurrentState() returns the state of the widget (OffDefault, OffDisabled, OffFocused, OffActive, OnDefault, OnDisabled, OnFocused or OnActive) according to the latest user interaction by additionally taking in account the widgets current Checked state (On or Off).

The obtained state information is useful to update decorations associated to the widget if those should depend on the widget's current state. For more details concerning the decorations, see the property OnUpdate.

Please note, if the widget is configured to perform animations during state transitions, you can use the methods GetTransitionStartState(), GetTransitionEndState() and GetTransitionProgress() to obtain information concerning the animation.

method WidgetSet::CommonState GetTransitionEndState();

The method GetTransitionEndState() returns the state of the widget (OffDefault, OffDisabled, OffFocused, OffActive, OnDefault, OnDisabled, OnFocused or OnActive) valid after the actual state transition will finish and by additionally taking in account the Checked state (On or Off) the widget will assume finally.

This information, together with the values returned by the methods GetTransitionStartState() and GetTransitionProgress(), can be useful to calculate the state of decoration views which depend on the progress of the animation. For more details concerning the decorations, see the property OnUpdate.

If the widget is not configured to perform any state transitions with animations or there is no transition in progress, GetTransitionEndState() returns the widget's latest state equal to the value returned by the method GetCurrentState().

method float GetTransitionProgress();

The method GetTransitionProgress() returns a value in range 0.0..1.0 according to the progress of the actually performed state transition. The start and the end states for the transition can be queried by the methods GetTransitionStartState() and GetTransitionEndState(). The obtained information can be useful to calculate the state of decoration views which depend on the progress of the animation. For more details concerning the decorations, see the property OnUpdate.

If the widget is not configured to perform any state transitions with animations or there is no transition in progress, GetTransitionProgress() returns the value 0.0.

method WidgetSet::CommonState GetTransitionStartState();

The method GetTransitionStartState() returns the state of the widget (OffDefault, OffDisabled, OffFocused, OffActive, OnDefault, OnDisabled, OnFocused or OnActive) valid just before the actual state transition begun by additionally taking in account the Checked state (On or Off) the widget had at this time.

This information, together with the values returned by the methods GetTransitionEndState() and GetTransitionProgress(), can be useful to calculate the state of decoration views which depend on the progress of the animation. For more details concerning the decorations, see the property OnUpdate.

If the widget is not configured to perform any state transitions with animations or there is no transition in progress, GetTransitionStartState() returns the widget's latest state equal to the value returned by the method GetCurrentState().

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 slot OnUpdate = null;

The property 'OnUpdate' can refer to a slot method, which should be invoked by the widget when its state changes (or more generally, when the user interacts with the widget). This method is intended to update decorations associated to this toggle button widget.

From the implementation of the slot method you can invoke the methods GetCurrentState(), GetTransitionStartState(), GetTransitionEndState() and GetTransitionProgress() to query the current state of the widget.

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 Model-View-Controller (MVC) programming paradigm. Here the toggle button represents the 'View' and 'Controller' and the property referred via 'Outlet' can be seen as a part of the 'Model'.

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.