Files
Upsilon/apps/shared/store_selectable_table_view.cpp
Hugo Saint-Vignes ada369bf08 [apps/shared] Add comment for selectNonHiddenCellAtClippedLocation
Change-Id: I0e0f7963274688facb467caa934f410e66c9f859
2020-11-04 14:45:34 +01:00

45 lines
1.6 KiB
C++

#include "store_selectable_table_view.h"
namespace Shared {
StoreSelectableTableView::StoreSelectableTableView(DoublePairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, SelectableTableViewDelegate * delegate) :
SelectableTableView(parentResponder, dataSource, selectionDataSource, delegate),
m_store(store)
{
}
bool StoreSelectableTableView::handleEvent(Ion::Events::Event event) {
int step = Ion::Events::repetitionFactor();
if (event == Ion::Events::Down) {
return selectNonHiddenCellAtClippedLocation(selectedColumn(), selectedRow() + step);
}
if (event == Ion::Events::Up) {
return selectNonHiddenCellAtClippedLocation(selectedColumn(), selectedRow() - step);
}
if (event == Ion::Events::Left) {
return selectNonHiddenCellAtClippedLocation(selectedColumn() - step, selectedRow());
}
if (event == Ion::Events::Right) {
return selectNonHiddenCellAtClippedLocation(selectedColumn() + step, selectedRow());
}
return false;
}
bool StoreSelectableTableView::selectNonHiddenCellAtClippedLocation(int i, int j) {
// Clip i to retrieve a valid seriesIndex
if (i < 0) {
i = 0;
} else if (i >= dataSource()->numberOfColumns()) {
i = dataSource()->numberOfColumns() - 1;
}
int seriesIndex = i / DoublePairStore::k_numberOfColumnsPerSeries;
int numberOfPairsOfCurrentSeries = m_store->numberOfPairsOfSeries(seriesIndex);
if (j > 1 + numberOfPairsOfCurrentSeries) {
j = 1 + numberOfPairsOfCurrentSeries;
}
// if negative, j will be clipped in selectCellAtClippedLocation
return selectCellAtClippedLocation(i, j);
}
}