creativity  v1.3.0
Agent-based model of creativity and piracy
InfoWindow.hpp
1 #pragma once
2 #include <eris/types.hpp>
3 #include <gtkmm/window.h>
4 #include <gtkmm/notebook.h>
5 #include <gtkmm/grid.h>
6 #include <gtkmm/label.h>
7 #include <gtkmm/scrolledwindow.h>
8 #include <list>
9 #include <string>
10 #include <type_traits>
11 #include <unordered_map>
12 #include <utility>
13 #include <vector>
14 #include <memory>
15 #include <Eigen/Core>
16 
17 namespace creativity { namespace state { class State; } }
18 
19 namespace creativity { namespace gui {
20 
23 class InfoWindow : public Gtk::Window {
24  public:
26  InfoWindow() = delete;
27 
30  const eris::eris_id_t id;
31 
33  virtual void refresh(std::shared_ptr<const state::State> state) = 0;
34 
35  protected:
42  InfoWindow(std::shared_ptr<Gtk::Window> main_window, eris::eris_id_t id, const std::string &title);
43 
47  template <class T, typename = typename std::enable_if<std::is_arithmetic<T>::value>::type>
48  void updateValue(const std::string &code, const T &val) {
49  updateValue(code, std::to_string(val));
50  }
51 
53  void updateValue(const std::string &code, const std::string &val);
54 
59  void updateMatrix(const std::string &code, const Eigen::Ref<const Eigen::MatrixXd> &m, bool lower_triangle = false);
60 
64  void clearMatrix(const std::string &code, const std::string &value = "");
65 
67  std::unordered_map<std::string, std::pair<Gtk::Label, Gtk::Label>> fields_;
69  std::unordered_map<std::string, std::vector<std::unique_ptr<Gtk::Label>>> matrix_;
71  std::list<Gtk::Grid> grids_;
73  std::list<Gtk::Label> labels_;
75  std::list<Gtk::Notebook> nbs_;
77  std::list<Gtk::ScrolledWindow> swins_;
78 
80  int gpos_ = 0;
81 
82  // Initialization helper functions:
83 
85  Gtk::Grid& new_grid();
89  Gtk::Grid& new_tab_grid(Gtk::Notebook &notebook, const std::string &title);
93  void data_at(Gtk::Grid &grid, const std::string &code, const std::string &value_name, int row, int col,
94  double label_align = 1.0, double value_align = 0.0);
96  void data_append(Gtk::Grid &grid, const std::string &code, const std::string &value_name,
97  double label_align = 1.0, double value_align = 0.0);
101  void label_at(Gtk::Grid &grid, const std::string &label, double alignment, int row, int col, int width, int height);
105  void labels_at(Gtk::Grid &grid, const std::string &label1, const std::string &label2, int row, int col);
107  void labels_append(Gtk::Grid &grid, const std::string &label1, const std::string &label2);
109  void comment_append(Gtk::Grid &grid, const std::string &comment, int cols = 2);
115  void matrix_at(Gtk::Grid &grid, const std::string &code, const std::string &name, int row, int col, int nrows, int ncols);
116 
120  unsigned long t_ = (unsigned long) -1;
122  bool initial_refresh_ = true;
123 };
124 
125 } }
std::list< Gtk::Grid > grids_
Grid for the display.
Definition: InfoWindow.hpp:71
std::list< Gtk::Label > labels_
Stored labels that aren&#39;t fields (i.e. single labels)
Definition: InfoWindow.hpp:73
Primary namespace for all Creativity library code.
Definition: config.hpp:4
const eris::eris_id_t id
The eris_id of the simulation object about which this dialog is displaying details.
Definition: InfoWindow.hpp:30
std::list< Gtk::ScrolledWindow > swins_
Any scrolled windows used.
Definition: InfoWindow.hpp:77
std::unordered_map< std::string, std::pair< Gtk::Label, Gtk::Label > > fields_
Fields containing a pair of labels: description and value.
Definition: InfoWindow.hpp:67
Gtk dialog for showing reader or book info.
Definition: InfoWindow.hpp:23
std::list< Gtk::Notebook > nbs_
Notebooks for the tabs.
Definition: InfoWindow.hpp:75
std::unordered_map< std::string, std::vector< std::unique_ptr< Gtk::Label > > > matrix_
Field containing a description and a matrix of values.
Definition: InfoWindow.hpp:69
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.
Definition: InfoWindow.hpp:48