Minsky
minsky::ButtonWidget< rowCol > Class Template Reference

supports +/-/←/→/↓/↑ widget More...

#include <godleyTableWindow.h>

Inheritance diagram for minsky::ButtonWidget< rowCol >:
Inheritance graph
Collaboration diagram for minsky::ButtonWidget< rowCol >:
Collaboration graph

Public Member Functions

void draw (cairo_t *)
 
void drawButton (cairo_t *, const std::string &label, double r, double g, double b, int idx)
 draw button idx, with label label and colour r, b, g More...
 
void invoke (double x)
 invoke action associated with button at x More...
 
void hover (int button)
 indicate which button mouse is hovering over. x<0 means not hovering More...
 
void hover (double x)
 
int button (double x) const
 convert x coordinate into a button More...
 
int mouseOver () const
 
 ButtonWidget (GodleyIcon &godleyIcon, unsigned idx=0)
 
template<>
void invoke (double x)
 
template<>
void invoke (double x)
 

Public Attributes

Pos pos =middle
 
unsigned idx =0
 row or column this widget is located in More...
 

Static Public Attributes

static constexpr double buttonSpacing =15
 

Protected Attributes

GodleyIcongodleyIcon
 
int m_mouseOver =-1
 

Private Member Functions

 CLASSDESC_ACCESS (ButtonWidget)
 

Additional Inherited Members

- Public Types inherited from minsky::ButtonWidgetEnums
enum  RowCol { row, col }
 
enum  Pos {
  first, second, middle, last,
  firstAndLast
}
 

Detailed Description

template<minsky::ButtonWidgetEnums::RowCol rowCol>
class minsky::ButtonWidget< rowCol >

supports +/-/←/→/↓/↑ widget

Definition at line 45 of file godleyTableWindow.h.

Constructor & Destructor Documentation

◆ ButtonWidget()

template<minsky::ButtonWidgetEnums::RowCol rowCol>
minsky::ButtonWidget< rowCol >::ButtonWidget ( GodleyIcon godleyIcon,
unsigned  idx = 0 
)
inline

Definition at line 70 of file godleyTableWindow.h.

70  :
unsigned idx
row or column this widget is located in

Member Function Documentation

◆ button()

template<minsky::ButtonWidgetEnums::RowCol rowCol>
int minsky::ButtonWidget< rowCol >::button ( double  x) const
inline

convert x coordinate into a button

Definition at line 67 of file godleyTableWindow.h.

Referenced by minsky::ButtonWidget< row >::hover().

67 {return x/buttonSpacing;}
static constexpr double buttonSpacing
Here is the caller graph for this function:

◆ CLASSDESC_ACCESS()

template<minsky::ButtonWidgetEnums::RowCol rowCol>
minsky::ButtonWidget< rowCol >::CLASSDESC_ACCESS ( ButtonWidget< rowCol >  )
private

◆ draw()

template<ButtonWidgetEnums::RowCol rowCol>
void minsky::ButtonWidget< rowCol >::draw ( cairo_t *  cairo)

Definition at line 1197 of file godleyTableWindow.cc.

1198  {
1199  const CairoSave cs(cairo);
1200  int idx=0;
1201  if (rowCol==row || (!cminsky().multipleEquities() && godleyIcon.table.singleEquity())) { // no column widgets on equity column in single equity column mode
1202  if (rowCol == row || (rowCol == col && pos!=last))
1203  drawButton(cairo,"+",0,1,0,idx++);
1204  if ((rowCol == row && pos!=first && pos!=firstAndLast) || (rowCol == col && pos!=last)) // no delete button for first row containing initial conditions. For ticket 1064
1205  drawButton(cairo,"—",1,0,0,idx++);
1206  if ((rowCol == row && pos!=first && pos!=second && pos!=firstAndLast) || (rowCol == col && pos!=first && pos!=last)) // no move up button for first row containing initial conditions. For ticket 1064
1207  drawButton(cairo,rowCol==row? "↑": "←",0,0,0,idx++);
1208  if ((pos!=first && pos!=last && pos!=firstAndLast) || (rowCol == col && pos!=last)) // no move down button for first row containing initial conditions. For ticket 1064
1209  drawButton(cairo,rowCol==row? "↓": "→",0,0,0,idx++);
1210  } else {
1211  drawButton(cairo,"+",0,1,0,idx++);
1212  if ((pos!=first && pos!=firstAndLast) || rowCol == col) // no delete button for first row containing initial conditions. For ticket 1064
1213  drawButton(cairo,"—",1,0,0,idx++);
1214  if (pos!=first && pos!=second && pos!=firstAndLast) // no move up button for first row containing initial conditions. For ticket 1064
1215  drawButton(cairo,rowCol==row? "↑": "←",0,0,0,idx++);
1216  if ((pos!=first && pos!=last && pos!=firstAndLast) || (rowCol == col && pos!=last)) // no move down button for first row containing initial conditions. For ticket 1064
1217  drawButton(cairo,rowCol==row? "↓": "→",0,0,0,idx++);
1218  }
1219 
1220  }
bool singleEquity() const
Check whether more than one equity column is present irrespective of single or multiple equity column...
Definition: godleyTable.cc:196
unsigned idx
row or column this widget is located in
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
void drawButton(cairo_t *, const std::string &label, double r, double g, double b, int idx)
draw button idx, with label label and colour r, b, g

◆ drawButton()

template<ButtonWidgetEnums::RowCol rowCol>
void minsky::ButtonWidget< rowCol >::drawButton ( cairo_t *  cairo,
const std::string &  label,
double  r,
double  g,
double  b,
int  idx 
)

draw button idx, with label label and colour r, b, g

Definition at line 1171 of file godleyTableWindow.cc.

1172  {
1173  // stash current point for drawing a box
1174  double x0, y0;
1175  cairo_get_current_point(cairo,&x0, &y0);
1176 
1177  const CairoSave cs(cairo);
1178  Pango pango(cairo);
1179  // increase text size a bit for the buttons
1180  pango.setFontSize(0.8*buttonSpacing);
1181  pango.setMarkup(label);
1182  cairo_set_source_rgb(cairo,r,g,b);
1183  pango.show();
1184 
1185  // draw box around button
1186  cairo_rectangle(cairo, x0, y0+0.2*pango.height(), buttonSpacing, buttonSpacing);
1187  if (idx==m_mouseOver)
1188  cairo_set_source_rgb(cairo,0,0,0); // draw in black if mouse over button
1189  else
1190  cairo_set_source_rgb(cairo,0.5,0.5,0.5); // draw in grey
1191  cairo_set_line_width(cairo,1);
1192  cairo_stroke(cairo);
1193  cairo_move_to(cairo,x0+buttonSpacing,y0);
1194  }
unsigned idx
row or column this widget is located in
static constexpr double buttonSpacing

◆ hover() [1/2]

template<minsky::ButtonWidgetEnums::RowCol rowCol>
void minsky::ButtonWidget< rowCol >::hover ( int  button)
inline

indicate which button mouse is hovering over. x<0 means not hovering

Definition at line 64 of file godleyTableWindow.h.

int button(double x) const
convert x coordinate into a button

◆ hover() [2/2]

template<minsky::ButtonWidgetEnums::RowCol rowCol>
void minsky::ButtonWidget< rowCol >::hover ( double  x)
inline

Definition at line 65 of file godleyTableWindow.h.

65 {m_mouseOver=button(x);}
int button(double x) const
convert x coordinate into a button

◆ invoke() [1/3]

template<minsky::ButtonWidgetEnums::RowCol rowCol>
void minsky::ButtonWidget< rowCol >::invoke ( double  x)

invoke action associated with button at x

◆ invoke() [2/3]

template<>
void minsky::ButtonWidget< ButtonWidgetEnums::row >::invoke ( double  x)

Definition at line 75 of file godleyTableWindow.cc.

76  {
77  const int button=x/buttonSpacing;
78  switch (button)
79  {
80  case 0:
82  break;
83  case 1:
84  if (pos!=first && pos!=firstAndLast) godleyIcon.deleteRow(idx+1); // Initial conditions row cannot be deleted, even when it is the only row in the table. For ticket 1064
85  break;
86  case 2:
87  if (pos==second) // Third button of second row cannot swap initial conditions and second row. For ticket 1064
89  else if (pos!=first && pos!=firstAndLast) // Third button cannot swap column headings and initial conditions row values. For ticket 1064
91  break;
92  case 3:
93  if (pos==middle) // Fourth button on first and second row cannot move initial conditions row. For ticket 1064
95  break;
96  }
97  try {godleyIcon.update();} // Update current Godley icon and table after button widget invoke. for ticket 1059.
98  catch (...) {}
99  }
unsigned idx
row or column this widget is located in
int button(double x) const
convert x coordinate into a button
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void moveRow(int row, int n)
move row row down by n places (up if -ve)
Definition: godleyTable.cc:98
void insertRow(unsigned row)
insert row at row
Definition: godleyTable.cc:59
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:289
static constexpr double buttonSpacing
void deleteRow(unsigned row)
delete row before row
Definition: godleyIcon.cc:225

◆ invoke() [3/3]

template<>
void minsky::ButtonWidget< ButtonWidgetEnums::col >::invoke ( double  x)

Definition at line 102 of file godleyTableWindow.cc.

103  {
104  const int button=x/buttonSpacing;
105  if (!cminsky().multipleEquities() && godleyIcon.table.singleEquity()) { // no column widgets on equity column in single equity column mode
106  if (pos!=last)
107  switch (button)
108  {
109  case 0:
111  break;
112  case 1:
114  break;
115  case 2:
116  if (pos==first)
118  else if (pos!=first)
120  break;
121  case 3:
122  if (pos==middle)
124  break;
125  }
126  } else {
127  switch (button)
128  {
129  case 0:
131  break;
132  case 1:
134  break;
135  case 2:
136  if (pos==first)
138  else
140  break;
141  case 3:
142  if (pos==middle)
144  break;
145  }
146  }
147  try {godleyIcon.update();} // Update current Godley icon and table after button widget invoke. for ticket 1059.
148  catch (...) {}
149  }
bool singleEquity() const
Check whether more than one equity column is present irrespective of single or multiple equity column...
Definition: godleyTable.cc:196
void deleteCol(unsigned col)
delete col before col
Definition: godleyTable.cc:83
void moveCol(int col, int n)
Definition: godleyTable.cc:109
unsigned idx
row or column this widget is located in
int button(double x) const
convert x coordinate into a button
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void update()
updates the variable lists with the Godley table
Definition: godleyIcon.cc:289
static constexpr double buttonSpacing
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
void insertCol(unsigned col)
insert col at col
Definition: godleyTable.cc:68

◆ mouseOver()

template<minsky::ButtonWidgetEnums::RowCol rowCol>
int minsky::ButtonWidget< rowCol >::mouseOver ( ) const
inline

Definition at line 68 of file godleyTableWindow.h.

Member Data Documentation

◆ buttonSpacing

template<minsky::ButtonWidgetEnums::RowCol rowCol>
constexpr double minsky::ButtonWidget< rowCol >::buttonSpacing =15
static

Definition at line 52 of file godleyTableWindow.h.

Referenced by minsky::ButtonWidget< row >::button().

◆ godleyIcon

template<minsky::ButtonWidgetEnums::RowCol rowCol>
GodleyIcon& minsky::ButtonWidget< rowCol >::godleyIcon
protected

Definition at line 49 of file godleyTableWindow.h.

◆ idx

template<minsky::ButtonWidgetEnums::RowCol rowCol>
unsigned minsky::ButtonWidget< rowCol >::idx =0

row or column this widget is located in

Definition at line 55 of file godleyTableWindow.h.

◆ m_mouseOver

template<minsky::ButtonWidgetEnums::RowCol rowCol>
int minsky::ButtonWidget< rowCol >::m_mouseOver =-1
protected

◆ pos

template<minsky::ButtonWidgetEnums::RowCol rowCol>
Pos minsky::ButtonWidget< rowCol >::pos =middle

Definition at line 54 of file godleyTableWindow.h.


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