ofxOui - UI Components for OpenFrameworks

ofxOuiMatrix.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiMatrix.hpp
3  *
4  * Button Matrix (supports both button -single-button activation- and toggle
5  * -multi-button activation-)
6  *
7  * This code has been authored by Jules Francoise <jfrancoi@sfu.ca>
8  * during his postdoc contract at Simon Fraser University (MovingStories
9  * project).
10  * See:
11  * http://julesfrancoise.com/
12  * http://movingstories.ca/
13  *
14  * Copyright (C) 2016 Jules Francoise.
15  *
16  * This Source Code Form is subject to the terms of the Mozilla Public
17  * License, v. 2.0. If a copy of the MPL was not distributed with this
18  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
19  */
20 
21 #ifndef ofxOuiMatrix_hpp
22 #define ofxOuiMatrix_hpp
23 
24 #include "ofxOuiButton.hpp"
25 
26 namespace ofxOui {
27 
33 class Matrix : public Component {
34  public:
38  class ClickEvent : public ofEventArgs {
39  public:
47  ClickEvent(Matrix* sender_, int row_, int col_, bool value_);
48 
53 
54  int row;
55  int col;
56  bool value;
57  };
58 
67  template <typename T, typename args, class ListenerClass>
68  void onClick(T* owner, void (ListenerClass::*listenerMethod)(args)) {
69  using namespace std::placeholders;
70  if (owner)
71  click_event_callback_ = std::bind(listenerMethod, owner, _1);
72  else
73  click_event_callback_ = nullptr;
74  }
75 
83  Matrix(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
84 
88  virtual ~Matrix();
89 
93  virtual void setup();
94 
98  virtual void update();
99 
103  virtual void draw();
104 
108  int rows;
109 
113  int cols;
114 
118  float padding;
119 
125  bool toggle;
126 
130  bool draw_grid;
131 
136 
140  vector<vector<Button>> buttons;
141 
142  protected:
143  void mouseDragged(ofMouseEventArgs& e);
145 
146  ofRectangle grid_rect_;
150  std::function<void(Matrix::ClickEvent&)> click_event_callback_;
151 };
152 }
153 
154 #endif
virtual void update()
OF-like update function.
Definition: ofxOuiMatrix.cpp:80
int rows
number of rows
Definition: ofxOuiMatrix.hpp:108
int col
Definition: ofxOuiMatrix.hpp:55
Event arguments for button clicks.
Definition: ofxOuiMatrix.hpp:38
void onButtonClick(Button::ClickEvent &e)
Definition: ofxOuiMatrix.cpp:137
Shape
Base shape of the UI components.
Definition: ofxOuiCommon.hpp:73
virtual void setup()
Setup the Matrix layout.
Definition: ofxOuiMatrix.cpp:44
int cols
number of columns
Definition: ofxOuiMatrix.hpp:113
virtual ~Matrix()
Destructor.
Definition: ofxOuiMatrix.cpp:39
void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiMatrix.cpp:122
Button const * selected_button_
Definition: ofxOuiMatrix.hpp:149
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
ClickEvent(Matrix *sender_, int row_, int col_, bool value_)
Constructor.
Definition: ofxOuiMatrix.cpp:154
Button component (allows both button and toggle modes)
Definition: ofxOuiButton.hpp:31
ofRectangle grid_rect_
Definition: ofxOuiMatrix.hpp:146
float padding
padding between matrix buttons
Definition: ofxOuiMatrix.hpp:118
int row
Definition: ofxOuiMatrix.hpp:54
Matrix * sender
pointer to the sender component
Definition: ofxOuiMatrix.hpp:52
virtual void draw()
OF-like draw function.
Definition: ofxOuiMatrix.cpp:94
Definition: ofxOuiColormap.hpp:25
vector< vector< Button > > buttons
Matrix of button GUIs.
Definition: ofxOuiMatrix.hpp:140
Event arguments for button clicks.
Definition: ofxOuiButton.hpp:36
void onClick(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for click events.
Definition: ofxOuiMatrix.hpp:68
Shape button_shape
shape of individual buttons
Definition: ofxOuiMatrix.hpp:135
float button_height_
Definition: ofxOuiMatrix.hpp:148
bool draw_grid
specifies if the grid between buttons should be drawn
Definition: ofxOuiMatrix.hpp:130
Matrix(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiMatrix.cpp:23
float button_width_
Definition: ofxOuiMatrix.hpp:147
std::function< void(Matrix::ClickEvent &)> click_event_callback_
Definition: ofxOuiMatrix.hpp:150
bool value
Definition: ofxOuiMatrix.hpp:56
Button Matrix (supports both button -single-button activation- and toggle -multi-button activation-) ...
Definition: ofxOuiMatrix.hpp:33
bool toggle
specifies if the matrix works in toggle with several buttons that can be activated at the same time o...
Definition: ofxOuiMatrix.hpp:125