creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
creativity::gui::InfoWindow Class Referenceabstract

Gtk dialog for showing reader or book info. More...

#include <creativity/gui/InfoWindow.hpp>

Public Member Functions

 InfoWindow ()=delete
 No default constructor.
 
virtual void refresh (std::shared_ptr< const state::State > state)=0
 Refresh the information in the dialog using the given simulation state. More...
 

Public Attributes

const eris::eris_id_t id
 The eris_id of the simulation object about which this dialog is displaying details.
 

Protected Member Functions

 InfoWindow (std::shared_ptr< Gtk::Window > main_window, eris::eris_id_t id, const std::string &title)
 Creates a new InfoWindow, setting up the dialog window. More...
 
template<class T , typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
void updateValue (const std::string &code, const T &val)
 Updates a single value Gtk::Label text with the given value by passing it to std::to_string.
 
void updateValue (const std::string &code, const std::string &val)
 Updates a single value Gtk::Label text with the given string.
 
void updateMatrix (const std::string &code, const Eigen::Ref< const Eigen::MatrixXd > &m, bool lower_triangle=false)
 Updates a matrix set up with matrix_at with the values of the given matrix. More...
 
void clearMatrix (const std::string &code, const std::string &value="")
 Clears all values of a matrix set up with matrix_at, setting all values to the given value (defaulting to an empty string).
 
Gtk::Grid & new_grid ()
 Create a new grid, store it, return a reference to it (but don't add to any element)
 
Gtk::Grid & new_tab_grid (Gtk::Notebook &notebook, const std::string &title)
 Create a new grid and adds it as the content of new tab "title" on notebook, returns a reference to it.
 
void data_at (Gtk::Grid &grid, const std::string &code, const std::string &value_name, int row, int col, double label_align=1.0, double value_align=0.0)
 Creates a "value: data" label pair with labels stored in fields_ that can be updated later. More...
 
void data_append (Gtk::Grid &grid, const std::string &code, const std::string &value_name, double label_align=1.0, double value_align=0.0)
 Calls data_at to put the label at (gpos_, 0), then increments gpos_.
 
void label_at (Gtk::Grid &grid, const std::string &label, double alignment, int row, int col, int width, int height)
 Creates a label at the given location, taking up the given number of rows and columns, with horizontal alignment as given (0-1). More...
 
void labels_at (Gtk::Grid &grid, const std::string &label1, const std::string &label2, int row, int col)
 Creates a pair of single-cell labels at the given (row,col) and (row,col+1). More...
 
void labels_append (Gtk::Grid &grid, const std::string &label1, const std::string &label2)
 Creates a pair of static labels at the current (gpos_) row, first two columns.
 
void comment_append (Gtk::Grid &grid, const std::string &comment, int cols=2)
 Creates a static, wrapping, multi-column label, at the current (gpos_) row.
 
void matrix_at (Gtk::Grid &grid, const std::string &code, const std::string &name, int row, int col, int nrows, int ncols)
 Creates labels for a matrix of the given size in the grid with [0,0] element at (row+1,col+1), storing the labels in row-major order in matrix_. More...
 

Protected Attributes

std::unordered_map< std::string, std::pair< Gtk::Label, Gtk::Label > > fields_
 Fields containing a pair of labels: description and value.
 
std::unordered_map< std::string, std::vector< std::unique_ptr< Gtk::Label > > > matrix_
 Field containing a description and a matrix of values.
 
std::list< Gtk::Grid > grids_
 Grid for the display.
 
std::list< Gtk::Label > labels_
 Stored labels that aren't fields (i.e. single labels)
 
std::list< Gtk::Notebook > nbs_
 Notebooks for the tabs.
 
std::list< Gtk::ScrolledWindow > swins_
 Any scrolled windows used.
 
int gpos_ = 0
 The global label position, used during setup.
 
unsigned long t_ = (unsigned long) -1
 The time currently being shown (don't need to do anything in refresh() if this doesn't change.
 
bool initial_refresh_ = true
 On the initial refresh, don't replace the book model.
 

Detailed Description

Gtk dialog for showing reader or book info.

Base class; see ReaderInfoWindow and BookInfoWindow.

Constructor & Destructor Documentation

§ InfoWindow()

creativity::gui::InfoWindow::InfoWindow ( std::shared_ptr< Gtk::Window >  main_window,
eris::eris_id_t  id,
const std::string &  title 
)
protected

Creates a new InfoWindow, setting up the dialog window.

Parameters
main_windowthe parent Gtk::Window this window attaches to
idthe eris id of the displayed element
titlethe window title

Member Function Documentation

§ data_at()

void creativity::gui::InfoWindow::data_at ( Gtk::Grid &  grid,
const std::string &  code,
const std::string &  value_name,
int  row,
int  col,
double  label_align = 1.0,
double  value_align = 0.0 
)
protected

Creates a "value: data" label pair with labels stored in fields_ that can be updated later.

The pair of labels is located at (row,col) and (row,col+1).

§ label_at()

void creativity::gui::InfoWindow::label_at ( Gtk::Grid &  grid,
const std::string &  label,
double  alignment,
int  row,
int  col,
int  width,
int  height 
)
protected

Creates a label at the given location, taking up the given number of rows and columns, with horizontal alignment as given (0-1).

Intended for static values.

§ labels_at()

void creativity::gui::InfoWindow::labels_at ( Gtk::Grid &  grid,
const std::string &  label1,
const std::string &  label2,
int  row,
int  col 
)
protected

Creates a pair of single-cell labels at the given (row,col) and (row,col+1).

The first is right-aligned, the second is left-aligned.

§ matrix_at()

void creativity::gui::InfoWindow::matrix_at ( Gtk::Grid &  grid,
const std::string &  code,
const std::string &  name,
int  row,
int  col,
int  nrows,
int  ncols 
)
protected

Creates labels for a matrix of the given size in the grid with [0,0] element at (row+1,col+1), storing the labels in row-major order in matrix_.

updateMatrix() can later be called to update the label values to a given matrix. (row,col) gets the given label, and the remainder of the row and column get position labels.

§ refresh()

virtual void creativity::gui::InfoWindow::refresh ( std::shared_ptr< const state::State state)
pure virtual

Refresh the information in the dialog using the given simulation state.

Implemented in creativity::gui::ReaderInfoWindow, and creativity::gui::BookInfoWindow.

§ updateMatrix()

void creativity::gui::InfoWindow::updateMatrix ( const std::string &  code,
const Eigen::Ref< const Eigen::MatrixXd > &  m,
bool  lower_triangle = false 
)
protected

Updates a matrix set up with matrix_at with the values of the given matrix.

If the optional lower_triangle parameter is given as true, only the lower diagonal of the matrix is displayed; the upper-triangle values are set to blanks.

Inheritance diagram for creativity::gui::InfoWindow:
[legend]
Collaboration diagram for creativity::gui::InfoWindow:
[legend]

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