1 /*
2     nanogui/graph.h -- Simple graph widget for showing a function plot
3 
4     NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
5     The widget drawing code is based on the NanoVG demo application
6     by Mikko Mononen.
7 
8     All rights reserved. Use of this source code is governed by a
9     BSD-style license that can be found in the LICENSE.txt file.
10 */
11 /** \file */
12 
13 #pragma once
14 
15 #include <nanogui/widget.h>
16 
NAMESPACE_BEGIN(nanogui)17 NAMESPACE_BEGIN(nanogui)
18 
19 /**
20  * \class Graph graph.h nanogui/graph.h
21  *
22  * \brief Simple graph widget for showing a function plot.
23  */
24 class NANOGUI_EXPORT Graph : public Widget {
25 public:
26     Graph(Widget *parent, const std::string &caption = "Untitled");
27 
28     const std::string &caption() const { return mCaption; }
29     void setCaption(const std::string &caption) { mCaption = caption; }
30 
31     const std::string &header() const { return mHeader; }
32     void setHeader(const std::string &header) { mHeader = header; }
33 
34     const std::string &footer() const { return mFooter; }
35     void setFooter(const std::string &footer) { mFooter = footer; }
36 
37     const Color &backgroundColor() const { return mBackgroundColor; }
38     void setBackgroundColor(const Color &backgroundColor) { mBackgroundColor = backgroundColor; }
39 
40     const Color &foregroundColor() const { return mForegroundColor; }
41     void setForegroundColor(const Color &foregroundColor) { mForegroundColor = foregroundColor; }
42 
43     const Color &textColor() const { return mTextColor; }
44     void setTextColor(const Color &textColor) { mTextColor = textColor; }
45 
46     const VectorXf &values() const { return mValues; }
47     VectorXf &values() { return mValues; }
48     void setValues(const VectorXf &values) { mValues = values; }
49 
50     virtual Vector2i preferredSize(NVGcontext *ctx) const override;
51     virtual void draw(NVGcontext *ctx) override;
52 
53     virtual void save(Serializer &s) const override;
54     virtual bool load(Serializer &s) override;
55 protected:
56     std::string mCaption, mHeader, mFooter;
57     Color mBackgroundColor, mForegroundColor, mTextColor;
58     VectorXf mValues;
59 };
60 
61 NAMESPACE_END(nanogui)
62