large refactor
This commit is contained in:
65
src/status.hpp
Normal file
65
src/status.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef _STATUS_H_
|
||||
#define _STATUS_H_
|
||||
|
||||
#define LGFX_AUTODETECT
|
||||
#include <LovyanGFX.hpp>
|
||||
|
||||
class Status
|
||||
{
|
||||
public:
|
||||
Status(String value) : value{value}
|
||||
{
|
||||
old_length = value.length();
|
||||
}
|
||||
|
||||
~Status() = default;
|
||||
|
||||
void set(String value)
|
||||
{
|
||||
old_length = this->value.length();
|
||||
this->value = value;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void draw(LGFX *canvas)
|
||||
{
|
||||
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
|
Reference in New Issue
Block a user