Program Listing for File colorpicker.h

Return to documentation for file (nanogui/colorpicker.h)

/*
    NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.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 ColorPicker : public PopupButton {
public:
    ColorPicker(Widget *parent, const Color& color = Color(1.0f, 0.0f, 0.0f, 1.0f));

    std::function<void(const Color &)> callback() const { return mCallback; }

    void setCallback(const std::function<void(const Color &)> &callback) {
        mCallback = callback;
        mCallback(backgroundColor());
    }

    std::function<void(const Color &)> finalCallback() const { return mFinalCallback; }

    void setFinalCallback(const std::function<void(const Color &)> &callback) { mFinalCallback = callback; }

    Color color() const;

    void setColor(const Color& color);

    const std::string &pickButtonCaption() { return mPickButton->caption(); }

    void setPickButtonCaption(const std::string &caption) { mPickButton->setCaption(caption); }

    const std::string &resetButtonCaption() { return mResetButton->caption(); }

    void setResetButtonCaption(const std::string &caption) { mResetButton->setCaption(caption); }

protected:
    std::function<void(const Color &)> mCallback;

    std::function<void(const Color &)> mFinalCallback;

    ColorWheel *mColorWheel;

    Button *mPickButton;

    Button *mResetButton;

public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

NAMESPACE_END(nanogui)