From 225eb1668b8999e96e5b0161e1175e8fe77dee5d Mon Sep 17 00:00:00 2001 From: Just Call Me Koko <25190487+justcallmekoko@users.noreply.github.com> Date: Sat, 1 Feb 2020 13:26:45 -0500 Subject: [PATCH] Add configurable drawButton function --- Extensions/Button.cpp | 29 +++++++++++++++++++++++++++++ Extensions/Button.h | 1 + 2 files changed, 30 insertions(+) diff --git a/Extensions/Button.cpp b/Extensions/Button.cpp index 2aefee5..8f26dfc 100644 --- a/Extensions/Button.cpp +++ b/Extensions/Button.cpp @@ -61,6 +61,35 @@ void TFT_eSPI_Button::drawButton(bool inverted) { _gfx->setTextDatum(tempdatum); } +void TFT_eSPI_Button::drawButton(uint8_t d, int padding, String button_name, boolean inverted) { + uint16_t fill, outline, text; + + if(!inverted) { + fill = _fillcolor; + outline = _outlinecolor; + text = _textcolor; + } else { + fill = _textcolor; + outline = _outlinecolor; + text = _fillcolor; + } + + uint8_t r = min(_w, _h) / 4; // Corner radius + _gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill); + _gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline); + + _gfx->setTextColor(text); + _gfx->setTextSize(_textsize); + + uint8_t tempdatum = _gfx->getTextDatum(); + _gfx->setTextDatum(d); + if (button_name == "") + _gfx->drawString(_label, _x1 + padding, _y1 + (_h/2)); + else + _gfx->drawString(button_name, _x1 + padding, _y1 + (_h/2)); + _gfx->setTextDatum(tempdatum); +} + bool TFT_eSPI_Button::contains(int16_t x, int16_t y) { return ((x >= _x1) && (x < (_x1 + _w)) && (y >= _y1) && (y < (_y1 + _h))); diff --git a/Extensions/Button.h b/Extensions/Button.h index e8fa55e..b6ffbef 100644 --- a/Extensions/Button.h +++ b/Extensions/Button.h @@ -19,6 +19,7 @@ class TFT_eSPI_Button { uint16_t w, uint16_t h, uint16_t outline, uint16_t fill, uint16_t textcolor, char *label, uint8_t textsize); void drawButton(bool inverted = false); + void drawButton(uint8_t d, int padding, String button_name = "", boolean inverted = false); bool contains(int16_t x, int16_t y); void press(bool p);