From c32bcc03f0bfded0dbb268de5db31c2ba17607c8 Mon Sep 17 00:00:00 2001 From: JuanJakobo <34421964+JuanJakobo@users.noreply.github.com> Date: Sun, 10 Jan 2021 17:58:59 +0100 Subject: [PATCH] move fonts to listView and close using inkview met --- src/ui/listView.cpp | 15 ++++++++------- src/ui/listView.h | 13 ++++++++----- src/ui/listViewEntry.cpp | 20 ++++++++++---------- src/ui/listViewEntry.h | 6 +----- src/ui/loginView.cpp | 9 ++++++--- src/ui/loginView.h | 4 +++- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/ui/listView.cpp b/src/ui/listView.cpp index 7257ba8..f611b4b 100644 --- a/src/ui/listView.cpp +++ b/src/ui/listView.cpp @@ -23,9 +23,6 @@ ListView::ListView(const irect *contentRect, const std::shared_ptr> { FillAreaRect(_contentRect, WHITE); - _titleFont = std::unique_ptr(OpenFont("LiberationMono", 35, 1)); - _footerFont = std::unique_ptr(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> 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(_shownPage) + "/" + Util::valueToString(_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); } } diff --git a/src/ui/listView.h b/src/ui/listView.h index ddee7b2..95b3ca9 100644 --- a/src/ui/listView.h +++ b/src/ui/listView.h @@ -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> _items = nullptr; vector _entries; - std::unique_ptr _titleFont; - std::unique_ptr _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 \ No newline at end of file diff --git a/src/ui/listViewEntry.cpp b/src/ui/listViewEntry.cpp index 0db3848..f632ddd 100644 --- a/src/ui/listViewEntry.cpp +++ b/src/ui/listViewEntry.cpp @@ -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; diff --git a/src/ui/listViewEntry.h b/src/ui/listViewEntry.h index ce2c9f8..66772ec 100644 --- a/src/ui/listViewEntry.h +++ b/src/ui/listViewEntry.h @@ -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 _entryFont = std::unique_ptr(OpenFont("LiberationMono", _fontHeight, 1));; - std::unique_ptr _entryFontBold = std::unique_ptr(OpenFont("LiberationMono-Bold", _fontHeight, 1)); irect _position; }; #endif \ No newline at end of file diff --git a/src/ui/loginView.cpp b/src/ui/loginView.cpp index c448ffb..e71dfee 100644 --- a/src/ui/loginView.cpp +++ b/src/ui/loginView.cpp @@ -20,9 +20,8 @@ LoginView *LoginView::_loginViewStatic; LoginView::LoginView(const irect *contentRect) : _contentRect(contentRect) { _loginViewStatic = this; - _loginFont = std::unique_ptr(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); diff --git a/src/ui/loginView.h b/src/ui/loginView.h index 1d9818c..bdb7b8d 100644 --- a/src/ui/loginView.h +++ b/src/ui/loginView.h @@ -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 _loginFont; + ifont *_loginFont = OpenFont("LiberationMono", 40, 1); const irect *_contentRect; irect _urlButton; irect _loginButton;