Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
Button Class Reference

Abstract class that provides basic button functionality. More...

#include <Button.h>

Inheritance diagram for Button:
TextBoxButton ToggleButton MomentaryButton

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ callback_type

Type definition that defines when the callback function is called relative to button press/release.

Enumerator
ON_PRESS 
ON_RELEASE 

Constructor & Destructor Documentation

◆ Button()

Button::Button ( const char * buttonName,
Canvas & DestCanvas,
uint16_t dest_x,
uint16_t dest_y,
uint16_t width,
uint16_t height,
callback_type whenCallback )
inline

Constructor for creating a Button object.

Parameters
[in]buttonNameString containing the name of the button (used for error messages)
[in]DestCanvasDestination canvas where the button is to be placed
[in]dest_xUpper Left X coordinate within DestCanvas where the button is to be placed
[in]dest_yUpper Left Y coordinate within DestCanvas where the button is to be placed
[in]widthWidth of the button
[in]heightHeight of the button
[in]whenCallbackDefines when the callback function is called (on press or on release)

◆ ~Button()

virtual Button::~Button ( void )
virtualdefault

Default destructor.

Parameters
None.

Member Function Documentation

◆ _changeCallback()

void Button::_changeCallback ( callback_type type)
inlineprotected

Convenience method that changes when the callback is called.

Parameters
[in]typeNew callback type

◆ _registerButtonStates()

void Button::_registerButtonStates ( ButtonState ** buttonStatePtrArr,
uint8_t numStates )
protected

Registers the ButtonState objects that define this button.

Parameters
[in]buttonStatePtrArrArray of pointers to ButtonState objects
[in]numStatesNumber of states defined in buttonStatePtrArr

Button will "manage" the ButtonStates that have been registered via this method.

◆ _validateObject()

void Button::_validateObject ( void )
protected

Validates that all ButtonState objects have been defined.

Parameters
None.

◆ begin()

void Button::begin ( void )
virtual

Initializes the button. This method should be called before first use.

Parameters
None.

This method loads the button imagery from the source canvas, making the imagery available for use.

Reimplemented in TextBoxButton, and ToggleButton.

◆ disable()

void Button::disable ( void )
inline

Disables the button, so that it ignores button presses.

Parameters
None.

◆ draw() [1/2]

void Button::draw ( Canvas & newCanvas)
inline

Draws the image from the current ButtonState onto the specified canvas.

Parameters
[in]newCanvasCanvas where the button is to be drawn

◆ draw() [2/2]

void Button::draw ( void )
inline

Draws the image from the current ButtonState onto the destination canvas.

Parameters
None.

◆ enable()

void Button::enable ( void )
inline

Enables the button, making it accept button presses.

Parameters
None.

◆ height()

uint16_t Button::height ( void ) const
inline

Returns the height of the button in pixels.

Parameters
None.
Returns
Height of Button

◆ isEnabled()

bool Button::isEnabled ( void ) const
inline

Indicates whether the Button is enabled.

Parameters
None.
Returns
True if enabled, false otherwise.

◆ nextState()

void Button::nextState ( void )
inline

Advances the button to the next state.

Parameters
None.

◆ press()

bool Button::press ( FT5316::TouchLocation loc)
virtual

Presses the button if loc is within the bounds of the button.

Parameters
[in]locx-y coordinate where the TFT screen has been touched

◆ release()

void Button::release ( void )
virtual

Called when the button is released.

Parameters
None.

Reimplemented in MomentaryButton.

◆ setState()

void Button::setState ( uint8_t state)
inline

Sets the button to the specified state.

Parameters
[in]stateState to which the button is to be set

◆ state()

uint8_t Button::state ( void ) const
inline

Returns the current state of the button.

Parameters
None.
Returns
State of the button

◆ width()

uint16_t Button::width ( void ) const
inline

Returns the width of the button in pixels.

Parameters
None.
Returns
Width of Button

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