Compare commits
4 Commits
rotary
...
allow-sing
Author | SHA1 | Date | |
---|---|---|---|
53c5f9a0f3 | |||
7e17dcf7d8 | |||
76041027df | |||
51bae4e7f3 |
@ -81,6 +81,7 @@ set(sources
|
||||
src/screenmanager.cpp
|
||||
src/splitgraphdisplay.cpp
|
||||
src/popupdisplay.cpp
|
||||
src/richtexthelper.cpp
|
||||
src/richtextrenderer.cpp
|
||||
src/icons/back.cpp
|
||||
src/icons/checked.cpp
|
||||
@ -122,6 +123,8 @@ idf_component_register(
|
||||
${dependencies}
|
||||
)
|
||||
|
||||
set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 23)
|
||||
|
||||
target_compile_options(${COMPONENT_TARGET}
|
||||
PRIVATE
|
||||
-fstack-reuse=all
|
||||
|
@ -77,8 +77,26 @@ using MenuItemIconInterface = SelectableIconInterface<24, 24>;
|
||||
|
||||
using MenuItemSelectedIconInterface = SelectedIconInterface<24, 24>;
|
||||
|
||||
template<const MenuItemIcon * ...T>
|
||||
class StaticMenuItemIcon;
|
||||
|
||||
template<const MenuItemIcon *T, const MenuItemIcon *Tselected>
|
||||
using StaticMenuItemIcon = StaticSelectableIcon<24, 24, T, Tselected>;
|
||||
class StaticMenuItemIcon<T, Tselected> : public StaticSelectableIcon<24, 24, T, Tselected>
|
||||
{
|
||||
using Base = StaticSelectableIcon<24, 24, T, Tselected>;
|
||||
|
||||
public:
|
||||
using Base::Base;
|
||||
};
|
||||
|
||||
template<const MenuItemIcon *T>
|
||||
class StaticMenuItemIcon<T> : public StaticSelectableIcon<24, 24, T, T>
|
||||
{
|
||||
using Base = StaticSelectableIcon<24, 24, T, T>;
|
||||
|
||||
public:
|
||||
using Base::Base;
|
||||
};
|
||||
|
||||
template<const MenuItemIcon *T>
|
||||
using StaticMenuItemSelectedIcon = StaticSelectedIcon<24, 24, T>;
|
||||
|
18
src/richtexthelper.cpp
Normal file
18
src/richtexthelper.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "richtexthelper.h"
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <strutils.h>
|
||||
|
||||
namespace espgui {
|
||||
|
||||
void richTextEscape(std::string &subject)
|
||||
{
|
||||
cpputils::stringReplaceAll('&', "&&", subject);
|
||||
}
|
||||
|
||||
std::string richTextEscape(std::string_view subject)
|
||||
{
|
||||
return cpputils::stringReplaceAll('&', "&&", subject);
|
||||
}
|
||||
|
||||
} // namespace espgui
|
@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace espgui {
|
||||
namespace colors {
|
||||
constexpr char RED[] = "&1"; // #ff0000 (TFT_RED)
|
||||
@ -17,4 +21,8 @@ constexpr char SMALL[] = "&s"; // tft.setTextFont(2)
|
||||
constexpr char MEDIUM[] = "&m"; // tft.setTextFont(4)
|
||||
constexpr char RESTORE[] = "&f"; // restore original font
|
||||
} // namespace fonts
|
||||
|
||||
void richTextEscape(std::string &subject);
|
||||
std::string richTextEscape(std::string_view subject);
|
||||
|
||||
} // namespace espgui
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <string_view>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <strutils.h>
|
||||
#include <fontrenderer.h>
|
||||
|
||||
// local includes
|
||||
@ -13,16 +12,6 @@
|
||||
|
||||
namespace espgui {
|
||||
|
||||
void richTextEscape(std::string &subject)
|
||||
{
|
||||
cpputils::stringReplaceAll('&', "&&", subject);
|
||||
}
|
||||
|
||||
std::string richTextEscape(std::string_view subject)
|
||||
{
|
||||
return cpputils::stringReplaceAll('&', "&&", subject);
|
||||
}
|
||||
|
||||
int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font)
|
||||
{
|
||||
FontRenderer fontRenderer{tft};
|
||||
|
@ -9,9 +9,6 @@ namespace espgui { class TftInterface; class FontRenderer; }
|
||||
|
||||
namespace espgui {
|
||||
|
||||
void richTextEscape(std::string &subject);
|
||||
std::string richTextEscape(std::string_view subject);
|
||||
|
||||
int16_t renderRichText(TftInterface &tft, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font);
|
||||
int16_t renderRichText(TftInterface &tft, FontRenderer &fontRenderer, std::string_view str, int32_t poX, int32_t poY, uint16_t color, uint16_t bgcolor, uint8_t font);
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
// system includes
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
// 3rdparty lib includes
|
||||
#include <cpputils.h>
|
||||
#include <stdlib_noniso.h>
|
||||
#include <fontrenderer.h>
|
||||
|
||||
// local includes
|
||||
@ -104,6 +104,81 @@ void VuMeter::start(TftInterface &tft)
|
||||
tft.drawRect(5, 3, 230, 119, TFT_BLACK); // Draw bezel line
|
||||
}
|
||||
|
||||
namespace {
|
||||
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
|
||||
bool negative = false;
|
||||
|
||||
if (std::isnan(number)) {
|
||||
std::strcpy(s, "nan");
|
||||
return s;
|
||||
}
|
||||
if (std::isinf(number)) {
|
||||
std::strcpy(s, "inf");
|
||||
return s;
|
||||
}
|
||||
|
||||
char* out = s;
|
||||
|
||||
int fillme = width; // how many cells to fill for the integer part
|
||||
if (prec > 0) {
|
||||
fillme -= (prec+1);
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
negative = true;
|
||||
fillme--;
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
// I optimized out most of the divisions
|
||||
double rounding = 2.0;
|
||||
for (uint8_t i = 0; i < prec; ++i)
|
||||
rounding *= 10.0;
|
||||
rounding = 1.0 / rounding;
|
||||
|
||||
number += rounding;
|
||||
|
||||
// Figure out how big our number really is
|
||||
double tenpow = 1.0;
|
||||
int digitcount = 1;
|
||||
while (number >= 10.0 * tenpow) {
|
||||
tenpow *= 10.0;
|
||||
digitcount++;
|
||||
}
|
||||
|
||||
number /= tenpow;
|
||||
fillme -= digitcount;
|
||||
|
||||
// Pad unused cells with spaces
|
||||
while (fillme-- > 0) {
|
||||
*out++ = ' ';
|
||||
}
|
||||
|
||||
// Handle negative sign
|
||||
if (negative) *out++ = '-';
|
||||
|
||||
// Print the digits, and if necessary, the decimal point
|
||||
digitcount += prec;
|
||||
int8_t digit = 0;
|
||||
while (digitcount-- > 0) {
|
||||
digit = (int8_t)number;
|
||||
if (digit > 9) digit = 9; // insurance
|
||||
*out++ = (char)('0' | digit);
|
||||
if ((digitcount == prec) && (prec > 0)) {
|
||||
*out++ = '.';
|
||||
}
|
||||
number -= digit;
|
||||
number *= 10.0;
|
||||
}
|
||||
|
||||
// make sure the string is terminated
|
||||
*out = 0;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void VuMeter::redraw(TftInterface &tft, float value)
|
||||
{
|
||||
FontRenderer fontRenderer{tft};
|
||||
|
Reference in New Issue
Block a user