Compare commits
1 Commits
keyboard
...
scrolling-
Author | SHA1 | Date | |
---|---|---|---|
cf9c9401ec |
@ -51,6 +51,7 @@ set(headers
|
||||
src/widgets/label.h
|
||||
src/widgets/progressbar.h
|
||||
src/widgets/reverseprogressbar.h
|
||||
src/widgets/scrollinglabel.h
|
||||
src/widgets/slider.h
|
||||
src/widgets/verticalmeter.h
|
||||
src/widgets/vumeter.h
|
||||
@ -81,6 +82,7 @@ set(sources
|
||||
src/widgets/label.cpp
|
||||
src/widgets/progressbar.cpp
|
||||
src/widgets/reverseprogressbar.cpp
|
||||
src/widgets/scrollinglabel.cpp
|
||||
src/widgets/slider.cpp
|
||||
src/widgets/verticalmeter.cpp
|
||||
src/widgets/vumeter.cpp
|
||||
|
60
src/widgets/scrollinglabel.cpp
Normal file
60
src/widgets/scrollinglabel.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include "scrollinglabel.h"
|
||||
|
||||
// local includes
|
||||
#include "tftinstance.h"
|
||||
#include "richtextrenderer.h"
|
||||
|
||||
namespace espgui {
|
||||
ScrollingLabel::ScrollingLabel(int x, int y) :
|
||||
m_x{x},
|
||||
m_y{y}
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollingLabel::start()
|
||||
{
|
||||
m_lastStr.clear();
|
||||
m_lastFont = -1;
|
||||
m_lastColor = -1;
|
||||
|
||||
m_lastWidth = 0;
|
||||
m_lastHeight = 0;
|
||||
}
|
||||
|
||||
void ScrollingLabel::redraw(const std::string& str, bool forceRedraw)
|
||||
{
|
||||
/*if (m_lastStr == str &&
|
||||
m_lastFont == tft.textfont &&
|
||||
m_lastColor == tft.textcolor &&
|
||||
!forceRedraw)
|
||||
return;
|
||||
|
||||
const auto renderedWidth = renderRichText(str, m_x, m_y);
|
||||
const auto renderedHeight = tft.fontHeight();
|
||||
|
||||
if (renderedWidth < m_lastWidth)
|
||||
tft.fillRect(m_x + renderedWidth, m_y,
|
||||
m_lastWidth - renderedWidth, m_lastHeight,
|
||||
tft.textbgcolor);
|
||||
|
||||
if (renderedHeight < m_lastHeight)
|
||||
tft.fillRect(m_x, m_y + renderedHeight,
|
||||
renderedWidth, m_lastHeight - renderedHeight,
|
||||
tft.textbgcolor);
|
||||
|
||||
m_lastStr = str;
|
||||
m_lastFont = tft.textfont;
|
||||
m_lastColor = tft.textcolor;
|
||||
|
||||
m_lastWidth = renderedWidth;
|
||||
m_lastHeight = renderedHeight;*/
|
||||
}
|
||||
|
||||
void ScrollingLabel::clear()
|
||||
{
|
||||
if (m_lastWidth || m_lastHeight)
|
||||
tft.fillRect(m_x, m_y, m_lastWidth, m_lastHeight, tft.textbgcolor);
|
||||
|
||||
start();
|
||||
}
|
||||
}
|
36
src/widgets/scrollinglabel.h
Normal file
36
src/widgets/scrollinglabel.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <string>
|
||||
|
||||
namespace espgui {
|
||||
class ScrollingLabel
|
||||
{
|
||||
public:
|
||||
ScrollingLabel(int x, int y);
|
||||
|
||||
int x() const { return m_x; };
|
||||
int y() const { return m_y; };
|
||||
|
||||
void start();
|
||||
void redraw(const std::string& str, bool forceRedraw = false);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
const int m_x;
|
||||
const int m_y;
|
||||
|
||||
std::string m_lastStr;
|
||||
std::string m_str;
|
||||
std::string_view visibleStr;
|
||||
int m_lastFont;
|
||||
int m_lastColor;
|
||||
|
||||
int m_lastWidth;
|
||||
int m_lastHeight;
|
||||
};
|
||||
|
||||
class AutoScrollingLabel : public ScrollingLabel // needs void update()
|
||||
{
|
||||
};
|
||||
} // namespace espgui
|
Reference in New Issue
Block a user