Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
BindSwitch Class Reference

Represents a toggle switch UI element in the Bind framework. More...

`#include <BindSwitch.hpp>`

Inheritance diagram for BindSwitch:

## Public Member Functions
| BindSwitch (const char *cstr)
| Constructor to create a `BindSwitch` with a custom label.
| BindSwitch ()
| Default constructor to create a `BindSwitch` with a default label ("Switch").
void | setLabel (const char *cstr)
| Sets the label text for the toggle switch.
void | setlabel (const char *cstr)
void | setCallback (void(*callback)(bool))
| Set the Callback function for the toggle switch.
void | invokeCallback (bool val)
uint16_t | getBytes (uint8_t *out) override
| Generates and returns the byte data representing the toggle switch configuration.

## Public Attributes
int16_t | x
| X-coordinate position of the toggle switch.
int16_t | y
| Y-coordinate position of the toggle switch.
uint8_t | cmdId = 0
| Command identifier. See the notes for possible cmdId values.
bool | value
| The current state (ON/OFF) of the toggle switch.
int16_t | fontSize
| Font size for the switch label.
int32_t | textColor
| Text color for the switch label.
Public Attributes inherited from BindView
int16_t | tag

## Detailed Description

Represents a toggle switch UI element in the Bind framework.

BindSwitch

The `BindSwitch` class allows you to create toggle switch UI elements within your Arduino projects to be shown in BindCanvas. You can customize the appearance and behavior of the switch, such as its position, label text, size, and colors. Users can interact with the switch to toggle its state, and you can capture and respond to these state changes.

Note
  Possible cmdId values for a BindView and corresponding effects:
  - BIND_ADD_OR_REFRESH_CMD: Adds the object to the canvas (screen) or refreshes the existing one.
  - BIND_DATA_ONLY_CMD: Refreshes the existing object without moving or resizing; updates data, such as text.
  - BIND_REMOVE_CMD: Removes the object from the canvas (screen).
  - BIND_DISABLE_CMD: Disables the object.
  - BIND_ENABLE_CMD: Enables the object.
  - BIND_HIDE_CMD: Hides the object.
  - BIND_VISIBLE_CMD: Restores the object's visibility.

Example usage:

- Create a toggle switch with specific settings.
- Set its position, label, and appearance properties.
- Register a callback function to handle state changes when users interact with the switch: `mySwitchObj.setCallback(mySwitchCallback)`.
- Synchronize the switch with the Bind framework using `bind.sync(mySwitchObj)` to enable user interactions.

Note: To receive touch events and user interactions, you must regularly call `bind.sync()` in your main loop.

See also
  Bind for more information on using Bind UI elements.

## Constructor & Destructor Documentation

## ◆ BindSwitch()

BindSwitch::BindSwitch | ( | const char * | cstr | ) |
| inline

Constructor to create a `BindSwitch` with a custom label.

Parameters

  cstr | The label text for the toggle switch.

## Member Function Documentation

## ◆ getBytes()

uint16_t BindSwitch::getBytes | ( | uint8_t * | out | ) |
| inline override virtual

Generates and returns the byte data representing the toggle switch configuration.

This function is meant for internal use by the Bind framework and should not be called directly by users. It serializes the toggle switch's properties into a byte array for communication with the Bind framework.

Parameters

  out | Pointer to the output byte array.

Returns
  The number of bytes written to the output array.

Reimplemented from BindView.

## ◆ setCallback()

void BindSwitch::setCallback | ( | void(*)(bool) | callback | ) |
| inline

Set the Callback function for the toggle switch.

This callback function is called when the toggle switch value is changed. The signature of the callback function should be like:

void callback(bool value)
BindSwitch::value
bool value
The current state (ON/OFF) of the toggle switch.
Definition BindSwitch.hpp:63

Parameters

  callback |

## ◆ setLabel()

void BindSwitch::setLabel | ( | const char * | cstr | ) |
| inline

Sets the label text for the toggle switch.

Parameters

  cstr | The label text for the toggle switch.

The documentation for this class was generated from the following files:

- BindSwitch.hpp
- Bind.cpp