ofxOui - UI Components for OpenFrameworks

ofxOuiTextInput.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiTextInput.hpp
3  *
4  * Text Input Element (single-line text I guess...)
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 ofxOuiTextInput_hpp
21 #define ofxOuiTextInput_hpp
22 
23 #include "../core/ofxOuiComponent.hpp"
24 
25 namespace ofxOui {
26 
31 class TextInput : public Component {
32  public:
36  class TextInputEvent : public ofEventArgs {
37  public:
38  TextInputEvent(TextInput *sender_, string text_);
39 
44 
45  string text;
46  };
47 
56  template <typename T, typename args, class ListenerClass>
57  void onTextInput(T *owner, void (ListenerClass::*listenerMethod)(args)) {
58  using namespace std::placeholders;
59  if (owner)
60  text_input_event_callback_ = std::bind(listenerMethod, owner, _1);
61  else
63  }
64 
72  TextInput(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
73 
77  virtual ~TextInput();
78 
79  protected:
80  virtual void drawLabel();
81  void mouseMoved(ofMouseEventArgs &e);
82  void mouseDragged(ofMouseEventArgs &e);
83  void mousePressed(ofMouseEventArgs &e);
84  void mouseReleased(ofMouseEventArgs &e);
85  void keyPressed(ofKeyEventArgs &e);
86 
88  std::function<void(TextInput::TextInputEvent &)> text_input_event_callback_;
89 };
90 }
91 
92 #endif
Event arguments for text editing events.
Definition: ofxOuiTextInput.hpp:36
void keyPressed(ofKeyEventArgs &e)
Definition: ofxOuiTextInput.cpp:90
void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiTextInput.cpp:65
TextInputEvent(TextInput *sender_, string text_)
Definition: ofxOuiTextInput.cpp:111
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
void mouseReleased(ofMouseEventArgs &e)
Definition: ofxOuiTextInput.cpp:86
void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiTextInput.cpp:70
string text
Definition: ofxOuiTextInput.hpp:45
void mouseMoved(ofMouseEventArgs &e)
Definition: ofxOuiTextInput.cpp:60
Text input component (single-line)
Definition: ofxOuiTextInput.hpp:31
void onTextInput(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for text input events.
Definition: ofxOuiTextInput.hpp:57
TextInput * sender
pointer to the sender component
Definition: ofxOuiTextInput.hpp:43
Definition: ofxOuiColormap.hpp:25
virtual void drawLabel()
Definition: ofxOuiTextInput.cpp:51
TextInput(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiTextInput.cpp:22
std::function< void(TextInput::TextInputEvent &)> text_input_event_callback_
Definition: ofxOuiTextInput.hpp:88
bool erase_on_next_input_
Definition: ofxOuiTextInput.hpp:87
virtual ~TextInput()
Destructor.
Definition: ofxOuiTextInput.cpp:38