Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Graph::mFill flag to render flag with or without fill. #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/nanogui/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class NANOGUI_EXPORT Graph : public Widget {
const Color &textColor() const { return mTextColor; }
void setTextColor(const Color &textColor) { mTextColor = textColor; }

bool fill() const { return mFill; }
void setFill(bool fill) { mFill = fill; }

const VectorXf &values() const { return mValues; }
VectorXf &values() { return mValues; }
void setValues(const VectorXf &values) { mValues = values; }
Expand All @@ -56,6 +59,7 @@ class NANOGUI_EXPORT Graph : public Widget {
std::string mCaption, mHeader, mFooter;
Color mBackgroundColor, mForegroundColor, mTextColor;
VectorXf mValues;
bool mFill;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
Expand Down
4 changes: 3 additions & 1 deletion python/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void register_misc(py::module &m) {
.def("textColor", &Graph::textColor, D(Graph, textColor))
.def("setTextColor", &Graph::setTextColor, D(Graph, setTextColor))
.def("values", (VectorXf &(Graph::*)(void)) &Graph::values, D(Graph, values))
.def("setValues", &Graph::setValues, D(Graph, setValues));
.def("setValues", &Graph::setValues, D(Graph, setValues))
.def("fill", &Graph::fill, D(Graph, fill))
.def("setFill", &Graph::setFill, D(Graph, setFill));

py::class_<ImageView, Widget, ref<ImageView>, PyImageView>(m, "ImageView", D(ImageView))
.def(py::init<Widget *, GLuint>(), D(ImageView, ImageView))
Expand Down
4 changes: 4 additions & 0 deletions python/py_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,10 @@ static const char *__doc_nanogui_Graph_values = R"doc()doc";

static const char *__doc_nanogui_Graph_values_2 = R"doc()doc";

static const char *__doc_nanogui_Graph_setFill = R"doc()doc";

static const char *__doc_nanogui_Graph_fill = R"doc()doc";

static const char *__doc_nanogui_GridLayout =
R"doc(Grid layout.

Expand Down
15 changes: 10 additions & 5 deletions src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
NAMESPACE_BEGIN(nanogui)

Graph::Graph(Widget *parent, const std::string &caption)
: Widget(parent), mCaption(caption) {
: Widget(parent), mCaption(caption), mFill(true) {
mBackgroundColor = Color(20, 128);
mForegroundColor = Color(255, 192, 0, 128);
mTextColor = Color(240, 192);
Expand Down Expand Up @@ -48,10 +48,15 @@ void Graph::draw(NVGcontext *ctx) {
}

nvgLineTo(ctx, mPos.x() + mSize.x(), mPos.y() + mSize.y());
nvgStrokeColor(ctx, Color(100, 255));
nvgStroke(ctx);
nvgFillColor(ctx, mForegroundColor);
nvgFill(ctx);
if (mFill) {
nvgStrokeColor(ctx, Color(100, 255));
nvgStroke(ctx);
nvgFillColor(ctx, mForegroundColor);
nvgFill(ctx);
} else {
nvgStrokeColor(ctx, mForegroundColor);
nvgStroke(ctx);
}

nvgFontFace(ctx, "sans");

Expand Down