/*
Forum: https://forum.arduino.cc/t/best-way-to-print-letters-with-strikethrough/1355282
Wokwi: https://wokwi.com/projects/423332516171588609
2025-02-20
ec2021
Realization of a simple "Strike Through" function for TFT displays
Known limitation: String must fit in one line
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void Print(String txt, int atX, int atY, int tSize, uint16_t col){
int boxX, boxY, width, height;
tft.setCursor(atX, atY);
tft.setTextColor(col);
tft.setTextSize(tSize);
tft.println(txt);
tft.getTextBounds(txt,atX,atY, &boxX, &boxY, &width, &height);
tft.drawFastHLine(boxX,boxY+height/2,width,col);
};
void setup() {
tft.begin();
tft.setRotation(0);
Print("Strike Through",10,10, 1, ILI9341_RED);
Print("Strike Through",10,30, 2, ILI9341_BLUE);
tft.setRotation(1);
Print("Strike Through",10, 120, 3, ILI9341_GREEN);
}
void loop() {
}