Better rendering of selected menu items
This commit is contained in:
@ -124,21 +124,24 @@ void MenuDisplay::redraw()
|
|||||||
int newHighlightedIndex{-1};
|
int newHighlightedIndex{-1};
|
||||||
|
|
||||||
const auto drawItemRect = [](const auto &label, const auto color){
|
const auto drawItemRect = [](const auto &label, const auto color){
|
||||||
tft.drawRoundRect(5,
|
tft.fillRect(5,
|
||||||
label.y()-1,
|
label.y()-1,
|
||||||
tft.width() - 10,
|
tft.width() - 10,
|
||||||
lineHeight+1,
|
lineHeight+1,
|
||||||
5,
|
|
||||||
color);
|
color);
|
||||||
|
//tft.drawRoundRect(5,
|
||||||
|
// label.y()-1,
|
||||||
|
// tft.width() - 10,
|
||||||
|
// lineHeight+1,
|
||||||
|
// 5,
|
||||||
|
// color);
|
||||||
};
|
};
|
||||||
|
|
||||||
runForEveryMenuItem([&](MenuItem &item){
|
runForEveryMenuItem([&](MenuItem &item){
|
||||||
const auto index = i++;
|
const auto index = i++;
|
||||||
|
|
||||||
if (!item.visible())
|
if (!item.visible())
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (index < m_scrollOffset)
|
if (index < m_scrollOffset)
|
||||||
return;
|
return;
|
||||||
@ -150,17 +153,31 @@ void MenuDisplay::redraw()
|
|||||||
const auto selected = index == m_selectedIndex;
|
const auto selected = index == m_selectedIndex;
|
||||||
|
|
||||||
if (selected)
|
if (selected)
|
||||||
|
{
|
||||||
newHighlightedIndex = relativeIndex;
|
newHighlightedIndex = relativeIndex;
|
||||||
|
|
||||||
|
if (relativeIndex != m_highlightedIndex)
|
||||||
|
{
|
||||||
|
drawItemRect(*labelsIter, TFT_GREY);
|
||||||
|
*iconsIter = nullptr;
|
||||||
|
labelsIter->clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (relativeIndex == m_highlightedIndex)
|
else if (relativeIndex == m_highlightedIndex)
|
||||||
|
{
|
||||||
drawItemRect(*labelsIter, TFT_BLACK);
|
drawItemRect(*labelsIter, TFT_BLACK);
|
||||||
|
*iconsIter = nullptr;
|
||||||
|
labelsIter->clear();
|
||||||
|
}
|
||||||
|
|
||||||
tft.setTextFont(item.font());
|
tft.setTextFont(item.font());
|
||||||
tft.setTextColor(item.color(), TFT_BLACK);
|
tft.setTextColor(item.color(), selected ? TFT_GREY : TFT_BLACK);
|
||||||
labelsIter->redraw(item.text());
|
labelsIter->redraw(item.text());
|
||||||
|
|
||||||
if (item.icon() != *iconsIter)
|
if (item.icon() != *iconsIter)
|
||||||
{
|
{
|
||||||
tft.fillRect(6, labelsIter->y()+1, 24, 24, TFT_BLACK);
|
if (*iconsIter)
|
||||||
|
tft.fillRect(6, labelsIter->y()+1, 24, 24, selected ? TFT_GREY : TFT_BLACK);
|
||||||
|
|
||||||
auto icon = item.icon();
|
auto icon = item.icon();
|
||||||
if (icon)
|
if (icon)
|
||||||
@ -172,10 +189,10 @@ void MenuDisplay::redraw()
|
|||||||
*iconsIter = icon;
|
*iconsIter = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected && (relativeIndex != m_highlightedIndex))
|
// if (selected && (relativeIndex != m_highlightedIndex))
|
||||||
{
|
// {
|
||||||
drawItemRect(*labelsIter, TFT_WHITE);
|
// drawItemRect(*labelsIter, TFT_GREY);
|
||||||
}
|
// }
|
||||||
|
|
||||||
labelsIter++;
|
labelsIter++;
|
||||||
iconsIter++;
|
iconsIter++;
|
||||||
|
Reference in New Issue
Block a user