metaforce/specter/include/Specter/Table.hpp

146 lines
4.8 KiB
C++
Raw Normal View History

2015-11-21 01:14:49 +00:00
#ifndef SPECTER_TABLE_HPP
#define SPECTER_TABLE_HPP
#include "View.hpp"
#include "ScrollView.hpp"
2015-12-29 02:02:43 +00:00
#include "TextView.hpp"
#include <array>
namespace Specter
{
#define SPECTER_TABLE_MAX_ROWS 128ul
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
{
2016-01-01 00:12:19 +00:00
virtual float getColumnSplit(size_t cIdx) const {return -1.0;}
virtual bool columnSplitResizeAllowed() const {return false;}
virtual void setColumnSplit(size_t cIdx, float split) {}
2016-01-01 00:12:19 +00:00
virtual SortDirection getSort(size_t& cIdx) const {cIdx = 0; return SortDirection::None;}
virtual void setSort(size_t cIdx, SortDirection dir) {}
2016-01-01 00:12:19 +00:00
virtual void setSelectedRow(size_t rIdx) {}
virtual void rowActivated(size_t rIdx) {}
};
class Table : public View
{
ITableDataBinding* m_data;
ITableStateBinding* m_state;
size_t m_maxColumns;
2015-12-29 02:02:43 +00:00
size_t m_rows = 0;
size_t m_columns = 0;
2016-01-01 00:12:19 +00:00
size_t m_selectedRow = -1;
2016-01-02 04:17:47 +00:00
size_t m_deferredActivation = -1;
2016-01-01 00:12:19 +00:00
size_t m_clickFrames = 15;
2015-12-29 02:02:43 +00:00
struct CellView : public View
{
Table& m_t;
std::unique_ptr<TextView> m_text;
2016-01-01 00:12:19 +00:00
size_t m_c, m_r;
boo::SWindowRect m_scissorRect;
uint64_t m_textHash = 0;
CellView(Table& t, ViewResources& res);
2016-01-01 00:12:19 +00:00
bool m_selected = false;
void select();
void deselect();
void reset();
bool reset(size_t c);
bool reset(size_t c, size_t r);
2016-01-01 00:12:19 +00:00
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
const boo::SWindowRect& scissor);
2015-12-29 02:02:43 +00:00
void draw(boo::IGraphicsCommandQueue* gfxQ);
};
2016-01-01 00:12:19 +00:00
std::vector<ViewChild<std::unique_ptr<CellView>>> m_headerViews;
using ColumnPool = std::array<std::array<ViewChild<std::unique_ptr<CellView>>, SPECTER_TABLE_MAX_ROWS>, 2>;
std::vector<ColumnPool> m_cellPools;
size_t m_ensuredRows = 0;
std::vector<ColumnPool>& ensureCellPools(size_t rows, size_t cols, ViewResources& res);
size_t m_activePool = -1;
2015-12-29 02:02:43 +00:00
bool m_header = false;
std::vector<boo::SWindowRect> m_hCellRects;
size_t m_hDraggingIdx = 0;
2016-01-01 00:12:19 +00:00
std::unique_ptr<SolidShaderVert[]> m_hVerts;
VertexBufferBinding m_vertsBinding;
2016-01-01 00:12:19 +00:00
void _setHeaderVerts(const boo::SWindowRect& rect);
std::vector<boo::SWindowRect> getCellRects(const boo::SWindowRect& tableRect) const;
ViewChild<std::unique_ptr<ScrollView>> m_scroll;
struct RowsView : public View
{
Table& m_t;
2015-12-29 22:58:09 +00:00
std::unique_ptr<SolidShaderVert[]> m_verts;
VertexBufferBinding m_vertsBinding;
2015-12-29 22:58:09 +00:00
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();}
2016-01-01 00:12:19 +00:00
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseMove(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
2015-12-29 02:02:43 +00:00
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
const boo::SWindowRect& scissor);
void draw(boo::IGraphicsCommandQueue* gfxQ);
} m_rowsView;
2016-01-01 00:12:19 +00:00
bool m_headerNeedsUpdate = false;
2016-01-03 04:04:02 +00:00
bool m_inSelectRow = false;
void _updateData();
2016-01-01 00:12:19 +00:00
public:
2016-01-01 00:12:19 +00:00
Table(ViewResources& res, View& parentView, ITableDataBinding* data,
ITableStateBinding* state=nullptr, size_t maxColumns=8);
2016-01-01 00:12:19 +00:00
void cycleSortColumn(size_t c);
void selectRow(size_t r);
2015-12-29 02:02:43 +00:00
void setMultiplyColor(const Zeus::CColor& color);
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&);
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();
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ);
};
}
2015-11-21 01:14:49 +00:00
#endif // SPECTER_TABLE_HPP