Program Listing for File messagedialog.hΒΆ

/*
    nanogui/messagedialog.h -- Simple "OK" or "Yes/No"-style modal dialogs

    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/window.h>

NAMESPACE_BEGIN(nanogui)


class NANOGUI_EXPORT MessageDialog : public Window {
public:
    enum class Type {
        Information,
        Question,
        Warning
    };

    MessageDialog(Widget *parent, Type type, const std::string &title = "Untitled",
                  const std::string &message = "Message",
                  const std::string &buttonText = "OK",
                  const std::string &altButtonText = "Cancel", bool altButton = false);

    Label *iconLabel() { return mIconLabel; }
    const Label *iconLabel() const { return mIconLabel; }
    void setIcon(int icon);

    Label *messageLabel() { return mMessageLabel; }
    const Label *messageLabel() const { return mMessageLabel; }

    Button *primaryButton() { return mPrimaryButton; }
    const Button *primaryButton() const { return mPrimaryButton; }
    void setPrimaryIcon(int icon);

    Button *alternateButton() { return mAlternateButton; }
    const Button *alternateButton() const { return mAlternateButton; }
    void setAlternateIcon(int icon);

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

    virtual void setTheme(Theme *theme) override;

protected:
    Type mType;

    Label *mIconLabel;

    Label *mMessageLabel;

    Button *mPrimaryButton;

    Button *mAlternateButton;

    std::function<void(int)> mCallback;

public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

NAMESPACE_END(nanogui)