Abstract class that provides basic button functionality. More...
#include <Button.h>
Public Types | |
| enum | callback_type { ON_PRESS , ON_RELEASE } |
| Type definition that defines when the callback function is called relative to button press/release. More... | |
Public Member Functions | |
Constructors and Destructors | |
| Button (const char *buttonName, Canvas &DestCanvas, uint16_t dest_x, uint16_t dest_y, uint16_t width, uint16_t height, callback_type whenCallback) | |
| Constructor for creating a Button object. | |
| virtual | ~Button (void)=default |
| Default destructor. | |
General Methods | |
| virtual void | begin (void) |
| Initializes the button. This method should be called before first use. | |
| virtual bool | press (FT5316::TouchLocation loc) |
Presses the button if loc is within the bounds of the button. | |
| virtual void | release (void) |
| Called when the button is released. | |
| void | enable (void) |
| Enables the button, making it accept button presses. | |
| void | disable (void) |
| Disables the button, so that it ignores button presses. | |
| void | setState (uint8_t state) |
| Sets the button to the specified state. | |
| void | nextState (void) |
| Advances the button to the next state. | |
| void | draw (void) |
| Draws the image from the current ButtonState onto the destination canvas. | |
| void | draw (Canvas &newCanvas) |
| Draws the image from the current ButtonState onto the specified canvas. | |
Accessor Methods | |
| bool | isEnabled (void) const |
| Indicates whether the Button is enabled. | |
| uint16_t | width (void) const |
| Returns the width of the button in pixels. | |
| uint16_t | height (void) const |
| Returns the height of the button in pixels. | |
| uint8_t | state (void) const |
| Returns the current state of the button. | |
Protected Member Functions | |
| void | _validateObject (void) |
| Validates that all ButtonState objects have been defined. | |
| void | _registerButtonStates (ButtonState **buttonStatePtrArr, uint8_t numStates) |
| Registers the ButtonState objects that define this button. | |
| void | _changeCallback (callback_type type) |
| Convenience method that changes when the callback is called. | |
Abstract class that provides basic button functionality.
This is the base class for all buttons. This class manages the button states and provides methods for pressing, releasing, enabling, and disabling the button. Derived classes will define how many states the button has and will provide the ButtonState objects that define the appearance and functionality of each state.
|
inline |
Constructor for creating a Button object.
| [in] | buttonName | String containing the name of the button (used for error messages) |
| [in] | DestCanvas | Destination canvas where the button is to be placed |
| [in] | dest_x | Upper Left X coordinate within DestCanvas where the button is to be placed |
| [in] | dest_y | Upper Left Y coordinate within DestCanvas where the button is to be placed |
| [in] | width | Width of the button |
| [in] | height | Height of the button |
| [in] | whenCallback | Defines when the callback function is called (on press or on release) |
|
virtualdefault |
Default destructor.
|
inlineprotected |
Convenience method that changes when the callback is called.
| [in] | type | New callback type |
|
protected |
Registers the ButtonState objects that define this button.
| [in] | buttonStatePtrArr | Array of pointers to ButtonState objects |
| [in] | numStates | Number of states defined in buttonStatePtrArr |
Button will "manage" the ButtonStates that have been registered via this method.
|
protected |
Validates that all ButtonState objects have been defined.
|
virtual |
Initializes the button. This method should be called before first use.
This method loads the button imagery from the source canvas, making the imagery available for use.
Reimplemented in TextBoxButton, and ToggleButton.
|
inline |
Disables the button, so that it ignores button presses.
|
inline |
Draws the image from the current ButtonState onto the specified canvas.
| [in] | newCanvas | Canvas where the button is to be drawn |
|
inline |
Draws the image from the current ButtonState onto the destination canvas.
|
inline |
Enables the button, making it accept button presses.
|
inline |
|
inline |
|
inline |
Advances the button to the next state.
|
virtual |
Presses the button if loc is within the bounds of the button.
| [in] | loc | x-y coordinate where the TFT screen has been touched |
|
virtual |
|
inline |
Sets the button to the specified state.
| [in] | state | State to which the button is to be set |
|
inline |
Returns the current state of the button.
|
inline |