add buttons to navigate first, last and next page

pull/23/head
JuanJakobo 2020-11-09 18:07:39 +01:00
parent dc72d826d6
commit e44733be7d
2 changed files with 53 additions and 23 deletions

View File

@ -30,8 +30,8 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount; int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount;
_shownPage = 1;
_page = 1; _page = 1;
_shownPage = _page;
auto i = _items->size(); auto i = _items->size();
auto z = 0; auto z = 0;
@ -52,7 +52,12 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
z++; z++;
} }
_pageButton = iRect(_contentRect->w - 100, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER); _pageIcon = iRect(_contentRect->w - 100, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
//TODO draw botton back and next, draw just once?
_firstPageButton = iRect(_contentRect->x, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
_lastPageButton = iRect(_contentRect->x + 120, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
_nextPageButton = iRect(_contentRect->x + 240, _contentRect->h + _contentRect->y - _footerHeight, 100, _footerHeight, ALIGN_CENTER);
drawEntries(); drawEntries();
drawFooter(); drawFooter();
@ -76,8 +81,15 @@ void ListView::drawFooter()
{ {
SetFont(_footerFont.get(), WHITE); SetFont(_footerFont.get(), WHITE);
string footer = Util::valueToString<int>(_shownPage) + "/" + Util::valueToString<int>(_page); string footer = Util::valueToString<int>(_shownPage) + "/" + Util::valueToString<int>(_page);
FillAreaRect(&_pageButton, BLACK); FillAreaRect(&_pageIcon, BLACK);
DrawTextRect2(&_pageButton, footer.c_str());
DrawTextRect2(&_pageIcon, footer.c_str());
FillAreaRect(&_firstPageButton, BLACK);
DrawTextRect2(&_firstPageButton, "First");
FillAreaRect(&_lastPageButton, BLACK);
DrawTextRect2(&_lastPageButton, "Last");
FillAreaRect(&_nextPageButton, BLACK);
DrawTextRect2(&_nextPageButton, "Next");
} }
void ListView::drawEntry(int itemID) void ListView::drawEntry(int itemID)
@ -95,27 +107,39 @@ void ListView::drawEntries()
} }
} }
int ListView::listClicked(int x, int y) void ListView::actualizePage(int _pageToShown)
{ {
if (IsInRect(x, y, &_pageButton)) if (_pageToShown > _page)
{ {
if (_page > 1) Message(ICON_ERROR, "Info", "You have reached the last page, to return to the first, please click home.", 1200);
}
else if (_pageToShown < 1)
{ {
FillArea(_contentRect->x,_contentRect->y+_headerHeight, _contentRect->w, _contentRect->h, WHITE); Message(ICON_ERROR, "Info", "You are already on the first page.", 1200);
if (_shownPage >= _page)
{
_shownPage = 1;
} }
else else
{ {
_shownPage++; _shownPage = _pageToShown;
} FillArea(_contentRect->x, _contentRect->y + _headerHeight, _contentRect->w, _contentRect->h, WHITE);
drawEntries(); drawEntries();
drawFooter(); drawFooter();
} }
} }
int ListView::listClicked(int x, int y)
{
if (IsInRect(x, y, &_firstPageButton))
{
actualizePage(1);
}
else if (IsInRect(x, y, &_nextPageButton))
{
actualizePage(_shownPage+1);
}
else if (IsInRect(x, y, &_lastPageButton))
{
actualizePage(_shownPage-1);
}
else else
{ {
for (unsigned int i = 0; i < _entries.size(); i++) for (unsigned int i = 0; i < _entries.size(); i++)

View File

@ -56,6 +56,9 @@ public:
*/ */
void drawEntries(); void drawEntries();
void actualizePage(int _pageToShown);
/** /**
* Checkes if the listview has been clicked and either changes the page or returns item ID * Checkes if the listview has been clicked and either changes the page or returns item ID
* *
@ -73,7 +76,10 @@ private:
std::unique_ptr<ifont> _footerFont; std::unique_ptr<ifont> _footerFont;
int _page; int _page;
int _shownPage; int _shownPage;
irect _pageButton; irect _pageIcon;
irect _nextPageButton;
irect _lastPageButton;
irect _firstPageButton;
int _footerHeight = 100; int _footerHeight = 100;
int _headerHeight = 40; int _headerHeight = 40;
int _itemCount = 7; int _itemCount = 7;