54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
/*
|
|
nanogui/combobox.h -- simple combo box widget based on a popup button
|
|
|
|
NanoGUI was developed by Wenzel Jakob <wenzel@inf.ethz.ch>.
|
|
The widget drawing code is based on the NanoVG demo application
|
|
by Mikko Mononen.
|
|
|
|
All rights reserved. Use of this source code is governed by a
|
|
BSD-style license that can be found in the LICENSE.txt file.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <nanogui/popupbutton.h>
|
|
|
|
NAMESPACE_BEGIN(nanogui)
|
|
|
|
class NANOGUI_EXPORT ComboBox : public PopupButton {
|
|
public:
|
|
/// Create an empty combo box
|
|
ComboBox(Widget *parent);
|
|
|
|
/// Create a new combo box with the given items
|
|
ComboBox(Widget *parent, const std::vector<std::string> &items,
|
|
const std::function<void(int)>& callback);
|
|
|
|
/**
|
|
* \brief Create a new combo box with the given items, providing both short and
|
|
* long descriptive labels for each item
|
|
*/
|
|
ComboBox(Widget *parent, const std::vector<std::string> &items,
|
|
const std::vector<std::string> &itemsShort);
|
|
|
|
std::function<void(int)> callback() const { return mCallback; }
|
|
void setCallback(const std::function<void(int)> &callback) { mCallback = callback; }
|
|
|
|
int selectedIndex() const { return mSelectedIndex; }
|
|
void setSelectedIndex(int idx);
|
|
|
|
void setItems(const std::vector<std::string> &items, const std::vector<std::string> &itemsShort);
|
|
void setItems(const std::vector<std::string> &items) { setItems(items, items); }
|
|
const std::vector<std::string> &items() const { return mItems; }
|
|
const std::vector<std::string> &itemsShort() const { return mItemsShort; }
|
|
|
|
virtual void save(Serializer &s) const;
|
|
virtual bool load(Serializer &s);
|
|
protected:
|
|
std::vector<std::string> mItems, mItemsShort;
|
|
std::function<void(int)> mCallback;
|
|
int mSelectedIndex;
|
|
};
|
|
|
|
NAMESPACE_END(nanogui)
|