diff --git a/src/ui/fileModel.h b/src/ui/fileModel.h new file mode 100644 index 0000000..4ea5d57 --- /dev/null +++ b/src/ui/fileModel.h @@ -0,0 +1,28 @@ +//------------------------------------------------------------------ +// fileModel.h +// +// Author: JuanJakobo +// Date: 23.04.2021 +// Description: +//------------------------------------------------------------------- + +#ifndef FILEMODEL +#define FILEMODEL + +//#include "model.h" + +#include + +enum Type +{ + FOLDER, + FIL +}; + +struct File : Entry{ + std::string name; + std::string path; + Type type; +}; + +#endif diff --git a/src/ui/fileView/fileView.cpp b/src/ui/fileView/fileView.cpp new file mode 100644 index 0000000..89b2639 --- /dev/null +++ b/src/ui/fileView/fileView.cpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------ +// fileView.cpp +// +// Author: JuanJakobo +// Date: 08.09.2021 +// +//------------------------------------------------------------------- + +#include "fileView.h" +#include "fileViewEntry.h" +#include "fileModel.h" + +#include +#include + +using std::vector; + +FileView::FileView(const irect &contentRect, const vector &files, int page) : ListView(contentRect, page) +{ + auto pageHeight = 0; + auto contentHeight = _contentRect->h - _footerHeight; + auto entrycount = files.size(); + + _entries.reserve(entrycount); + + auto i = 0; + while (i < entrycount) + { + auto entrySize = TextRectHeight(contentRect->w, files.at(i).name.c_str(), 0) + 2.5 * _entryFontHeight; + if ((pageHeight + entrySize) > contentHeight) + { + pageHeight = 0; + _page++; + } + irect rect = iRect(_contentRect->x, _contentRect->y + pageHeight, _contentRect->w, entrySize, 0); + + _entries.emplace_back(std::unique_ptr(new FileViewEntry(_page, rect, files.at(i)))); + + i++; + pageHeight = pageHeight + entrySize; + } + draw(); +} + diff --git a/src/ui/fileView/fileView.h b/src/ui/fileView/fileView.h new file mode 100644 index 0000000..abb00e3 --- /dev/null +++ b/src/ui/fileView/fileView.h @@ -0,0 +1,35 @@ +//------------------------------------------------------------------ +// fileView.h +// +// Author: JuanJakobo +// Date: 08.09.2021 +// Description: An UI class to display items in a listview +//------------------------------------------------------------------- + +#ifndef FILEVIEW +#define FILEVIEW + +#include "fileModel.h" +#include "listView.h" +#include "fileViewEntry.h" + +#include +#include + +class FileView final : public ListView +{ +public: + /** + * Displays a list view + * + * @param ContentRect area of the screen where the list view is placed + * @param Items items that shall be shown in the listview + * @param page page that is shown, default is 1 + */ + FileView(const irect &contentRect, const std::vector &files, int page = 1); + + File &getCurrentEntry() { return getEntry(_selectedEntry); }; + + File &getEntry(int entryID) { return std::dynamic_pointer_cast(_entries.at(entryID))->get(); }; +}; +#endif diff --git a/src/ui/fileView/fileViewEntry.cpp b/src/ui/fileView/fileViewEntry.cpp new file mode 100644 index 0000000..f2da96c --- /dev/null +++ b/src/ui/fileView/fileViewEntry.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------ +// fileViewEntry.cpp +// +// Author: JuanJakobo +// Date: 08.09.2021 +// +//------------------------------------------------------------------- + +#include "fileViewEntry.h" +#include "fileModel.h" + +#include + +FileViewEntry::FileViewEntry(int page, const irect &position, const File &entry) : ListViewEntry(page, position), _entry(entry) +{ +} + +void FileViewEntry::draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) +{ + SetFont(entryFontBold, BLACK); + int heightOfTitle = TextRectHeight(_position.w, _entry.name.c_str(), 0); + DrawTextRect(_position.x, _position.y, _position.w, heightOfTitle, _entry.name.c_str(), ALIGN_LEFT); + + SetFont(entryFont, BLACK); + + //DrawTextRect(_position.x, _position.y + heightOfTitle, _position.w, fontHeight, _entry.name.c_str(), ALIGN_LEFT); + DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, _entry.path.c_str(), ALIGN_LEFT); + std::string type = "File"; + if(_entry.type == Type::FOLDER) + type = "Folder"; + DrawTextRect(_position.x, _position.y + heightOfTitle + fontHeight, _position.w, fontHeight, type.c_str(), ALIGN_RIGHT); + + int line = (_position.y + _position.h) - 1; + DrawLine(0, line, ScreenWidth(), line, BLACK); +} diff --git a/src/ui/fileView/fileViewEntry.h b/src/ui/fileView/fileViewEntry.h new file mode 100644 index 0000000..dd0785d --- /dev/null +++ b/src/ui/fileView/fileViewEntry.h @@ -0,0 +1,41 @@ +//------------------------------------------------------------------ +// fileViewEntry.h +// +// Author: JuanJakobo +// Date: 08.09.2021 +// Description: +//------------------------------------------------------------------- + +#ifndef FILEVIEWENTRY +#define FILEVIEWENTRY + +#include "listViewEntry.h" +#include "fileModel.h" + +class FileViewEntry : public ListViewEntry +{ +public: + /** + * Creates an FileViewEntry + * + * @param Page site of the listView the Entry is shown + * @param Rect area of the screen the item is positioned + * @param entry entry that shall be drawn + */ + FileViewEntry(int page, const irect &position, const File &entry); + + /** + * draws the FileViewEntry to the screen + * + * @param entryFont font for the entry itself + * @param entryFontBold bold font for the header + * @param fontHeight height of the font + */ + void draw(const ifont *entryFont, const ifont *entryFontBold, int fontHeight) override; + + File &get() { return _entry; }; + +private: + File _entry; +}; +#endif