2015-11-21 01:14:49 +00:00
|
|
|
#ifndef SPECTER_TABLE_HPP
|
|
|
|
#define SPECTER_TABLE_HPP
|
|
|
|
|
2015-12-15 21:53:15 +00:00
|
|
|
#include "View.hpp"
|
2015-12-23 00:25:46 +00:00
|
|
|
#include "ScrollView.hpp"
|
2015-12-29 02:02:43 +00:00
|
|
|
#include "TextView.hpp"
|
2015-12-15 21:53:15 +00:00
|
|
|
|
|
|
|
namespace Specter
|
|
|
|
{
|
2015-12-30 02:20:24 +00:00
|
|
|
#define SPECTER_TABLE_MAX_ROWS 128ul
|
|
|
|
#define SPECTER_TABLE_MAX_COLUMNS 32ul
|
2015-12-23 00:25:46 +00:00
|
|
|
|
|
|
|
enum class SortDirection
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Ascending,
|
|
|
|
Descending
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ITableDataBinding
|
|
|
|
{
|
|
|
|
virtual size_t columnCount() const=0;
|
|
|
|
virtual size_t rowCount() const=0;
|
|
|
|
virtual const std::string* header(size_t cIdx) const {return nullptr;}
|
|
|
|
virtual const std::string* cell(size_t cIdx, size_t rIdx) const {return nullptr;}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ITableStateBinding
|
|
|
|
{
|
|
|
|
virtual float columnSplit(size_t cIdx) {return -1.0;}
|
|
|
|
virtual void setColumnSplit(size_t cIdx, float split) {}
|
|
|
|
virtual SortDirection sort(size_t cIdx) {return SortDirection::None;}
|
|
|
|
virtual void setSort(size_t cIdx, SortDirection dir) {}
|
|
|
|
};
|
2015-12-15 21:53:15 +00:00
|
|
|
|
|
|
|
class Table : public View
|
|
|
|
{
|
2015-12-23 00:25:46 +00:00
|
|
|
ITableDataBinding* m_data;
|
|
|
|
ITableStateBinding* m_state;
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
size_t m_rows = 0;
|
|
|
|
size_t m_columns = 0;
|
|
|
|
struct CellView : public View
|
|
|
|
{
|
|
|
|
Table& m_t;
|
|
|
|
std::unique_ptr<TextView> m_text;
|
|
|
|
CellView(Table& t, ViewResources& res);
|
|
|
|
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
|
|
|
|
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
|
|
|
};
|
|
|
|
std::vector<std::unique_ptr<CellView>> m_headerViews;
|
|
|
|
std::vector<std::vector<std::unique_ptr<CellView>>> m_cellViews;
|
|
|
|
bool m_header = false;
|
|
|
|
|
2015-12-23 00:25:46 +00:00
|
|
|
ViewChild<std::unique_ptr<ScrollView>> m_scroll;
|
|
|
|
|
|
|
|
struct RowsView : public View
|
|
|
|
{
|
|
|
|
Table& m_t;
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2015-12-30 02:20:24 +00:00
|
|
|
SolidShaderVert m_verts[SPECTER_TABLE_MAX_ROWS * SPECTER_TABLE_MAX_COLUMNS * 6];
|
2015-12-29 22:58:09 +00:00
|
|
|
boo::IGraphicsBufferD* m_vertsBuf = nullptr;
|
|
|
|
boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */
|
|
|
|
boo::IShaderDataBinding* m_shaderBinding = nullptr;
|
|
|
|
size_t m_visibleStart = 0;
|
|
|
|
size_t m_visibleRows = 0;
|
|
|
|
boo::SWindowRect m_scissorRect;
|
|
|
|
void _setRowVerts(const boo::SWindowRect& rowsRect, const boo::SWindowRect& scissor);
|
|
|
|
|
|
|
|
RowsView(Table& t, ViewResources& res);
|
2015-12-29 02:02:43 +00:00
|
|
|
int nominalHeight() const;
|
2015-12-29 22:58:09 +00:00
|
|
|
int nominalWidth() const {return m_t.m_scroll.m_view->nominalWidth();}
|
2015-12-29 02:02:43 +00:00
|
|
|
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
|
|
|
|
const boo::SWindowRect& scissor);
|
2015-12-23 00:25:46 +00:00
|
|
|
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
|
|
|
} m_rowsView;
|
|
|
|
|
2015-12-15 21:53:15 +00:00
|
|
|
public:
|
2015-12-23 00:25:46 +00:00
|
|
|
Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state=nullptr);
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
void setMultiplyColor(const Zeus::CColor& color);
|
|
|
|
|
2015-12-23 00:25:46 +00:00
|
|
|
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
|
|
|
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
2015-12-29 02:02:43 +00:00
|
|
|
void mouseMove(const boo::SWindowCoord&);
|
2015-12-23 00:25:46 +00:00
|
|
|
void mouseEnter(const boo::SWindowCoord&);
|
|
|
|
void mouseLeave(const boo::SWindowCoord&);
|
|
|
|
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta&);
|
|
|
|
|
2015-12-29 22:58:09 +00:00
|
|
|
void think();
|
2015-12-29 02:02:43 +00:00
|
|
|
void updateData();
|
2015-12-23 00:25:46 +00:00
|
|
|
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
|
|
|
|
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
2015-12-15 21:53:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-21 01:14:49 +00:00
|
|
|
#endif // SPECTER_TABLE_HPP
|