• Stars
    star
    4,526
  • Rank 8,948 (Top 0.2 %)
  • Language
    C++
  • License
    Other
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimalistic GUI library for OpenGL

NanoGUI

Docs Travis Build Status Appveyor Build Status

NanoGUI is a minimalistic cross-platform widget library for OpenGL 3.x or higher. It supports automatic layout generation, stateful C++11 lambdas callbacks, a variety of useful widget types and Retina-capable rendering on Apple devices thanks to NanoVG by Mikko Mononen. Python bindings of all functionality are provided using pybind11.

Note: this repository is currently in maintenance-only mode. A new and significantly modernized/refactored version of NanoGUI with features such as Metal/GLES/WebAssembly support is available here.

Contents

Example screenshot

Screenshot of Example 1.

Description

NanoGUI builds on GLFW for cross-platform OpenGL context creation and event handling, GLAD to use OpenGL 3.x or higher Windows, Eigen for basic vector types, and NanoVG to draw 2D primitives.

Note that the dependency library NanoVG already includes some basic example code to draw good-looking static widgets; what NanoGUI does is to flesh it out into a complete GUI toolkit with event handling, layout generation, etc.

NanoGUI currently works on Mac OS X (Clang) Linux (GCC or Clang) and Windows (Visual Studio β‰₯ 2015); it requires a recent C++11 capable compiler. All dependencies are jointly built using a CMake-based build system.

Creating widgets

NanoGUI makes it easy to instantiate widgets, set layout constraints, and register event callbacks using high-level C++11 code. For instance, the following two lines from the included example application add a new button to an existing window window and register an event callback.

Button *b = new Button(window, "Plain button");
b->setCallback([] { cout << "pushed!" << endl; });

The following lines from the example application create the coupled slider and text box on the bottom of the second window (see the screenshot).

/* Create an empty panel with a horizontal layout */
Widget *panel = new Widget(window);
panel->setLayout(new BoxLayout(BoxLayout::Horizontal, BoxLayout::Middle, 0, 20));

/* Add a slider and set defaults */
Slider *slider = new Slider(panel);
slider->setValue(0.5f);
slider->setFixedWidth(80);

/* Add a textbox and set defaults */
TextBox *textBox = new TextBox(panel);
textBox->setFixedSize(Vector2i(60, 25));
textBox->setValue("50");
textBox->setUnits("%");

/* Propagate slider changes to the text box */
slider->setCallback([textBox](float value) {
    textBox->setValue(std::to_string((int) (value * 100)));
});

The Python version of this same piece of code looks like this:

# Create an empty panel with a horizontal layout
panel = Widget(window)
panel.setLayout(BoxLayout(BoxLayout.Horizontal, BoxLayout.Middle, 0, 20))

# Add a slider and set defaults
slider = Slider(panel)
slider.setValue(0.5f)
slider.setFixedWidth(80)

# Add a textbox and set defaults
textBox = TextBox(panel)
textBox.setFixedSize(Vector2i(60, 25))
textBox.setValue("50")
textBox.setUnits("%")

# Propagate slider changes to the text box
def cb(value):
    textBox.setValue("%i" % int(value * 100))
slider.setCallback(cb)

"Simple mode"

Christian SchΓΌller contributed a convenience class that makes it possible to create AntTweakBar-style variable manipulators using just a few lines of code. For instance, the source code below was used to create the following example application.

Screenshot

/// dvar, bar, strvar, etc. are double/bool/string/.. variables

FormHelper *gui = new FormHelper(screen);
ref<Window> window = gui->addWindow(Eigen::Vector2i(10, 10), "Form helper example");
gui->addGroup("Basic types");
gui->addVariable("bool", bvar);
gui->addVariable("string", strvar);

gui->addGroup("Validating fields");
gui->addVariable("int", ivar);
gui->addVariable("float", fvar);
gui->addVariable("double", dvar);

gui->addGroup("Complex types");
gui->addVariable("Enumeration", enumval, enabled)
   ->setItems({"Item 1", "Item 2", "Item 3"});
gui->addVariable("Color", colval);

gui->addGroup("Other widgets");
gui->addButton("A button", [](){ std::cout << "Button pressed." << std::endl; });

screen->setVisible(true);
screen->performLayout();
window->center();

Compiling

Clone the repository and all dependencies (with git clone --recursive), run CMake to generate Makefiles or CMake/Visual Studio project files, and the rest should just work automatically.

On Debian/Ubuntu, make sure that you have installed the following packages

$ apt-get install cmake xorg-dev libglu1-mesa-dev

To also get the Python bindings, you'll need to run

$ apt-get install python-dev

On RedHat/Fedora, make sure that you have installed the following packages

$ sudo dnf install cmake mesa-libGLU-devel libXi-devel libXcursor-devel libXinerama-devel libXrandr-devel xorg-x11-server-devel

To also get the Python bindings, you'll need to run

$ sudo dnf install python3-devel

License

NanoGUI is provided under a BSD-style license that can be found in the LICENSE file. By using, distributing, or contributing to this project, you agree to the terms and conditions of this license.

NanoGUI uses Daniel Bruce's Entypo+ font for the icons used on various widgets. This work is licensed under a CC BY-SA 4.0 license. Commercial entities using NanoGUI should consult the proper legal counsel for how to best adhere to the attribution clause of the license.

More Repositories

1

instant-meshes

Interactive field-aligned mesh generator
C++
4,785
star
2

nanobind

nanobind: tiny and efficient C++/Python bindings
C++
2,009
star
3

nori

Nori: an educational ray tracer
C++
796
star
4

tbb

Intel TBB with CMake build system
C++
349
star
5

filesystem

A tiny self-contained path manipulation library for C++
C++
234
star
6

layerlab

The layer laboratory
C++
88
star
7

nanobind_example

A nanobind example project
CMake
77
star
8

hdrmerge

Scientific RAW to HDR merging tool
C++
75
star
9

pcg32

Tiny self-contained C++ version of the PCG32 pseudorandom number generator
C++
65
star
10

dset

Lock-free parallel disjoint set data structure (aka UNION-FIND) with path compression and union by rank
C++
51
star
11

libftdi

FTDI USB driver (with improved CMake buld system)
C
22
star
12

term-tools

term-tools
Shell
13
star
13

nori-old

C++
12
star
14

openexr

OpenEXR is a high dynamic-range (HDR) image file format developed by Industrial Light & Magic for use in computer imaging applications
C++
11
star
15

pss

Parallel Stable Sort
C++
10
star
16

hypothesis

A collection of quantile and quadrature routines for Z, Chi^2, and Student's T hypothesis tests
C++
9
star
17

ek_python_test

Enoki + pybind11 example project
CMake
8
star
18

psum

CS3218 Lecture 5: Processor Architecture & Efficiency β€” Benchmark problem
Jupyter Notebook
6
star
19

nori-very-old

Archive of last year's Nori base code & assignment web page
C++
4
star
20

typing_repro

CMake
4
star
21

wjakob.nvim

Personal neovim tweaks
Scheme
2
star
22

wjakob.vim

Wenzel's VIM snippets
Vim Script
1
star
23

inheritance_issue_3

C
1
star
24

pytest_issue

C
1
star
25

pypy_issues

C
1
star