ofxOui - UI Components for OpenFrameworks

ofxOuiNumbox.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiNumbox.hpp
3  *
4  * Number box (with mouse + keyboard interaction, C74 max style)
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 ofxOuiNumbox_hpp
21 #define ofxOuiNumbox_hpp
22 
23 #include "../core/ofxOuiComponent.hpp"
24 
25 namespace ofxOui {
26 
31 class Numbox : public Component {
32  public:
36  class ValueEvent : public ofEventArgs {
37  public:
43  ValueEvent(Numbox *sender_, float value_);
44 
49 
53  float value;
54  };
55 
64  template <typename T, typename args, class ListenerClass>
65  void onEditValue(T *owner, void (ListenerClass::*listenerMethod)(args)) {
66  using namespace std::placeholders;
67  if (owner)
68  numbox_event_callback_ = std::bind(listenerMethod, owner, _1);
69  else
70  numbox_event_callback_ = nullptr;
71  }
72 
80  Numbox(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
81 
85  virtual ~Numbox();
86 
90  virtual void update();
91 
95  float value;
96 
100  float min;
101 
105  float max;
106 
111 
112  protected:
113  virtual void drawLabel();
114  void clipValue();
115  virtual void mouseDragged(ofMouseEventArgs &e);
116  virtual void mousePressed(ofMouseEventArgs &e);
117  virtual void mouseReleased(ofMouseEventArgs &e);
118  virtual void keyPressed(ofKeyEventArgs &e);
119 
120  bool dragging_;
121  string user_input_;
125  float drag_step_;
126  std::function<void(Numbox::ValueEvent &)> numbox_event_callback_;
127 };
128 }
129 
130 #endif
virtual void mouseReleased(ofMouseEventArgs &e)
Definition: ofxOuiNumbox.cpp:124
string user_input_
Definition: ofxOuiNumbox.hpp:121
float drag_step_
Definition: ofxOuiNumbox.hpp:125
virtual ~Numbox()
Destructor.
Definition: ofxOuiNumbox.cpp:42
virtual void keyPressed(ofKeyEventArgs &e)
Definition: ofxOuiNumbox.cpp:132
float value
value of the number box
Definition: ofxOuiNumbox.hpp:53
int y_pressed_
Definition: ofxOuiNumbox.hpp:122
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
virtual void drawLabel()
Definition: ofxOuiNumbox.cpp:74
std::function< void(Numbox::ValueEvent &)> numbox_event_callback_
Definition: ofxOuiNumbox.hpp:126
void clipValue()
Definition: ofxOuiNumbox.cpp:69
virtual void update()
OF-like update function.
Definition: ofxOuiNumbox.cpp:53
float value
value of the number box
Definition: ofxOuiNumbox.hpp:95
ValueEvent(Numbox *sender_, float value_)
Constructor.
Definition: ofxOuiNumbox.cpp:173
Text box font wrapper.
Definition: ofxOuiTextBox.hpp:31
Numbox(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiNumbox.cpp:21
virtual void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiNumbox.cpp:86
float min
minimum value
Definition: ofxOuiNumbox.hpp:100
virtual void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiNumbox.cpp:101
Number box (with mouse + keyboard interaction, C74 max style)
Definition: ofxOuiNumbox.hpp:31
Event arguments for value editing events.
Definition: ofxOuiNumbox.hpp:36
Definition: ofxOuiColormap.hpp:25
float max
maximum value
Definition: ofxOuiNumbox.hpp:105
float value_pressed_
Definition: ofxOuiNumbox.hpp:123
Numbox * sender
pointer to the sender component
Definition: ofxOuiNumbox.hpp:48
bool dragging_
Definition: ofxOuiNumbox.hpp:120
void onEditValue(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for value editing events.
Definition: ofxOuiNumbox.hpp:65
int precision
precision of the number display
Definition: ofxOuiNumbox.hpp:110
TextBox value_text_
Definition: ofxOuiNumbox.hpp:124