Table sort and selection functionality

This commit is contained in:
Jack Andersen 2015-12-31 14:12:19 -10:00
parent f9abc7c6dc
commit 35ad8827a7
8 changed files with 438 additions and 48 deletions

View File

@ -26,6 +26,7 @@ public:
};
private:
Type m_type;
HECL::SystemString m_path;
std::vector<HECL::SystemString> m_comps;
class LeftSide : public View
@ -112,7 +113,7 @@ private:
}
} m_fileFieldBind;
struct FileListingDataBind : ITableDataBinding
struct FileListingDataBind : ITableDataBinding, ITableStateBinding
{
struct Entry
{
@ -184,6 +185,32 @@ private:
HECL::HNFlags::B | HECL::HNFlags::Decimal);
}
}
m_needsUpdate = false;
}
bool m_sizeSort = false;
SortDirection m_sortDir = SortDirection::Ascending;
bool m_needsUpdate = false;
SortDirection getSort(size_t& cIdx) const
{
cIdx = m_sizeSort ? 2 : 0;
return m_sortDir;
}
void setSort(size_t cIdx, SortDirection dir)
{
if (cIdx == 1)
return;
m_sizeSort = cIdx == 2;
m_sortDir = dir;
m_needsUpdate = true;
}
void setSelectedRow(size_t rIdx)
{
}
FileListingDataBind(const IViewManager& vm)

View File

@ -22,6 +22,9 @@ private:
int m_scroll[2] = {};
int m_targetScroll[2] = {};
size_t m_consecutiveIdx = 0;
double m_consecutiveScroll[16][2] = {};
bool m_drawInd = false;
SolidShaderVert m_verts[4];
@ -38,6 +41,11 @@ public:
updateSize();
}
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseMove(const boo::SWindowCoord&);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
void scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll);
int getScrollX() const {return m_scroll[0];}
int getScrollY() const {return m_scroll[1];}

View File

@ -26,10 +26,12 @@ struct ITableDataBinding
struct ITableStateBinding
{
virtual float columnSplit(size_t cIdx) {return -1.0;}
virtual float getColumnSplit(size_t cIdx) const {return -1.0;}
virtual void setColumnSplit(size_t cIdx, float split) {}
virtual SortDirection sort(size_t cIdx) {return SortDirection::None;}
virtual SortDirection getSort(size_t& cIdx) const {cIdx = 0; return SortDirection::None;}
virtual void setSort(size_t cIdx, SortDirection dir) {}
virtual void setSelectedRow(size_t rIdx) {}
virtual void rowActivated(size_t rIdx) {}
};
class Table : public View
@ -40,18 +42,37 @@ class Table : public View
size_t m_maxColumns;
size_t m_rows = 0;
size_t m_columns = 0;
size_t m_selectedRow = -1;
size_t m_clickFrames = 15;
struct CellView : public View
{
Table& m_t;
std::unique_ptr<TextView> m_text;
CellView(Table& t, ViewResources& res);
size_t m_c, m_r;
CellView(Table& t, ViewResources& res, size_t c, size_t r);
bool m_selected = false;
void select();
void deselect();
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);
void draw(boo::IGraphicsCommandQueue* gfxQ);
};
std::vector<std::unique_ptr<CellView>> m_headerViews;
std::vector<std::vector<std::unique_ptr<CellView>>> m_cellViews;
std::vector<ViewChild<std::unique_ptr<CellView>>> m_headerViews;
std::vector<std::vector<ViewChild<std::unique_ptr<CellView>>>> m_cellViews;
bool m_header = false;
std::unique_ptr<SolidShaderVert[]> m_hVerts;
boo::IGraphicsBufferD* m_hVertsBuf = nullptr;
boo::IVertexFormat* m_hVtxFmt = nullptr; /* OpenGL only */
boo::IShaderDataBinding* m_hShaderBinding = nullptr;
void _setHeaderVerts(const boo::SWindowRect& rect);
ViewChild<std::unique_ptr<ScrollView>> m_scroll;
struct RowsView : public View
@ -70,14 +91,23 @@ class Table : public View
RowsView(Table& t, ViewResources& res);
int nominalHeight() const;
int nominalWidth() const {return m_t.m_scroll.m_view->nominalWidth();}
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&);
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
const boo::SWindowRect& scissor);
void draw(boo::IGraphicsCommandQueue* gfxQ);
} m_rowsView;
public:
Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state=nullptr, size_t maxColumns=8);
bool m_headerNeedsUpdate = false;
public:
Table(ViewResources& res, View& parentView, ITableDataBinding* data,
ITableStateBinding* state=nullptr, size_t maxColumns=8);
void cycleSortColumn(size_t c);
void selectRow(size_t r);
void setMultiplyColor(const Zeus::CColor& color);
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);

View File

@ -219,10 +219,10 @@ struct ViewChild
bool m_mouseIn = false;
int m_mouseDown = 0;
void mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
bool mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (!m_view)
return;
return false;
if (m_view->subRect().coordInRect(coord))
{
if ((m_mouseDown & 1 << int(button)) == 0)
@ -230,7 +230,9 @@ struct ViewChild
m_view->mouseDown(coord, button, mod);
m_mouseDown |= 1 << int(button);
}
return true;
}
return false;
}
void mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)

View File

@ -45,6 +45,7 @@ class ThemeData
Zeus::CColor m_tableCellBg1 = {0.1725, 0.1725, 0.1725, 0.75};
Zeus::CColor m_tableCellBg2 = {0.2425, 0.2425, 0.2425, 0.75};
Zeus::CColor m_tableCellBgSelected = {0.6425, 0.6425, 0.6425, 1.0};
Zeus::CColor m_scrollIndicator = {0.2823, 0.2823, 0.2823, 1.0};
@ -82,6 +83,7 @@ public:
virtual const Zeus::CColor& tableCellBg1() const {return m_tableCellBg1;}
virtual const Zeus::CColor& tableCellBg2() const {return m_tableCellBg2;}
virtual const Zeus::CColor& tableCellBgSelected() const {return m_tableCellBgSelected;}
virtual const Zeus::CColor& scrollIndicator() const {return m_scrollIndicator;}
};

View File

@ -58,7 +58,7 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, const std::string
IViewManager& vm = rootView().viewManager();
m_fileField.m_view.reset(new TextField(res, *this, &m_fileFieldBind));
m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, nullptr, 3));
m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, &m_fileListingBind, 3));
m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind, nullptr, 1));
m_systemBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont));
m_systemBookmarksLabel->typesetGlyphs(vm.translateOr("system_locations", "System Locations"), res.themeData().uiText());
@ -86,6 +86,7 @@ void FileBrowser::navigateToPath(const HECL::SystemString& path)
if (HECL::Stat(path.c_str(), &theStat))
return;
m_path = path;
m_comps = PathComponents(path);
if (S_ISREG(theStat.st_mode))
{
@ -103,8 +104,10 @@ void FileBrowser::navigateToPath(const HECL::SystemString& path)
needSlash = true;
dir += d;
}
HECL::DirectoryEnumerator dEnum(dir);
HECL::DirectoryEnumerator dEnum(dir, HECL::DirectoryEnumerator::Mode::DirsThenFilesSorted,
m_fileListingBind.m_sizeSort, m_fileListingBind.m_sortDir==SortDirection::Descending);
m_fileListingBind.updateListing(dEnum);
m_fileListing.m_view->selectRow(-1);
m_fileListing.m_view->updateData();
m_pathButtons.clear();
@ -329,6 +332,8 @@ void FileBrowser::RightSide::resized(const boo::SWindowRect& root, const boo::SW
void FileBrowser::think()
{
ModalWindow::think();
if (m_fileListingBind.m_needsUpdate)
navigateToPath(m_path);
m_fileField.m_view->think();
m_fileListing.m_view->think();
m_systemBookmarks.m_view->think();

View File

@ -78,14 +78,64 @@ bool ScrollView::_scroll(const boo::SScrollDelta& scroll)
return false;
}
void ScrollView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (m_contentView)
m_contentView->mouseDown(coord, button, mod);
}
void ScrollView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (m_contentView)
m_contentView->mouseUp(coord, button, mod);
}
void ScrollView::mouseMove(const boo::SWindowCoord& coord)
{
if (m_contentView)
m_contentView->mouseMove(coord);
}
void ScrollView::mouseEnter(const boo::SWindowCoord& coord)
{
if (m_contentView)
m_contentView->mouseEnter(coord);
}
void ScrollView::mouseLeave(const boo::SWindowCoord& coord)
{
if (m_contentView)
m_contentView->mouseLeave(coord);
}
void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll)
{
if (!scroll.isAccelerated)
{
boo::SScrollDelta newScroll = scroll;
m_consecutiveScroll[m_consecutiveIdx][0] += scroll.delta[0];
m_consecutiveScroll[m_consecutiveIdx][1] += scroll.delta[1];
newScroll.delta[0] = 0;
newScroll.delta[1] = 0;
for (size_t i=0 ; i<16 ; ++i)
{
newScroll.delta[0] += m_consecutiveScroll[i][0];
newScroll.delta[1] += m_consecutiveScroll[i][1];
}
if (_scroll(newScroll))
updateSize();
return;
}
if (_scroll(scroll))
updateSize();
}
void ScrollView::think()
{
m_consecutiveIdx = (m_consecutiveIdx+1) % 16;
m_consecutiveScroll[m_consecutiveIdx][0] = 0.0;
m_consecutiveScroll[m_consecutiveIdx][1] = 0.0;
bool update = false;
float pf = rootView().viewRes().pixelFactor();

View File

@ -4,12 +4,40 @@
namespace Specter
{
static LogVisor::LogModule Log("Specter::Table");
#define ROW_HEIGHT 18
#define CELL_MARGIN 1
Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state, size_t maxColumns)
: View(res, parentView), m_data(data), m_state(state), m_maxColumns(maxColumns), m_rowsView(*this, res)
: View(res, parentView), m_data(data), m_state(state), m_maxColumns(maxColumns),
m_hVerts(new SolidShaderVert[maxColumns * 6]), m_rowsView(*this, res)
{
if (!maxColumns)
Log.report(LogVisor::FatalError, "0-column tables not supported");
m_hVertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), maxColumns * 6);
if (!res.m_viewRes.m_texVtxFmt)
{
boo::VertexElementDescriptor vdescs[] =
{
{m_hVertsBuf, nullptr, boo::VertexSemantic::Position4},
{m_hVertsBuf, nullptr, boo::VertexSemantic::Color}
};
m_hVtxFmt = res.m_factory->newVertexFormat(2, vdescs);
boo::IGraphicsBuffer* bufs[] = {m_viewVertBlockBuf};
m_hShaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_solidShader,
m_hVtxFmt, m_hVertsBuf, nullptr,
nullptr, 1, bufs, 0, nullptr);
}
else
{
boo::IGraphicsBuffer* bufs[] = {m_viewVertBlockBuf};
m_hShaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_solidShader,
res.m_viewRes.m_texVtxFmt,
m_hVertsBuf, nullptr,
nullptr, 1, bufs, 0, nullptr);
}
commitResources(res);
m_scroll.m_view.reset(new ScrollView(res, *this, ScrollView::Style::ThinIndicator));
@ -47,8 +75,82 @@ Table::RowsView::RowsView(Table& t, ViewResources& res)
commitResources(res);
}
Table::CellView::CellView(Table& t, ViewResources& res)
: View(res, t), m_t(t), m_text(new TextView(res, *this, res.m_mainFont)) {}
Table::CellView::CellView(Table& t, ViewResources& res, size_t c, size_t r)
: View(res, t), m_t(t), m_text(new TextView(res, *this, res.m_mainFont)), m_c(c), m_r(r) {}
void Table::_setHeaderVerts(const boo::SWindowRect& sub)
{;
if (m_headerViews.empty())
return;
SolidShaderVert* v = m_hVerts.get();
const ThemeData& theme = rootView().themeData();
float pf = rootView().viewRes().pixelFactor();
int div = sub.size[0] / m_headerViews.size();
int margin = CELL_MARGIN * pf;
int rowHeight = ROW_HEIGHT * pf;
int xOff = 0;
int yOff = sub.size[1];
size_t c;
auto it = m_headerViews.cbegin();
size_t sCol = -1;
SortDirection sDir = SortDirection::None;
if (m_state)
sDir = m_state->getSort(sCol);
for (c=0 ; c<std::min(m_maxColumns, m_columns) ; ++c)
{
const ViewChild<std::unique_ptr<CellView>>& hv = *it;
const Zeus::CColor* c1 = &theme.button1Inactive();
const Zeus::CColor* c2 = &theme.button2Inactive();
if (hv.m_mouseDown && hv.m_mouseIn)
{
c1 = &theme.button1Press();
c2 = &theme.button2Press();
}
else if (hv.m_mouseIn)
{
c1 = &theme.button1Hover();
c2 = &theme.button2Hover();
}
Zeus::CColor cm1 = *c1;
Zeus::CColor cm2 = *c2;
if (sCol == c)
{
if (sDir == SortDirection::Ascending)
{
cm1 *= Zeus::CColor::skGreen;
cm2 *= Zeus::CColor::skGreen;
}
else if (sDir == SortDirection::Descending)
{
cm1 *= Zeus::CColor::skRed;
cm2 *= Zeus::CColor::skRed;
}
}
v[0].m_pos.assign(xOff + margin, yOff - margin, 0);
v[0].m_color = cm1;
v[1] = v[0];
v[2].m_pos.assign(xOff + margin, yOff - margin - rowHeight, 0);
v[2].m_color = cm2;
v[3].m_pos.assign(xOff + div - margin, yOff - margin, 0);
v[3].m_color = cm1;
v[4].m_pos.assign(xOff + div - margin, yOff - margin - rowHeight, 0);
v[4].m_color = cm2;
v[5] = v[4];
v += 6;
xOff += div;
++it;
}
if (c)
m_hVertsBuf->load(m_hVerts.get(), sizeof(SolidShaderVert) * 6 * c);
m_headerNeedsUpdate = false;
}
void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWindowRect& scissor)
{
@ -70,12 +172,13 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind
yOff += spacing;
++idx;
}
int startIdx = std::max(0, int(m_t.m_rows) - idx);
int startIdx = int(m_t.m_rows) - idx;
size_t r, c;
for (r=0, c=0 ; r<SPECTER_TABLE_MAX_ROWS && (sub.location[1] + yOff + spacing) >= scissor.location[1] ; ++r)
{
const Zeus::CColor& color = (r&1) ? theme.tableCellBg1() : theme.tableCellBg2();
const Zeus::CColor& color = (startIdx+r==m_t.m_selectedRow) ? theme.tableCellBgSelected() :
((r&1) ? theme.tableCellBg1() : theme.tableCellBg2());
int xOff = 0;
for (c=0 ; c<std::min(m_t.m_maxColumns, m_t.m_columns) ; ++c)
{
@ -94,10 +197,55 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind
}
yOff -= spacing;
}
m_visibleStart = startIdx;
m_visibleStart = std::max(0, startIdx);
m_visibleRows = r;
if (r * c)
m_vertsBuf->load(m_verts, sizeof(SolidShaderVert) * 6 * r * c);
m_vertsBuf->load(m_verts.get(), sizeof(SolidShaderVert) * 6 * r * c);
}
void Table::cycleSortColumn(size_t c)
{
if (c >= m_columns)
Log.report(LogVisor::FatalError, "cycleSortColumn out of bounds (%" PRISize ", %" PRISize ")",
c, m_columns);
if (m_state)
{
size_t cIdx;
SortDirection dir = m_state->getSort(cIdx);
if (dir == SortDirection::None || cIdx != c)
m_state->setSort(c, SortDirection::Ascending);
else if (dir == SortDirection::Ascending)
m_state->setSort(c, SortDirection::Descending);
else if (dir == SortDirection::Descending)
m_state->setSort(c, SortDirection::Ascending);
}
}
void Table::selectRow(size_t r)
{
if (r >= m_rows && r != -1)
Log.report(LogVisor::FatalError, "selectRow out of bounds (%" PRISize ", %" PRISize ")",
r, m_rows);
if (r == m_selectedRow)
return;
if (m_selectedRow != -1)
for (auto& col : m_cellViews)
{
ViewChild<std::unique_ptr<CellView>>& cv = col.at(m_selectedRow);
if (cv.m_view)
cv.m_view->deselect();
}
m_selectedRow = r;
if (m_selectedRow != -1)
for (auto& col : m_cellViews)
{
ViewChild<std::unique_ptr<CellView>>& cv = col.at(m_selectedRow);
if (cv.m_view)
cv.m_view->select();
}
updateSize();
if (m_state)
m_state->setSelectedRow(r);
}
void Table::setMultiplyColor(const Zeus::CColor& color)
@ -105,40 +253,138 @@ void Table::setMultiplyColor(const Zeus::CColor& color)
View::setMultiplyColor(color);
if (m_scroll.m_view)
m_scroll.m_view->setMultiplyColor(color);
for (std::unique_ptr<CellView>& hv : m_headerViews)
if (hv)
hv->m_text->setMultiplyColor(color);
for (ViewChild<std::unique_ptr<CellView>>& hv : m_headerViews)
if (hv.m_view)
hv.m_view->m_text->setMultiplyColor(color);
for (auto& col : m_cellViews)
{
for (std::unique_ptr<CellView>& cv : col)
if (cv)
cv->m_text->setMultiplyColor(color);
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
if (cv.m_view)
cv.m_view->m_text->setMultiplyColor(color);
}
}
void Table::CellView::select()
{
m_selected = true;
m_text->colorGlyphs(rootView().themeData().fieldText());
}
void Table::CellView::deselect()
{
m_selected = false;
m_text->colorGlyphs(rootView().themeData().uiText());
}
void Table::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
m_scroll.mouseDown(coord, button, mod);
if (m_headerNeedsUpdate)
_setHeaderVerts(subRect());
}
void Table::RowsView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
if (hv.mouseDown(coord, button, mod))
return; /* Trap header event */
for (std::vector<ViewChild<std::unique_ptr<CellView>>>& col : m_t.m_cellViews)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
cv.mouseDown(coord, button, mod);
}
void Table::CellView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (m_r != -1)
{
m_t.selectRow(m_r);
if (m_t.m_clickFrames < 15 && m_t.m_state)
m_t.m_state->rowActivated(m_r);
else
m_t.m_clickFrames = 0;
}
else
m_t.m_headerNeedsUpdate = true;
}
void Table::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
m_scroll.mouseUp(coord, button, mod);
if (m_headerNeedsUpdate)
_setHeaderVerts(subRect());
}
void Table::RowsView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
size_t idx = 0;
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
{
if (hv.m_mouseDown && hv.m_mouseIn)
m_t.cycleSortColumn(idx);
hv.mouseUp(coord, button, mod);
++idx;
}
for (std::vector<ViewChild<std::unique_ptr<CellView>>>& col : m_t.m_cellViews)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
cv.mouseUp(coord, button, mod);
}
void Table::CellView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{
if (m_r == -1)
m_t.m_headerNeedsUpdate = true;
}
void Table::mouseMove(const boo::SWindowCoord& coord)
{
m_scroll.mouseMove(coord);
if (m_headerNeedsUpdate)
_setHeaderVerts(subRect());
}
void Table::RowsView::mouseMove(const boo::SWindowCoord& coord)
{
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
hv.mouseMove(coord);
for (std::vector<ViewChild<std::unique_ptr<CellView>>>& col : m_t.m_cellViews)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
cv.mouseMove(coord);
}
void Table::mouseEnter(const boo::SWindowCoord& coord)
{
m_scroll.mouseEnter(coord);
if (m_headerNeedsUpdate)
_setHeaderVerts(subRect());
}
void Table::CellView::mouseEnter(const boo::SWindowCoord& coord)
{
if (m_r == -1)
m_t.m_headerNeedsUpdate = true;
}
void Table::mouseLeave(const boo::SWindowCoord& coord)
{
m_scroll.mouseLeave(coord);
if (m_headerNeedsUpdate)
_setHeaderVerts(subRect());
}
void Table::RowsView::mouseLeave(const boo::SWindowCoord& coord)
{
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
hv.mouseLeave(coord);
for (std::vector<ViewChild<std::unique_ptr<CellView>>>& col : m_t.m_cellViews)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
cv.mouseLeave(coord);
}
void Table::CellView::mouseLeave(const boo::SWindowCoord& coord)
{
if (m_r == -1)
m_t.m_headerNeedsUpdate = true;
}
void Table::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll)
@ -150,20 +396,33 @@ void Table::think()
{
if (m_scroll.m_view)
m_scroll.m_view->think();
++m_clickFrames;
}
void Table::updateData()
{
m_header = false;
m_headerViews.clear();
m_cellViews.clear();
bool newViewChildren = false;
if (m_columns != m_data->columnCount())
newViewChildren = true;
m_rows = m_data->rowCount();
m_columns = m_data->columnCount();
if (!m_columns)
return;
if (newViewChildren)
{
m_headerViews.clear();
m_cellViews.clear();
m_headerViews.reserve(m_columns);
m_cellViews.reserve(m_columns);
for (size_t c=0 ; c<m_columns ; ++c)
{
m_headerViews.emplace_back();
m_cellViews.emplace_back();
}
}
ViewResources& res = rootView().viewRes();
const Zeus::CColor& textColor = rootView().themeData().uiText();
@ -173,23 +432,24 @@ void Table::updateData()
if (headerText)
{
m_header = true;
CellView* cv = new CellView(*this, res);
m_headerViews.emplace_back(cv);
CellView* cv = new CellView(*this, res, c, -1);
m_headerViews[c].m_view.reset(cv);
cv->m_text->typesetGlyphs(*headerText, textColor);
}
else
m_headerViews.emplace_back();
m_headerViews[c].m_view.reset();
m_cellViews.emplace_back();
std::vector<std::unique_ptr<CellView>>& col = m_cellViews.back();
std::vector<ViewChild<std::unique_ptr<CellView>>>& col = m_cellViews[c];
col.clear();
col.reserve(m_rows);
for (size_t r=0 ; r<m_rows ; ++r)
{
const std::string* cellText = m_data->cell(c, r);
if (cellText)
{
CellView* cv = new CellView(*this, res);
col.emplace_back(cv);
CellView* cv = new CellView(*this, res, c, r);
col.emplace_back();
col.back().m_view.reset(cv);
cv->m_text->typesetGlyphs(*cellText, textColor);
}
else
@ -211,11 +471,13 @@ void Table::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
cell.size[1] = ROW_HEIGHT * pf;
cell.location[1] += sub.size[1] - cell.size[1];
int div = sub.size[0] / m_cellViews.size();
cell.size[0] = div;
for (std::unique_ptr<CellView>& hv : m_headerViews)
_setHeaderVerts(sub);
for (ViewChild<std::unique_ptr<CellView>>& hv : m_headerViews)
{
if (hv)
hv->resized(root, cell);
if (hv.m_view)
hv.m_view->resized(root, cell);
cell.location[0] += div;
}
}
@ -241,6 +503,7 @@ void Table::RowsView::resized(const boo::SWindowRect& root, const boo::SWindowRe
float pf = rootView().viewRes().pixelFactor();
int div = sub.size[0] / m_t.m_cellViews.size();
boo::SWindowRect cell = sub;
cell.size[0] = div;
cell.size[1] = ROW_HEIGHT * pf;
cell.location[1] += sub.size[1] - cell.size[1];
int spacing = (ROW_HEIGHT + CELL_MARGIN * 2) * pf;
@ -248,11 +511,11 @@ void Table::RowsView::resized(const boo::SWindowRect& root, const boo::SWindowRe
for (auto& col : m_t.m_cellViews)
{
cell.location[1] = hStart;
for (std::unique_ptr<CellView>& cv : col)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
{
cell.location[1] -= spacing;
if (cv)
cv->resized(root, cell);
if (cv.m_view)
cv.m_view->resized(root, cell);
}
cell.location[0] += div;
}
@ -287,10 +550,10 @@ void Table::RowsView::draw(boo::IGraphicsCommandQueue* gfxQ)
for (auto& col : m_t.m_cellViews)
{
size_t idx = 0;
for (std::unique_ptr<CellView>& cv : col)
for (ViewChild<std::unique_ptr<CellView>>& cv : col)
{
if (cv && idx >= m_visibleStart && idx < m_visibleStart + m_visibleRows)
cv->draw(gfxQ);
if (cv.m_view && idx >= m_visibleStart && idx < m_visibleStart + m_visibleRows)
cv.m_view->draw(gfxQ);
++idx;
}
}
@ -298,9 +561,12 @@ void Table::RowsView::draw(boo::IGraphicsCommandQueue* gfxQ)
if (m_t.m_header)
{
for (std::unique_ptr<CellView>& hv : m_t.m_headerViews)
if (hv)
hv->draw(gfxQ);
gfxQ->setShaderDataBinding(m_t.m_hShaderBinding);
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
gfxQ->draw(1, m_t.m_columns * 6 - 2);
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
if (hv.m_view)
hv.m_view->draw(gfxQ);
}
}