fix #4 make font sizes in list relative to screen

pull/23/head
JuanJakobo 2021-01-12 16:26:57 +01:00
parent 9937171cbd
commit 3d745a26d6
2 changed files with 28 additions and 14 deletions

View File

@ -25,7 +25,19 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
_entries.clear();
int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount;
int entrySize = _contentRect->h / (_itemCount + 1);
_headerHeight = 0.25 * entrySize;
_footerHeight = 0.75 * entrySize;
_headerFontHeight = 0.8 * _headerHeight;
_footerFontHeight = 0.3 * _footerHeight;
_entryFontHeight = 0.2 * entrySize;
_headerFont = OpenFont("LiberationMono", _headerFontHeight, 1);
_footerFont = OpenFont("LiberationMono", _footerFontHeight, 1);
_entryFont = OpenFont("LiberationMono", _entryFontHeight, 1);
_entryFontBold = OpenFont("LiberationMono-Bold", _entryFontHeight, 1);
_page = 1;
_shownPage = _page;
@ -63,13 +75,13 @@ ListView::~ListView()
{
CloseFont(_entryFont);
CloseFont(_entryFontBold);
CloseFont(_titleFont);
CloseFont(_headerFont);
CloseFont(_footerFont);
}
void ListView::drawHeader(string headerText)
{
SetFont(_titleFont, BLACK);
SetFont(_headerFont, BLACK);
Util::decodeUrl(headerText);
DrawTextRect(_contentRect->x, _contentRect->y, _contentRect->w, _headerHeight - 1, headerText.c_str(), ALIGN_LEFT);
@ -95,7 +107,7 @@ void ListView::drawFooter()
void ListView::drawEntry(int itemID)
{
FillAreaRect(_entries[itemID].getPosition(), WHITE);
_entries[itemID].draw(_items->at(itemID), _entryFont, _entryFontBold, _fontHeight);
_entries[itemID].draw(_items->at(itemID), _entryFont, _entryFontBold, _entryFontHeight);
}
void ListView::drawEntries()
@ -103,7 +115,7 @@ void ListView::drawEntries()
for (auto i = 0; i < _entries.size(); i++)
{
if (_entries[i].getPage() == _shownPage)
_entries[i].draw(_items->at(i), _entryFont, _entryFontBold, _fontHeight);
_entries[i].draw(_items->at(i), _entryFont, _entryFontBold, _entryFontHeight);
}
}
@ -134,11 +146,11 @@ int ListView::listClicked(int x, int y)
}
else if (IsInRect(x, y, &_nextPageButton))
{
actualizePage(_shownPage+1);
actualizePage(_shownPage + 1);
}
else if (IsInRect(x, y, &_lastPageButton))
{
actualizePage(_shownPage-1);
actualizePage(_shownPage - 1);
}
else
{

View File

@ -69,16 +69,18 @@ public:
int listClicked(int x, int y);
private:
int _footerHeight = 100;
int _headerHeight = 40;
int _fontHeight = 30;
int _footerHeight;
int _headerHeight;
int _headerFontHeight;
int _footerFontHeight;
int _entryFontHeight;
const irect *_contentRect;
const std::shared_ptr<vector<Item>> _items = nullptr;
vector<ListViewEntry> _entries;
ifont *_titleFont = OpenFont("LiberationMono", 35, 1);
ifont *_footerFont = OpenFont("LiberationMono", 30, 1);
ifont *_entryFont = OpenFont("LiberationMono", _fontHeight, 1);
ifont *_entryFontBold = OpenFont("LiberationMono-Bold", _fontHeight, 1);
ifont *_headerFont;
ifont *_footerFont;
ifont *_entryFont;
ifont *_entryFontBold;
int _page;
int _shownPage;
irect _pageIcon;