65 lines
1.4 KiB
C++
65 lines
1.4 KiB
C++
#ifndef _STATUS_H_
|
|
#define _STATUS_H_
|
|
|
|
#define LGFX_AUTODETECT
|
|
#include <LovyanGFX.hpp>
|
|
|
|
class Status
|
|
{
|
|
public:
|
|
Status(LGFX *canvas, String value) : canvas{canvas}, value{value}
|
|
{
|
|
old_length = value.length();
|
|
}
|
|
|
|
~Status() = default;
|
|
|
|
void set(String value)
|
|
{
|
|
old_length = this->value.length();
|
|
this->value = value;
|
|
dirty = true;
|
|
}
|
|
|
|
void draw()
|
|
{
|
|
if (!dirty)
|
|
{
|
|
return;
|
|
}
|
|
dirty = false;
|
|
|
|
float MARGIN = 10.0;
|
|
|
|
canvas->setTextSize(3.0);
|
|
|
|
int bg_color = TFT_WHITE;
|
|
int fg_color = TFT_BLACK;
|
|
|
|
float old_x = canvas->width() - (canvas->fontWidth() * old_length) - MARGIN;
|
|
float new_x = canvas->width() - (canvas->fontWidth() * value.length()) - MARGIN;
|
|
float new_y = canvas->height() - canvas->fontHeight() - MARGIN;
|
|
|
|
canvas->setEpdMode(epd_fastest);
|
|
canvas->setColor(bg_color);
|
|
|
|
canvas->fillRect(old_x, new_y, canvas->width() - old_x, canvas->height() - new_y);
|
|
canvas->waitDisplay();
|
|
canvas->setColor(fg_color);
|
|
|
|
canvas->setEpdMode(epd_text);
|
|
canvas->setBaseColor(bg_color);
|
|
canvas->setTextColor(fg_color);
|
|
canvas->setCursor(new_x, new_y);
|
|
canvas->print(value);
|
|
}
|
|
|
|
private:
|
|
LGFX *canvas;
|
|
String value;
|
|
int old_length = 0;
|
|
|
|
bool dirty = true;
|
|
};
|
|
|
|
#endif |