forked from Bodmer/TFT_eSPI
Removed shitty Arduino String
This commit is contained in:
@@ -6,4 +6,18 @@ set(sources
|
||||
TFT_eSPI.cpp
|
||||
)
|
||||
|
||||
idf_component_register(INCLUDE_DIRS . SRCS ${headers} ${sources} REQUIRES arduino-esp32 freertos esp_system)
|
||||
set(dependencies
|
||||
arduino-esp32
|
||||
freertos
|
||||
esp_system
|
||||
)
|
||||
|
||||
idf_component_register(
|
||||
INCLUDE_DIRS
|
||||
.
|
||||
SRCS
|
||||
${headers}
|
||||
${sources}
|
||||
REQUIRES
|
||||
${dependencies}
|
||||
)
|
||||
|
@@ -47,7 +47,7 @@ void TFT_eSPI_Button::setLabelDatum(int16_t x_delta, int16_t y_delta, uint8_t da
|
||||
_textdatum = datum;
|
||||
}
|
||||
|
||||
void TFT_eSPI_Button::drawButton(bool inverted, String long_name) {
|
||||
void TFT_eSPI_Button::drawButton(bool inverted, std::string_view long_name) {
|
||||
uint16_t fill, outline, text;
|
||||
|
||||
if(!inverted) {
|
||||
|
@@ -23,7 +23,7 @@ class TFT_eSPI_Button : public TFT_eSPI {
|
||||
// Adjust text datum and x, y deltas
|
||||
void setLabelDatum(int16_t x_delta, int16_t y_delta, uint8_t datum = MC_DATUM);
|
||||
|
||||
void drawButton(bool inverted = false, String long_name = "");
|
||||
void drawButton(bool inverted = false, std::string_view long_name = "");
|
||||
bool contains(int16_t x, int16_t y);
|
||||
|
||||
void press(bool p);
|
||||
|
@@ -22,7 +22,7 @@ void TFT_eSPI::loadFont(const uint8_t array[])
|
||||
** Function name: loadFont
|
||||
** Description: loads parameters from a font vlw file
|
||||
*************************************************************************************x*/
|
||||
void TFT_eSPI::loadFont(String fontName, fs::FS &ffs)
|
||||
void TFT_eSPI::loadFont(std::string_view fontName, fs::FS &ffs)
|
||||
{
|
||||
fontFS = ffs;
|
||||
loadFont(fontName, false);
|
||||
@@ -33,7 +33,7 @@ void TFT_eSPI::loadFont(String fontName, fs::FS &ffs)
|
||||
** Function name: loadFont
|
||||
** Description: loads parameters from a font vlw file
|
||||
*************************************************************************************x*/
|
||||
void TFT_eSPI::loadFont(String fontName, bool flash)
|
||||
void TFT_eSPI::loadFont(std::string_view fontName, bool flash)
|
||||
{
|
||||
/*
|
||||
The vlw font format does not appear to be documented anywhere, so some reverse
|
||||
|
@@ -6,9 +6,9 @@
|
||||
// These are for the new anti-aliased fonts
|
||||
void loadFont(const uint8_t array[]);
|
||||
#ifdef FONT_FS_AVAILABLE
|
||||
void loadFont(String fontName, fs::FS &ffs);
|
||||
void loadFont(std::string_view fontName, fs::FS &ffs);
|
||||
#endif
|
||||
void loadFont(String fontName, bool flash = true);
|
||||
void loadFont(std::string_view fontName, bool flash = true);
|
||||
void unloadFont( void );
|
||||
bool getUnicodeIndex(uint16_t unicode, uint16_t *index);
|
||||
|
||||
|
@@ -2607,10 +2607,10 @@ void TFT_eSprite::drawGlyph(uint16_t code)
|
||||
** Function name: printToSprite
|
||||
** Description: Write a string to the sprite cursor position
|
||||
***************************************************************************************/
|
||||
void TFT_eSprite::printToSprite(String string)
|
||||
void TFT_eSprite::printToSprite(std::string_view string)
|
||||
{
|
||||
if(!fontLoaded) return;
|
||||
printToSprite((char*)string.c_str(), string.length());
|
||||
printToSprite(string.data(), string.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -2618,7 +2618,7 @@ void TFT_eSprite::printToSprite(String string)
|
||||
** Function name: printToSprite
|
||||
** Description: Write a string to the sprite cursor position
|
||||
***************************************************************************************/
|
||||
void TFT_eSprite::printToSprite(char *cbuffer, uint16_t len) //String string)
|
||||
void TFT_eSprite::printToSprite(char *cbuffer, uint16_t len) //std::string_view string)
|
||||
{
|
||||
if(!fontLoaded) return;
|
||||
|
||||
|
@@ -142,9 +142,7 @@ class TFT_eSprite : public TFT_eSPI {
|
||||
// Draw a single unicode character using the loaded font
|
||||
void drawGlyph(uint16_t code);
|
||||
// Print string to sprite using loaded font at cursor position
|
||||
void printToSprite(String string);
|
||||
// Print char array to sprite using loaded font at cursor position
|
||||
void printToSprite(char *cbuffer, uint16_t len);
|
||||
void printToSprite(std::string_view string);
|
||||
// Print indexed glyph to sprite using loaded font at x,y
|
||||
int16_t printToSprite(int16_t x, int16_t y, uint16_t index);
|
||||
|
||||
|
48
TFT_eSPI.cpp
48
TFT_eSPI.cpp
@@ -2883,21 +2883,6 @@ int16_t TFT_eSPI::height(void)
|
||||
** Function name: textWidth
|
||||
** Description: Return the width in pixels of a string in a given font
|
||||
***************************************************************************************/
|
||||
int16_t TFT_eSPI::textWidth(const String& string)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return textWidth(buffer, textfont);
|
||||
}
|
||||
|
||||
int16_t TFT_eSPI::textWidth(const String& string, uint8_t font)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return textWidth(buffer, font);
|
||||
}
|
||||
|
||||
int16_t TFT_eSPI::textWidth(const char *string)
|
||||
{
|
||||
@@ -4891,23 +4876,6 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font)
|
||||
** Function name: drawString (with or without user defined font)
|
||||
** Description : draw string with padding if it is defined
|
||||
***************************************************************************************/
|
||||
// Without font number, uses font set by setTextFont()
|
||||
int16_t TFT_eSPI::drawString(const String& string, int32_t poX, int32_t poY)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return drawString(buffer, poX, poY, textfont);
|
||||
}
|
||||
// With font number
|
||||
int16_t TFT_eSPI::drawString(const String& string, int32_t poX, int32_t poY, uint8_t font)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return drawString(buffer, poX, poY, font);
|
||||
}
|
||||
|
||||
// Without font number, uses font set by setTextFont()
|
||||
int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY)
|
||||
{
|
||||
@@ -5139,14 +5107,6 @@ return sumX;
|
||||
** Function name: drawCentreString (deprecated, use setTextDatum())
|
||||
** Descriptions: draw string centred on dX
|
||||
***************************************************************************************/
|
||||
int16_t TFT_eSPI::drawCentreString(const String& string, int32_t dX, int32_t poY, uint8_t font)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return drawCentreString(buffer, dX, poY, font);
|
||||
}
|
||||
|
||||
int16_t TFT_eSPI::drawCentreString(const char *string, int32_t dX, int32_t poY, uint8_t font)
|
||||
{
|
||||
uint8_t tempdatum = textdatum;
|
||||
@@ -5162,14 +5122,6 @@ int16_t TFT_eSPI::drawCentreString(const char *string, int32_t dX, int32_t poY,
|
||||
** Function name: drawRightString (deprecated, use setTextDatum())
|
||||
** Descriptions: draw string right justified to dX
|
||||
***************************************************************************************/
|
||||
int16_t TFT_eSPI::drawRightString(const String& string, int32_t dX, int32_t poY, uint8_t font)
|
||||
{
|
||||
int16_t len = string.length() + 2;
|
||||
char buffer[len];
|
||||
string.toCharArray(buffer, len);
|
||||
return drawRightString(buffer, dX, poY, font);
|
||||
}
|
||||
|
||||
int16_t TFT_eSPI::drawRightString(const char *string, int32_t dX, int32_t poY, uint8_t font)
|
||||
{
|
||||
uint8_t tempdatum = textdatum;
|
||||
|
17
TFT_eSPI.h
17
TFT_eSPI.h
@@ -28,9 +28,10 @@
|
||||
|
||||
//Standard support
|
||||
#include <Arduino.h>
|
||||
#include <Print.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
/***************************************************************************************
|
||||
** Section 2: Load library and processor specific header files
|
||||
***************************************************************************************/
|
||||
@@ -321,8 +322,8 @@ static const uint16_t default_4bit_palette[] PROGMEM = {
|
||||
// by calling getSetup(), zero impact on code size unless used, mainly for diagnostics
|
||||
typedef struct
|
||||
{
|
||||
String version = TFT_ESPI_VERSION;
|
||||
String setup_info; // Setup reference name available to use in a user setup
|
||||
std::string_view version = TFT_ESPI_VERSION;
|
||||
std::string setup_info; // Setup reference name available to use in a user setup
|
||||
uint32_t setup_id; // ID available to use in a user setup
|
||||
int32_t esp; // Processor code
|
||||
uint8_t trans; // SPI transaction support
|
||||
@@ -384,7 +385,7 @@ swap_coord(T& a, T& b) { T t = a; a = b; b = t; }
|
||||
typedef uint16_t (*getColorCallback)(uint16_t x, uint16_t y);
|
||||
|
||||
// Class functions and variables
|
||||
class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has access to protected members
|
||||
class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protected members
|
||||
|
||||
//--------------------------------------- public ------------------------------------//
|
||||
public:
|
||||
@@ -564,13 +565,9 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
|
||||
// Use with setTextDatum() to position string on TFT, and setTextPadding() to blank old displayed strings
|
||||
drawString(const char *string, int32_t x, int32_t y, uint8_t font), // Draw string using specified font number
|
||||
drawString(const char *string, int32_t x, int32_t y), // Draw string using current font
|
||||
drawString(const String& string, int32_t x, int32_t y, uint8_t font),// Draw string using specified font number
|
||||
drawString(const String& string, int32_t x, int32_t y), // Draw string using current font
|
||||
|
||||
drawCentreString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString()
|
||||
drawRightString(const char *string, int32_t x, int32_t y, uint8_t font), // Deprecated, use setTextDatum() and drawString()
|
||||
drawCentreString(const String& string, int32_t x, int32_t y, uint8_t font),// Deprecated, use setTextDatum() and drawString()
|
||||
drawRightString(const String& string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString()
|
||||
drawRightString(const char *string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString()
|
||||
|
||||
// Text rendering and font handling support funtions
|
||||
void setCursor(int16_t x, int16_t y), // Set cursor for tft.print()
|
||||
@@ -601,8 +598,6 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
|
||||
|
||||
int16_t textWidth(const char *string, uint8_t font), // Returns pixel width of string in specified font
|
||||
textWidth(const char *string), // Returns pixel width of string in current font
|
||||
textWidth(const String& string, uint8_t font), // As above for String types
|
||||
textWidth(const String& string),
|
||||
fontHeight(int16_t font), // Returns pixel height of string in specified font
|
||||
fontHeight(void); // Returns pixel width of string in current font
|
||||
|
||||
|
Reference in New Issue
Block a user