This commit is contained in:
ILDUS HAKOV 2024-10-01 11:59:19 -04:00 committed by GitHub
commit 61c032eca0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 2 deletions

View File

@ -1726,6 +1726,37 @@ bool Adafruit_GFX_Button::justPressed() { return (currstate && !laststate); }
/**************************************************************************/
bool Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); }
/**************************************************************************/
/*!
@brief Set label to button object.
@param label char pointer to new button label
*/
void Adafruit_GFX_Button::setLabel(char *label) {
strncpy(_label, label, 9);
_label[9] = 0;
drawButton();
}
/**************************************************************************/
/*!
@brief Get button 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;
currstate = (enable ? currstate : false);
drawButton();
}
// -------------------------------------------------------------------------
// GFXcanvas1, GFXcanvas8 and GFXcanvas16 (currently a WIP, don't get too

View File

@ -271,6 +271,8 @@ public:
uint8_t textsize_y);
void drawButton(bool inverted = false);
bool contains(int16_t x, int16_t y);
char *getLabel();
void setLabel(char *label);
/**********************************************************************/
/*!
@ -280,7 +282,7 @@ public:
/**********************************************************************/
void press(bool p) {
laststate = currstate;
currstate = p;
currstate = p & _enabled;
}
bool justPressed();
@ -294,6 +296,16 @@ public:
/**********************************************************************/
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
@ -303,7 +315,7 @@ private:
uint16_t _outlinecolor, _fillcolor, _textcolor;
char _label[10];
bool currstate, laststate;
bool currstate, laststate, _enabled = true;
};
/// A GFX 1-bit canvas context for graphics