Minsky: 3.17.0
grid.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2021
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef GRID_H
21 #define GRID_H
22 #include <vector>
23 #include "classdesc_access.h"
24 
25 namespace minsky
26 {
28  class ICell
29  {
30  public:
31  virtual ~ICell()=default;
32  virtual void show()=0;
33  virtual double width() const=0;
34  virtual double height() const=0;
35  };
36 
38  {
40  };
41 
42  template <class Cell>
43  class Grid: public JustificationStruct
44  {
46  virtual void moveCursorTo(double x, double y)=0;
48  public:
49  virtual ~Grid()=default;
51  virtual Cell& cell(unsigned row, unsigned col)=0;
52  virtual unsigned numRows() const=0;
53  virtual unsigned numCols() const=0;
55  virtual JustificationStruct::Justification justification(unsigned col) const {return left;};
57  virtual bool evenHeight() const {return true;}
59  std::vector<double> rightColMargin, bottomRowMargin;
61  void draw();
63  int colX(double x) const;
65  int rowY(double y) const;
66 
67  };
68 
69 }
70 
71 #include "grid.cd"
72 #endif
virtual void show()=0
render onto cairo surface
virtual double height() const =0
height of cell
virtual ~Grid()=default
std::vector< double > rightColMargin
coordinates of right and bottom margins of cells. Valid after draw()
Definition: grid.h:59
int colX(double x) const
column at x in unzoomed coordinates
Definition: grid.cc:103
virtual bool evenHeight() const
whether cells all have the same height or not
Definition: grid.h:57
CLASSDESC_ACCESS(Grid)
Cell template parameter duck types this interface.
Definition: grid.h:28
virtual void moveCursorTo(double x, double y)=0
move current cursor to x,y
virtual ~ICell()=default
int rowY(double y) const
row at y in unzoomed coordinates
Definition: grid.cc:112
std::vector< double > bottomRowMargin
Definition: grid.h:59
virtual unsigned numCols() const =0
virtual Cell & cell(unsigned row, unsigned col)=0
return reference to cell row, col. Reference is valid until next call to cell()
virtual JustificationStruct::Justification justification(unsigned col) const
justification of col
Definition: grid.h:55
void draw()
draw the grid
Definition: grid.cc:42
virtual unsigned numRows() const =0
virtual double width() const =0
width of cell on canvas