MCPcopy Create free account
hub / github.com/BruceDevices/firmware / drawButton

Method drawButton

lib/TFT_eSPI/Extensions/Button.cpp:52–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void TFT_eSPI_Button::drawButton(bool inverted, String long_name) {
53 uint16_t fill, outline, text;
54
55 if(!inverted) {
56 fill = _fillcolor;
57 outline = _outlinecolor;
58 text = _textcolor;
59 } else {
60 fill = _textcolor;
61 outline = _outlinecolor;
62 text = _fillcolor;
63 }
64
65 uint8_t r = min(_w, _h) / 4; // Corner radius
66 _gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
67 _gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
68
69 if (_gfx->textfont == 255) {
70 _gfx->setCursor(_x1 + (_w / 8),
71 _y1 + (_h / 4));
72 _gfx->setTextColor(text);
73 _gfx->setTextSize(_textsize);
74 _gfx->print(_label);
75 }
76 else {
77 _gfx->setTextColor(text, fill);
78 _gfx->setTextSize(_textsize);
79
80 uint8_t tempdatum = _gfx->getTextDatum();
81 _gfx->setTextDatum(_textdatum);
82 uint16_t tempPadding = _gfx->getTextPadding();
83 _gfx->setTextPadding(0);
84
85 if (long_name == "")
86 _gfx->drawString(_label, _x1 + (_w/2) + _xd, _y1 + (_h/2) - 4 + _yd);
87 else
88 _gfx->drawString(long_name, _x1 + (_w/2) + _xd, _y1 + (_h/2) - 4 + _yd);
89
90 _gfx->setTextDatum(tempdatum);
91 _gfx->setTextPadding(tempPadding);
92 }
93}
94
95bool TFT_eSPI_Button::contains(int16_t x, int16_t y) {
96 return ((x >= _x1) && (x < (_x1 + _w)) &&

Callers

nothing calls this directly

Calls 11

getTextPaddingMethod · 0.80
setTextPaddingMethod · 0.80
fillRoundRectMethod · 0.45
drawRoundRectMethod · 0.45
setCursorMethod · 0.45
setTextColorMethod · 0.45
setTextSizeMethod · 0.45
printMethod · 0.45
getTextDatumMethod · 0.45
setTextDatumMethod · 0.45
drawStringMethod · 0.45

Tested by

no test coverage detected