prepare fileClasses for folder selection
parent
b7900b3d10
commit
1c6d6da0e9
|
@ -0,0 +1,28 @@
|
|||
//------------------------------------------------------------------
|
||||
// fileModel.h
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 23.04.2021
|
||||
// Description:
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifndef FILEMODEL
|
||||
#define FILEMODEL
|
||||
|
||||
//#include "model.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
enum Type
|
||||
{
|
||||
FOLDER,
|
||||
FIL
|
||||
};
|
||||
|
||||
struct File : Entry{
|
||||
std::string name;
|
||||
std::string path;
|
||||
Type type;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,44 @@
|
|||
//------------------------------------------------------------------
|
||||
// fileView.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "fileView.h"
|
||||
#include "fileViewEntry.h"
|
||||
#include "fileModel.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::vector;
|
||||
|
||||
FileView::FileView(const irect &contentRect, const vector<File> &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<FileViewEntry>(new FileViewEntry(_page, rect, files.at(i))));
|
||||
|
||||
i++;
|
||||
pageHeight = pageHeight + entrySize;
|
||||
}
|
||||
draw();
|
||||
}
|
||||
|
|
@ -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 <vector>
|
||||
#include <memory>
|
||||
|
||||
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<File> &files, int page = 1);
|
||||
|
||||
File &getCurrentEntry() { return getEntry(_selectedEntry); };
|
||||
|
||||
File &getEntry(int entryID) { return std::dynamic_pointer_cast<FileViewEntry>(_entries.at(entryID))->get(); };
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,35 @@
|
|||
//------------------------------------------------------------------
|
||||
// fileViewEntry.cpp
|
||||
//
|
||||
// Author: JuanJakobo
|
||||
// Date: 08.09.2021
|
||||
//
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#include "fileViewEntry.h"
|
||||
#include "fileModel.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue