|
|
@ -28,6 +28,11 @@ typedef struct {
|
|
|
|
uint32_t rgb;
|
|
|
|
uint32_t rgb;
|
|
|
|
} btn_colors;
|
|
|
|
} btn_colors;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Disable TOUCH_UI_FIT_TEXT on a case-by-case basis
|
|
|
|
|
|
|
|
namespace FTDI {
|
|
|
|
|
|
|
|
constexpr uint16_t OPT_NOFIT = OPT_NOTICKS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************** Enhanced Command Processor **************************/
|
|
|
|
/**************************** Enhanced Command Processor **************************/
|
|
|
|
|
|
|
|
|
|
|
|
/* The CommandProcessor class wraps the CommandFifo with several features to make
|
|
|
|
/* The CommandProcessor class wraps the CommandFifo with several features to make
|
|
|
@ -305,7 +310,7 @@ class CommandProcessor : public CLCD::CommandFifo {
|
|
|
|
int8_t apply_fit_text(int16_t w, int16_t h, T text) {
|
|
|
|
int8_t apply_fit_text(int16_t w, int16_t h, T text) {
|
|
|
|
using namespace FTDI;
|
|
|
|
using namespace FTDI;
|
|
|
|
int8_t font = _font;
|
|
|
|
int8_t font = _font;
|
|
|
|
for (;;) {
|
|
|
|
for (;font >= 26;) {
|
|
|
|
#ifdef TOUCH_UI_USE_UTF8
|
|
|
|
#ifdef TOUCH_UI_USE_UTF8
|
|
|
|
const int16_t width = get_utf8_text_width(text, font_size_t::from_romfont(font));
|
|
|
|
const int16_t width = get_utf8_text_width(text, font_size_t::from_romfont(font));
|
|
|
|
const int16_t height = font_size_t::from_romfont(font).get_height();
|
|
|
|
const int16_t height = font_size_t::from_romfont(font).get_height();
|
|
|
@ -314,7 +319,7 @@ class CommandProcessor : public CLCD::CommandFifo {
|
|
|
|
const int16_t width = fm.get_text_width(text);
|
|
|
|
const int16_t width = fm.get_text_width(text);
|
|
|
|
const int16_t height = fm.height;
|
|
|
|
const int16_t height = fm.height;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if ((width < w && height < h) || font == 26) break;
|
|
|
|
if (width < w && height < h) break;
|
|
|
|
font--;
|
|
|
|
font--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return font;
|
|
|
|
return font;
|
|
|
@ -327,12 +332,23 @@ class CommandProcessor : public CLCD::CommandFifo {
|
|
|
|
return *this;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
|
|
uint16_t text_width(T text) {
|
|
|
|
|
|
|
|
using namespace FTDI;
|
|
|
|
|
|
|
|
#ifdef TOUCH_UI_USE_UTF8
|
|
|
|
|
|
|
|
return get_utf8_text_width(text, font_size_t::from_romfont(_font));
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
CLCD::FontMetrics fm(_font);
|
|
|
|
|
|
|
|
return fm.get_text_width(text);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
template<typename T>
|
|
|
|
CommandProcessor& text(int16_t x, int16_t y, int16_t w, int16_t h, T text, uint16_t options = FTDI::OPT_CENTER) {
|
|
|
|
CommandProcessor& text(int16_t x, int16_t y, int16_t w, int16_t h, T text, uint16_t options = FTDI::OPT_CENTER) {
|
|
|
|
using namespace FTDI;
|
|
|
|
using namespace FTDI;
|
|
|
|
apply_text_alignment(x, y, w, h, options);
|
|
|
|
apply_text_alignment(x, y, w, h, options);
|
|
|
|
#ifdef TOUCH_UI_FIT_TEXT
|
|
|
|
#ifdef TOUCH_UI_FIT_TEXT
|
|
|
|
const int8_t font = apply_fit_text(w, h, text);
|
|
|
|
const int8_t font = (options & OPT_NOFIT) ? _font : apply_fit_text(w, h, text);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
const int8_t font = _font;
|
|
|
|
const int8_t font = _font;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -367,7 +383,7 @@ class CommandProcessor : public CLCD::CommandFifo {
|
|
|
|
bool styleModified = false;
|
|
|
|
bool styleModified = false;
|
|
|
|
if (_btn_style_callback) styleModified = _btn_style_callback(*this, _tag, _style, options, false);
|
|
|
|
if (_btn_style_callback) styleModified = _btn_style_callback(*this, _tag, _style, options, false);
|
|
|
|
#ifdef TOUCH_UI_FIT_TEXT
|
|
|
|
#ifdef TOUCH_UI_FIT_TEXT
|
|
|
|
const int8_t font = apply_fit_text(w, h, text);
|
|
|
|
const int8_t font = (options & OPT_NOFIT) ? _font : apply_fit_text(w, h, text);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
const int8_t font = _font;
|
|
|
|
const int8_t font = _font;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -375,6 +391,14 @@ class CommandProcessor : public CLCD::CommandFifo {
|
|
|
|
#ifdef TOUCH_UI_USE_UTF8
|
|
|
|
#ifdef TOUCH_UI_USE_UTF8
|
|
|
|
apply_text_alignment(x, y, w, h, OPT_CENTER);
|
|
|
|
apply_text_alignment(x, y, w, h, OPT_CENTER);
|
|
|
|
CLCD::CommandFifo::str(F(""));
|
|
|
|
CLCD::CommandFifo::str(F(""));
|
|
|
|
|
|
|
|
if (!(options & FTDI::OPT_FLAT)) {
|
|
|
|
|
|
|
|
// Reproduce the black "shadow" the FTDI adds to the button label
|
|
|
|
|
|
|
|
CLCD::CommandFifo::cmd(SAVE_CONTEXT());
|
|
|
|
|
|
|
|
CLCD::CommandFifo::cmd(COLOR_RGB(0x00000));
|
|
|
|
|
|
|
|
draw_utf8_text(*this, x-1, y-1, text, font_size_t::from_romfont(font), OPT_CENTER);
|
|
|
|
|
|
|
|
CLCD::CommandFifo::cmd(RESTORE_CONTEXT());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the button label
|
|
|
|
draw_utf8_text(*this, x, y, text, font_size_t::from_romfont(font), OPT_CENTER);
|
|
|
|
draw_utf8_text(*this, x, y, text, font_size_t::from_romfont(font), OPT_CENTER);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
CLCD::CommandFifo::str(text);
|
|
|
|
CLCD::CommandFifo::str(text);
|
|
|
|