PokeMe64/include/widget/ListItemFiller.h
Philippe Symons f7a687b147 Various changes
- Add "Pikachu Bed" and "Tentacool Doll" decoration unlock options for
  gen 2
- bugfix for unsafe behaviour
- attempt to make the RESET button work for cartridge switching. It
  failed though. (not reliable). Therefore I just added a warning
  message instead.
- Work on new ScrollWidget for Credits/About screen (Work In Progress)
2024-07-31 22:29:21 +02:00

59 lines
1.6 KiB
C++
Executable File

#ifndef _LISTITEMFILLER_H
#define _LISTITEMFILLER_H
#include <vector>
#include <libdragon.h>
/**
* This template class simply serves the purpose of filling the specified ListType with widgets of the given ListItemWidgetType by creating
* these list item widgets based on a list of ListDataType entries and a ListItemWidgetStyleType
*
* ListType must have a function called addWidget(ListItemWidgetType)
* ListItemWidgetStyleType must have a setData(ListDataType) function
* AND a setStyle(ListItemWidgetStyleType) function
*
* ... in order to be able to use the ListItemFiller template class
*/
template<typename ListType, typename ListDataType, typename ListItemWidgetType, typename ListItemWidgetStyleType>
class ListItemFiller
{
public:
ListItemFiller(ListType& list)
: list_(list)
, widgets_()
{
}
~ListItemFiller()
{
deleteWidgets();
}
void addItems(ListDataType* dataList, size_t dataListSize, const MenuItemStyle& itemStyle)
{
ListItemWidgetType* itemWidget;
for(size_t i = 0; i < dataListSize; ++i)
{
itemWidget = new ListItemWidgetType();
itemWidget->setData(dataList[i]);
itemWidget->setStyle(itemStyle);
list_.addWidget(itemWidget);
}
}
void deleteWidgets()
{
for(ListItemWidgetType* item : widgets_)
{
delete item;
}
widgets_.clear();
}
protected:
private:
ListType& list_;
std::vector<ListItemWidgetType*> widgets_;
};
#endif