WIP scrollable label

This commit is contained in:
CommanderRedYT
2022-12-26 03:44:09 +01:00
parent 7f24e4bc37
commit 4b26475ca4
2 changed files with 31 additions and 1 deletions

View File

@ -6,6 +6,8 @@
using namespace std::chrono_literals;
#include "esp_log.h"
namespace espgui {
void MenuDisplay::start()
{
@ -135,6 +137,24 @@ void MenuDisplay::redraw(TftInterface &tft)
// color);
};
int longestLabelWidth{0};
runForEveryMenuItem([&](MenuItem &item){
if (item.text().size() > longestLabelWidth)
longestLabelWidth = item.text().size();
});
if (((espchrono::ago(m_lastScrollTimestamp) > 500ms && m_labelScrollOffset > 0) || (espchrono::ago(m_lastScrollTimestamp) > 1250ms && m_labelScrollOffset == 0)) && longestLabelWidth > 18)
{
m_lastScrollTimestamp = espchrono::millis_clock::now();
m_labelScrollOffset++;
if (m_labelScrollOffset > longestLabelWidth - 18)
m_labelScrollOffset = 0;
}
// ESP_LOGI("MenuDisplay", "m_labelScrollOffset: %d, longestLabelWidth: %d", m_labelScrollOffset, longestLabelWidth);
runForEveryMenuItem([&](MenuItem &item){
const auto index = i++;
@ -180,7 +200,14 @@ void MenuDisplay::redraw(TftInterface &tft)
labelsIter->start(tft);
}
labelsIter->redraw(tft, item.text(), item.color(), selected ? TFT_GREY : TFT_BLACK, item.font());
const auto text = item.text();
const auto textLength = text.size();
// labelsIter->redraw(tft, item.text(), item.color(), selected ? TFT_GREY : TFT_BLACK, item.font());
if (textLength > 18)
labelsIter->redraw(tft, text.substr(std::min<uint>(m_labelScrollOffset, textLength - 18)), item.color(), selected ? TFT_GREY : TFT_BLACK, item.font());
else
labelsIter->redraw(tft, text, item.color(), selected ? TFT_GREY : TFT_BLACK, item.font());
if (item.icon() != *iconsIter)
{

View File

@ -159,5 +159,8 @@ private:
std::optional<ButtonHeldInfo> m_upHeld;
std::optional<ButtonHeldInfo> m_downHeld;
espchrono::millis_clock::time_point m_lastScrollTimestamp;
uint m_labelScrollOffset{0};
};
} // namespace espgui