Add selected icon interface to menus
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include "icon.h"
|
||||
|
||||
namespace espgui {
|
||||
|
||||
template<uint16_t width, uint16_t height>
|
||||
class IconInterface
|
||||
{
|
||||
@ -11,10 +12,25 @@ public:
|
||||
virtual const Icon<width, height> *icon() const { return nullptr; }
|
||||
};
|
||||
|
||||
template<uint16_t width, uint16_t height>
|
||||
class SelectedIconInterface
|
||||
{
|
||||
public:
|
||||
virtual const Icon<width, height> *selectedIcon() const { return nullptr; }
|
||||
};
|
||||
|
||||
template<uint16_t width, uint16_t height, const Icon<width, height> *T>
|
||||
class StaticIcon : public virtual IconInterface<width, height>
|
||||
{
|
||||
public:
|
||||
virtual const Icon<width, height> *icon() const { return T; }
|
||||
};
|
||||
|
||||
template<uint16_t width, uint16_t height, const Icon<width, height> *T>
|
||||
class StaticSelectedIcon : public virtual SelectedIconInterface<width, height>
|
||||
{
|
||||
public:
|
||||
virtual const Icon<width, height> *selectedIcon() const { return T; }
|
||||
};
|
||||
|
||||
} // namespace espgui
|
||||
|
@ -161,6 +161,13 @@ void MenuDisplay::redraw()
|
||||
drawItemRect(*labelsIter, TFT_GREY);
|
||||
*iconsIter = nullptr;
|
||||
labelsIter->start();
|
||||
|
||||
if (auto icon = item.selectedIcon())
|
||||
{
|
||||
tft.setSwapBytes(true);
|
||||
tft.pushImage(tft.width() - 6 - icon->WIDTH, labelsIter->y() + 1, icon->WIDTH, icon->HEIGHT, icon->buffer);
|
||||
tft.setSwapBytes(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (relativeIndex == m_highlightedIndex)
|
||||
@ -176,16 +183,15 @@ void MenuDisplay::redraw()
|
||||
|
||||
if (item.icon() != *iconsIter)
|
||||
{
|
||||
if (*iconsIter)
|
||||
tft.fillRect(6, labelsIter->y()+1, 24, 24, selected ? TFT_GREY : TFT_BLACK);
|
||||
|
||||
auto icon = item.icon();
|
||||
if (icon)
|
||||
{
|
||||
tft.setSwapBytes(true);
|
||||
tft.pushImage(6, labelsIter->y()+1, icon->WIDTH, icon->HEIGHT, icon->buffer);
|
||||
tft.pushImage(6, labelsIter->y() + 1, icon->WIDTH, icon->HEIGHT, icon->buffer);
|
||||
tft.setSwapBytes(false);
|
||||
}
|
||||
else if (*iconsIter)
|
||||
tft.fillRect(6, labelsIter->y() + 1, 24, 24, selected ? TFT_GREY : TFT_BLACK);
|
||||
*iconsIter = icon;
|
||||
}
|
||||
|
||||
|
@ -10,19 +10,26 @@
|
||||
#include "scrollinterface.h"
|
||||
|
||||
namespace espgui {
|
||||
using MenuItemIconInterface = IconInterface<24, 24>;
|
||||
|
||||
using MenuItemIcon = Icon<24, 24>;
|
||||
|
||||
using MenuItemIconInterface = IconInterface<24, 24>;
|
||||
|
||||
using MenuItemSelectedIconInterface = SelectedIconInterface<24, 24>;
|
||||
|
||||
template<const MenuItemIcon *T>
|
||||
using StaticMenuItemIcon = StaticIcon<24, 24, T>;
|
||||
|
||||
template<const MenuItemIcon *T>
|
||||
using StaticMenuItemSelectedIcon = StaticSelectedIcon<24, 24, T>;
|
||||
|
||||
class MenuItem :
|
||||
public virtual ActionInterface,
|
||||
public virtual TextInterface,
|
||||
public virtual FontInterface,
|
||||
public virtual ColorInterface,
|
||||
public virtual MenuItemIconInterface,
|
||||
public virtual MenuItemSelectedIconInterface,
|
||||
public virtual VisibleInterface,
|
||||
public virtual ScrollInterface
|
||||
{
|
||||
@ -44,8 +51,8 @@ protected:
|
||||
};
|
||||
|
||||
class EmptyMenuItem :
|
||||
public MenuItem,
|
||||
public EmptyText
|
||||
public MenuItem,
|
||||
public EmptyText
|
||||
{
|
||||
public:
|
||||
void triggered() override {}
|
||||
|
Reference in New Issue
Block a user