ofxOui - UI Components for OpenFrameworks

ofxOuiDropDown.hpp
Go to the documentation of this file.
1 /*
2  * ofxOuiDropDown.hpp
3  *
4  * Dropdown Menu
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 ofxOuiDropDown_hpp
21 #define ofxOuiDropDown_hpp
22 
23 #include "ofxOuiButton.hpp"
24 
25 namespace ofxOui {
26 
31 class DropDown : public Component {
32  public:
36  class SelectEvent : public ofEventArgs {
37  public:
43  SelectEvent(DropDown *sender_, string text_);
44 
49 
53  string text;
54  };
55 
64  template <typename T, typename args, class ListenerClass>
65  void onSelect(T *owner, void (ListenerClass::*listenerMethod)(args)) {
66  using namespace std::placeholders;
67  if (owner)
68  select_event_callback_ = std::bind(listenerMethod, owner, _1);
69  else
70  select_event_callback_ = nullptr;
71  }
72 
80  DropDown(int x_ = 0, int y_ = 0, int width_ = 0, int height_ = 0);
81 
85  virtual ~DropDown();
86 
90  virtual void update();
91 
95  virtual void draw();
96 
100  vector<string> items;
101 
102  protected:
103  void createSubGui();
104  void mouseMoved(ofMouseEventArgs &e);
105  void mouseDragged(ofMouseEventArgs &e);
106  void mousePressed(ofMouseEventArgs &e);
107  void mouseReleased(ofMouseEventArgs &e);
108 
110  bool clear_buttons_ = false;
111  vector<shared_ptr<ofxOui::Button>> sub_buttons_;
112  std::function<void(DropDown::SelectEvent &)> select_event_callback_;
113 };
114 }
115 
116 #endif
vector< shared_ptr< ofxOui::Button > > sub_buttons_
Definition: ofxOuiDropDown.hpp:111
string text
label of the selected menu item
Definition: ofxOuiDropDown.hpp:53
void mouseDragged(ofMouseEventArgs &e)
Definition: ofxOuiDropDown.cpp:76
Base UI Component (equivalent to a label)
Definition: ofxOuiComponent.hpp:33
Drop-down menu.
Definition: ofxOuiDropDown.hpp:31
DropDown * sender
pointer to the sender component
Definition: ofxOuiDropDown.hpp:48
vector< string > items
list of items contained in the menu
Definition: ofxOuiDropDown.hpp:100
void mouseMoved(ofMouseEventArgs &e)
Definition: ofxOuiDropDown.cpp:71
bool clear_buttons_
Definition: ofxOuiDropDown.hpp:110
void mousePressed(ofMouseEventArgs &e)
Definition: ofxOuiDropDown.cpp:81
virtual void update()
OF-like update function.
Definition: ofxOuiDropDown.cpp:49
virtual void draw()
OF-like draw function.
Definition: ofxOuiDropDown.cpp:62
void createSubGui()
Definition: ofxOuiDropDown.cpp:116
bool mouse_moved_
Definition: ofxOuiDropDown.hpp:109
virtual ~DropDown()
Destructor.
Definition: ofxOuiDropDown.cpp:37
DropDown(int x_=0, int y_=0, int width_=0, int height_=0)
Constructor.
Definition: ofxOuiDropDown.cpp:22
Definition: ofxOuiColormap.hpp:25
void onSelect(T *owner, void(ListenerClass::*listenerMethod)(args))
Set callback function for item selection events.
Definition: ofxOuiDropDown.hpp:65
Event arguments for menu item selection.
Definition: ofxOuiDropDown.hpp:36
std::function< void(DropDown::SelectEvent &)> select_event_callback_
Definition: ofxOuiDropDown.hpp:112
SelectEvent(DropDown *sender_, string text_)
Constructor.
Definition: ofxOuiDropDown.cpp:130
void mouseReleased(ofMouseEventArgs &e)
Definition: ofxOuiDropDown.cpp:94