ofxOui - UI Components for OpenFrameworks

ofxOuiButton.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiButton.hpp
3  *
4  * Button component (with toggle mode)
5  *
6  * This code has been authored by Jules Francoise <jfrancoi@sfu.ca>
7  * during his postdoc contract at Simon Fraser University (MovingStories
8  * project).
9  * See:
10  * http://julesfrancoise.com/
11  * http://movingstories.ca/
12  *
13  * Copyright (C) 2016 Jules Francoise.
14  *
15  * This Source Code Form is subject to the terms of the Mozilla Public
16  * License, v. 2.0. If a copy of the MPL was not distributed with this
17  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
18  */
19 
20 #ifndef ofxOuiButton_hpp
21 #define ofxOuiButton_hpp
22 
23 #include "../core/ofxOuiComponent.hpp"
24 
25 namespace ofxOui {
26 
31 class Button : public Component {
32  public:
36  class ClickEvent : public ofEventArgs {
37  public:
43  ClickEvent(Button* sender_, bool value_);
44 
49 
53  bool value;
54  };
55 
63  Button(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
64 
68  virtual ~Button();
69 
78  template <typename T, typename args, class ListenerClass>
79  void onClick(T* owner, void (ListenerClass::*listenerMethod)(args)) {
80  using namespace std::placeholders;
81  if (owner)
82  click_event_callback_ = std::bind(listenerMethod, owner, _1);
83  else
84  click_event_callback_ = nullptr;
85  }
86 
90  virtual void update();
91 
95  bool toggle;
96 
97  protected:
98  virtual void mousePressed(ofMouseEventArgs& e);
99 
101  std::function<void(Button::ClickEvent&)> click_event_callback_;
102 };
103 }
104 
105 #endif
virtual void update()
OF-like update function.
Definition: ofxOuiButton.cpp:36
void onClick(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for click events.
Definition: ofxOuiButton.hpp:79
Button * sender
pointer to the sender component
Definition: ofxOuiButton.hpp:48
int num_frames_on_
Definition: ofxOuiButton.hpp:100
bool toggle
specifies if the button works as button or toggle
Definition: ofxOuiButton.hpp:95
Button(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiButton.cpp:22
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
virtual ~Button()
Destructor.
Definition: ofxOuiButton.cpp:31
Button component (allows both button and toggle modes)
Definition: ofxOuiButton.hpp:31
std::function< void(Button::ClickEvent &)> click_event_callback_
Definition: ofxOuiButton.hpp:101
virtual void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiButton.cpp:46
ClickEvent(Button *sender_, bool value_)
Constructor.
Definition: ofxOuiButton.cpp:62
Definition: ofxOuiColormap.hpp:25
bool value
button value
Definition: ofxOuiButton.hpp:53
Event arguments for button clicks.
Definition: ofxOuiButton.hpp:36