Skip to content

Commit

Permalink
added button enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
ihakov2 committed Oct 26, 2023
1 parent 9fbafe4 commit 5d22d2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 14 additions & 0 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,20 @@ void Adafruit_GFX_Button::setLabel(char *label) {
@return button label char pointer
*/
char *Adafruit_GFX_Button::getLabel() { return _label; }

/**********************************************************************/
/*!
@brief Set the button to enable/disable
@param enable boolean true to enable, false to disable
@param fillColor uint16_t set button fillColor
*/
/**********************************************************************/
void Adafruit_GFX_Button::setEnabled(bool enable, uint16_t fillColor) {
_enabled = enable;
_fillcolor = fillColor;
drawButton();
}

// -------------------------------------------------------------------------

// GFXcanvas1, GFXcanvas8 and GFXcanvas16 (currently a WIP, don't get too
Expand Down
16 changes: 13 additions & 3 deletions Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class Adafruit_GFX_Button {
/**********************************************************************/
void press(bool p) {
laststate = currstate;
currstate = p;
currstate = p & _enabled;
}

bool justPressed();
Expand All @@ -294,8 +294,18 @@ class Adafruit_GFX_Button {
@returns True if pressed
*/
/**********************************************************************/
bool isPressed(void) { return currstate; };
bool isPressed(void) { return currstate; };

/**********************************************************************/
/*!
@brief Check whether the button is enabled
@returns True if enabled
*/
/**********************************************************************/
bool isEnabled(void) { return _enabled; }

void setEnabled(bool enable, uint16_t fillColor);

private:
Adafruit_GFX *_gfx;
int16_t _x1, _y1; // Coordinates of top-left corner
Expand All @@ -305,7 +315,7 @@ class Adafruit_GFX_Button {
uint16_t _outlinecolor, _fillcolor, _textcolor;
char _label[10];

bool currstate, laststate;
bool currstate, laststate, _enabled = true;
};

/// A GFX 1-bit canvas context for graphics
Expand Down

0 comments on commit 5d22d2c

Please sign in to comment.