add buttons to navigate first, last and next page
parent
dc72d826d6
commit
e44733be7d
|
@ -30,8 +30,8 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
|
|||
|
||||
int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount;
|
||||
|
||||
_shownPage = 1;
|
||||
_page = 1;
|
||||
_shownPage = _page;
|
||||
|
||||
auto i = _items->size();
|
||||
auto z = 0;
|
||||
|
@ -52,7 +52,12 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
|
|||
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();
|
||||
drawFooter();
|
||||
|
@ -76,8 +81,15 @@ void ListView::drawFooter()
|
|||
{
|
||||
SetFont(_footerFont.get(), WHITE);
|
||||
string footer = Util::valueToString<int>(_shownPage) + "/" + Util::valueToString<int>(_page);
|
||||
FillAreaRect(&_pageButton, BLACK);
|
||||
DrawTextRect2(&_pageButton, footer.c_str());
|
||||
FillAreaRect(&_pageIcon, BLACK);
|
||||
|
||||
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)
|
||||
|
@ -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);
|
||||
|
||||
if (_shownPage >= _page)
|
||||
{
|
||||
_shownPage = 1;
|
||||
Message(ICON_ERROR, "Info", "You are already on the first page.", 1200);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shownPage++;
|
||||
}
|
||||
|
||||
_shownPage = _pageToShown;
|
||||
FillArea(_contentRect->x, _contentRect->y + _headerHeight, _contentRect->w, _contentRect->h, WHITE);
|
||||
drawEntries();
|
||||
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
|
||||
{
|
||||
for (unsigned int i = 0; i < _entries.size(); i++)
|
||||
|
|
|
@ -56,6 +56,9 @@ public:
|
|||
*/
|
||||
void drawEntries();
|
||||
|
||||
void actualizePage(int _pageToShown);
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
int _page;
|
||||
int _shownPage;
|
||||
irect _pageButton;
|
||||
irect _pageIcon;
|
||||
irect _nextPageButton;
|
||||
irect _lastPageButton;
|
||||
irect _firstPageButton;
|
||||
int _footerHeight = 100;
|
||||
int _headerHeight = 40;
|
||||
int _itemCount = 7;
|
||||
|
|
Loading…
Reference in New Issue