Minsky
minsky::Grid< Cell > Class Template Referenceabstract

#include <grid.h>

Inheritance diagram for minsky::Grid< Cell >:
Inheritance graph
Collaboration diagram for minsky::Grid< Cell >:
Collaboration graph

Public Member Functions

virtual ~Grid ()=default
 
virtual Cell & cell (unsigned row, unsigned col)=0
 return reference to cell row, col. Reference is valid until next call to cell() More...
 
virtual unsigned numRows () const =0
 
virtual unsigned numCols () const =0
 
virtual JustificationStruct::Justification justification (unsigned col) const
 justification of col More...
 
virtual bool evenHeight () const
 whether cells all have the same height or not More...
 
void draw ()
 draw the grid More...
 
int colX (double x) const
 column at x in unzoomed coordinates More...
 
int rowY (double y) const
 row at y in unzoomed coordinates More...
 

Public Attributes

std::vector< double > rightColMargin
 coordinates of right and bottom margins of cells. Valid after draw() More...
 
std::vector< double > bottomRowMargin
 

Private Member Functions

virtual void moveCursorTo (double x, double y)=0
 move current cursor to x,y More...
 
 CLASSDESC_ACCESS (Grid)
 

Additional Inherited Members

- Public Types inherited from minsky::JustificationStruct
enum  Justification { left, right, centre }
 

Detailed Description

template<class Cell>
class minsky::Grid< Cell >

Definition at line 43 of file grid.h.

Constructor & Destructor Documentation

◆ ~Grid()

template<class Cell>
virtual minsky::Grid< Cell >::~Grid ( )
virtualdefault

Member Function Documentation

◆ cell()

template<class Cell>
virtual Cell& minsky::Grid< Cell >::cell ( unsigned  row,
unsigned  col 
)
pure virtual

return reference to cell row, col. Reference is valid until next call to cell()

Implemented in minsky::VariablePane.

◆ CLASSDESC_ACCESS()

template<class Cell>
minsky::Grid< Cell >::CLASSDESC_ACCESS ( Grid< Cell >  )
private

◆ colX()

template<class Cell >
int minsky::Grid< Cell >::colX ( double  x) const

column at x in unzoomed coordinates

Definition at line 103 of file grid.cc.

104  {
105  if (rightColMargin.empty() || x<0 || x>=rightColMargin.back())
106  return -1;
107  auto p=std::upper_bound(rightColMargin.begin(), rightColMargin.end(), x);
108  return p-rightColMargin.begin();
109  }
std::vector< double > rightColMargin
coordinates of right and bottom margins of cells. Valid after draw()
Definition: grid.h:59

◆ draw()

template<class Cell >
void minsky::Grid< Cell >::draw ( )

draw the grid

Definition at line 42 of file grid.cc.

Referenced by minsky::VariablePane::redraw().

43  {
44  bottomRowMargin.clear();
45  if (evenHeight())
46  {
47  const double rowHeight=cell(0,0).height();
48  for (unsigned i=0; i<numRows(); ++i)
49  bottomRowMargin.push_back((i+1)*rowHeight);
50  }
51  else
52  {
53  double y=0;
54  for (unsigned i=0; i<numRows(); ++i)
55  {
56  double rowHeight=0;
57  for (unsigned j=0; j<numCols(); ++j)
58  rowHeight=std::max(rowHeight, cell(i,j).height());
59  y+=rowHeight;
60  bottomRowMargin.push_back(y);
61  }
62  }
63  assert(bottomRowMargin.size()==numRows());
64 
65  rightColMargin.clear();
66  double x=0;
67  for (unsigned col=0; col<numCols(); ++col)
68  {
69  double colWidth=0, y=0;
70  switch (justification(col))
71  {
72  case right: case centre:
73  // work out column width
74  for (unsigned row=0; row<numRows(); ++row)
75  colWidth=std::max(colWidth,cell(row,col).width()+padx);
76  break;
77  default:
78  break;
79  }
80 
81 
82  for (unsigned row=0; row<numRows(); ++row)
83  {
84  auto& currentCell=cell(row,col);
85  double offset=0;
86  switch (justification(col))
87  {
88  case left: break;
89  case right: offset+=colWidth-currentCell.width(); break;
90  case centre: offset+=0.5*(colWidth-currentCell.width()); break;
91  }
92  moveCursorTo(x+offset+0.5*padx,y);
93  currentCell.show();
94  colWidth=std::max(colWidth, currentCell.width()+padx);
95  y=bottomRowMargin[row];
96  }
97  x+=colWidth;
98  rightColMargin.push_back(x);
99  }
100  }
constexpr double padx
padding between cells
Definition: grid.cc:38
std::vector< double > rightColMargin
coordinates of right and bottom margins of cells. Valid after draw()
Definition: grid.h:59
virtual bool evenHeight() const
whether cells all have the same height or not
Definition: grid.h:57
virtual void moveCursorTo(double x, double y)=0
move current cursor to x,y
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
virtual unsigned numRows() const =0
Here is the caller graph for this function:

◆ evenHeight()

template<class Cell>
virtual bool minsky::Grid< Cell >::evenHeight ( ) const
inlinevirtual

whether cells all have the same height or not

Reimplemented in minsky::VariablePane.

Definition at line 57 of file grid.h.

57 {return true;}

◆ justification()

template<class Cell>
virtual JustificationStruct::Justification minsky::Grid< Cell >::justification ( unsigned  col) const
inlinevirtual

justification of col

Definition at line 55 of file grid.h.

◆ moveCursorTo()

template<class Cell>
virtual void minsky::Grid< Cell >::moveCursorTo ( double  x,
double  y 
)
privatepure virtual

move current cursor to x,y

Implemented in minsky::VariablePane.

◆ numCols()

template<class Cell>
virtual unsigned minsky::Grid< Cell >::numCols ( ) const
pure virtual

Implemented in minsky::VariablePane.

◆ numRows()

template<class Cell>
virtual unsigned minsky::Grid< Cell >::numRows ( ) const
pure virtual

Implemented in minsky::VariablePane.

◆ rowY()

template<class Cell >
int minsky::Grid< Cell >::rowY ( double  y) const

row at y in unzoomed coordinates

Definition at line 112 of file grid.cc.

113  {
114  if (bottomRowMargin.empty() || y<0 || y>=bottomRowMargin.back())
115  return -1;
116  auto p=std::upper_bound(bottomRowMargin.begin(), bottomRowMargin.end(), y);
117  return p-bottomRowMargin.begin();
118  }
std::vector< double > bottomRowMargin
Definition: grid.h:59

Member Data Documentation

◆ bottomRowMargin

template<class Cell>
std::vector<double> minsky::Grid< Cell >::bottomRowMargin

Definition at line 59 of file grid.h.

◆ rightColMargin

template<class Cell>
std::vector<double> minsky::Grid< Cell >::rightColMargin

coordinates of right and bottom margins of cells. Valid after draw()

Definition at line 59 of file grid.h.


The documentation for this class was generated from the following files: