#pragma once namespace roro { // Selection and scrolling for a grid of `cols` columns showing `visibleRows` rows at a time, filled // row by row. Left and Right go through every item and wrap around; Up and Down stay in the // column and wrap around, landing on the last item where the last row has no such column. class GridModel { public: GridModel(int cols, int visibleRows) : cols_(cols), rows_(visibleRows) {} void setCount(int count); int count() const { return count_; } int selected() const { return selected_; } // -1 when empty int cols() const { return cols_; } int rows() const { return count_ ? (count_ - 1) / cols_ + 1 : 0; } int firstVisibleRow() const { return first_; } int visibleRows() const { return rows_; } void select(int index); void left(); void right(); void up(); void down(); private: int cols_, rows_; int count_ = 0; int selected_ = -1; int first_ = 0; }; } // namespace roro