I'm using @KurtE's ILI9341_t3n library. This is how I construct a rounded button with text. Here is one of many cases on a switch(buttons) statement. I iterate through the buttons.
Code:
case 7: { // Zero Z button
w=60-1; h=40; x=tft.width()-w-1; y=60;
char * buttonText[1] = {"Clear Z"}; char **mytext = buttonText;
ii = 0; mydatum = BC_DATUM; linecolor = ILI9341_WHITE;
facecolor = thisGREY; textcolor = ILI9341_WHITE;
displayRoundedTextBox( x, y, w, h, linecolor, facecolor, 1, textcolor,
mytext, ii, mydatum );
break;
where displayRoundedTextBox is defined as:
Code:
void displayRoundedTextBox( uint16_t x, uint16_t y, uint16_t w, uint16_t h,
int16_t borderColor, int16_t faceColor, uint8_t fontSize, int16_t fontColor,
char *text1[], uint8_t ii, uint8_t mydatum) {
// make a rounded text box with text size fontSize, color fontColor,
// text = text, with face color faceColor, etc. at location (x,y) with box
// width w, and height h.
uint16_t radius = 5;
tft.drawRoundRect( x-1, y-1, w+2, h+2, radius, borderColor);
tft.fillRoundRect( x, y, w, h, radius, faceColor);
tft.setTextColor( fontColor );
tft.setFont(Arial_10_Bold);
tft.setTextDatum(mydatum); // bottom center location
tft.drawString( text1[ii], x+w/2, y+h/2 );// locate string according to mydatum
}
I use this construction a lot, well, because it has worked. It does generate the following compiler warning:
Code:
/home/bruce/Arduino/ELS_IDE2/touchdisplay.ino:198:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
198 | char * buttonText[1] = {"Clear Z"}; char **mytext = buttonText;
| ^~~~~~~~~
Worried a bit going into the future and supporting this. Don't want an update to Arduino or gcc to decide this is illegal... What is a better way of doing this that doesn't generate the warning? This stuff confuses me, I'm a crummy programmer...