Program Listing for File popup.h

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

/*
    nanogui/popup.h -- Simple popup widget which is attached to another given
    window (can be nested)

    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 Popup : public Window {
public:
    enum Side { Left = 0, Right };

    Popup(Widget *parent, Window *parentWindow);

    void setAnchorPos(const Vector2i &anchorPos) { mAnchorPos = anchorPos; }
    const Vector2i &anchorPos() const { return mAnchorPos; }

    void setAnchorHeight(int anchorHeight) { mAnchorHeight = anchorHeight; }
    int anchorHeight() const { return mAnchorHeight; }

    void setSide(Side popupSide) { mSide = popupSide; }
    Side side() const { return mSide; }

    Window *parentWindow() { return mParentWindow; }
    const Window *parentWindow() const { return mParentWindow; }

    virtual void performLayout(NVGcontext *ctx) override;

    virtual void draw(NVGcontext* ctx) override;

    virtual void save(Serializer &s) const override;
    virtual bool load(Serializer &s) override;
protected:
    virtual void refreshRelativePlacement() override;

protected:
    Window *mParentWindow;
    Vector2i mAnchorPos;
    int mAnchorHeight;
    Side mSide;
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

NAMESPACE_END(nanogui)