PokeMe64/include/widget/ListItemFiller.h
Philippe Symons 5f353d6a1c
Feature/show party icons on distribution pokemon selection screen (#8)
* Create PokemonPartyIconWidget for displaying the party menu icon in the distribution event pokemon menu (untested)

* Integrate PokemonPartyIconWidget into the DistributionPokemonListScene

* Do some visual changes to the DistributionPokemonListScene

* Revert "Undo README.md changes because they were already shown in github after merging the feature branch"

This reverts commit dc8d9bb00d.

* Update docs
2024-09-30 23:29:09 +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 ListItemWidgetStyleType& 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