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