move fonts to listView and close using inkview met

pull/23/head
JuanJakobo 2021-01-10 17:58:59 +01:00
parent 73adc742fd
commit c32bcc03f0
6 changed files with 36 additions and 31 deletions

View File

@ -23,9 +23,6 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
{
FillAreaRect(_contentRect, WHITE);
_titleFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", 35, 1));
_footerFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", 30, 1));
_entries.clear();
int entrySize = (_contentRect->h - _footerHeight - _headerHeight) / _itemCount;
@ -65,11 +62,15 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr<vector<Item>>
ListView::~ListView()
{
CloseFont(_entryFont);
CloseFont(_entryFontBold);
CloseFont(_titleFont);
CloseFont(_footerFont);
}
void ListView::drawHeader(string headerText)
{
SetFont(_titleFont.get(), BLACK);
SetFont(_titleFont, BLACK);
Util::decodeUrl(headerText);
DrawTextRect(_contentRect->x, _contentRect->y, _contentRect->w, _headerHeight - 1, headerText.c_str(), ALIGN_LEFT);
@ -79,7 +80,7 @@ void ListView::drawHeader(string headerText)
void ListView::drawFooter()
{
SetFont(_footerFont.get(), WHITE);
SetFont(_footerFont, WHITE);
string footer = Util::valueToString<int>(_shownPage) + "/" + Util::valueToString<int>(_page);
FillAreaRect(&_pageIcon, BLACK);
@ -95,7 +96,7 @@ void ListView::drawFooter()
void ListView::drawEntry(int itemID)
{
FillAreaRect(_entries[itemID].getPosition(), WHITE);
_entries[itemID].draw(_items->at(itemID));
_entries[itemID].draw(_items->at(itemID), _entryFont, _entryFontBold, _fontHeight);
}
void ListView::drawEntries()
@ -103,7 +104,7 @@ void ListView::drawEntries()
for (auto i = 0; i < _entries.size(); i++)
{
if (_entries[i].getPage() == _shownPage)
_entries[i].draw(_items->at(i));
_entries[i].draw(_items->at(i), _entryFont, _entryFontBold, _fontHeight);
}
}

View File

@ -69,19 +69,22 @@ public:
int listClicked(int x, int y);
private:
int _footerHeight = 100;
int _headerHeight = 40;
int _fontHeight = 30;
const irect *_contentRect;
const std::shared_ptr<vector<Item>> _items = nullptr;
vector<ListViewEntry> _entries;
std::unique_ptr<ifont> _titleFont;
std::unique_ptr<ifont> _footerFont;
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);
int _page;
int _shownPage;
irect _pageIcon;
irect _nextPageButton;
irect _lastPageButton;
irect _firstPageButton;
int _footerHeight = 100;
int _headerHeight = 40;
int _itemCount = 7;
int _itemCount = 7;
};
#endif

View File

@ -17,34 +17,34 @@ ListViewEntry::ListViewEntry(int page, irect rect) : _page(page), _position(rect
{
}
void ListViewEntry::draw(const Item &item)
void ListViewEntry::draw(const Item &item, ifont *entryFont, ifont *entryFontBold, int fontHeight)
{
SetFont(_entryFontBold.get(), BLACK);
DrawTextRect(_position.x, _position.y, _position.w, _fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
SetFont(entryFontBold, BLACK);
DrawTextRect(_position.x, _position.y, _position.w, fontHeight, item.getTitle().c_str(), ALIGN_LEFT);
SetFont(_entryFont.get(), BLACK);
SetFont(entryFont, BLACK);
if (item.getState() == FileState::ILOCAL)
{
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Local", ALIGN_RIGHT);
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Local", ALIGN_RIGHT);
}
else
{
if (item.getType() == IFILE)
{
DrawTextRect(_position.x, _position.y + _fontHeight, _position.w, _fontHeight, item.getFiletype().c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + fontHeight, _position.w, fontHeight, item.getFiletype().c_str(), ALIGN_LEFT);
if (item.getState() == FileState::ISYNCED)
{
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Synced", ALIGN_RIGHT);
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Synced", ALIGN_RIGHT);
}
else
{
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, "Click to Download", ALIGN_RIGHT);
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, "Click to Download", ALIGN_RIGHT);
}
}
DrawTextRect(_position.x, _position.y + 2 * _fontHeight, _position.w, _fontHeight, item.getLastEditDate().c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + 3 * _fontHeight, _position.w, _fontHeight, item.getSize().c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + 2 * fontHeight, _position.w, fontHeight, item.getLastEditDate().c_str(), ALIGN_LEFT);
DrawTextRect(_position.x, _position.y + 3 * fontHeight, _position.w, fontHeight, item.getSize().c_str(), ALIGN_LEFT);
}
int line = (_position.y + _position.h) - 1;

View File

@ -33,14 +33,10 @@ public:
*
* @param item item that shall be drawn
*/
void draw(const Item &item);
void draw(const Item &item, ifont *entryFont, ifont *entryFontBold, int fontHeight);
private:
int _page;
//TODO in central class?
int _fontHeight = 30;
std::unique_ptr<ifont> _entryFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", _fontHeight, 1));;
std::unique_ptr<ifont> _entryFontBold = std::unique_ptr<ifont>(OpenFont("LiberationMono-Bold", _fontHeight, 1));
irect _position;
};
#endif

View File

@ -20,9 +20,8 @@ LoginView *LoginView::_loginViewStatic;
LoginView::LoginView(const irect *contentRect) : _contentRect(contentRect)
{
_loginViewStatic = this;
_loginFont = std::unique_ptr<ifont>(OpenFont("LiberationMono", 40, 1));
SetFont(_loginFont.get(), BLACK);
SetFont(_loginFont, BLACK);
FillAreaRect(_contentRect, WHITE);
_urlButton = iRect(50, 200, (ScreenWidth() - 100), 75, ALIGN_CENTER);
@ -41,10 +40,14 @@ LoginView::LoginView(const irect *contentRect) : _contentRect(contentRect)
_loginButton = iRect(50, 750, (ScreenWidth() - 100), 75, ALIGN_CENTER);
FillAreaRect(&_loginButton, BLACK);
SetFont(_loginFont.get(), WHITE);
SetFont(_loginFont, WHITE);
DrawTextRect2(&_loginButton, "Login");
}
LoginView::~LoginView()
{
CloseFont(_loginFont);
}
void LoginView::keyboardHandlerStatic(char *text)
{
_loginViewStatic->keyboardHandler(text);

View File

@ -30,6 +30,8 @@ class LoginView
public:
LoginView(const irect *contentRect);
~LoginView();
int logginClicked(int x, int y);
string getUsername() { return _username; };
@ -38,7 +40,7 @@ public:
private:
static LoginView *_loginViewStatic;
std::unique_ptr<ifont> _loginFont;
ifont *_loginFont = OpenFont("LiberationMono", 40, 1);
const irect *_contentRect;
irect _urlButton;
irect _loginButton;