/nanogui

Minimalistic C++/Python GUI library for OpenGL, GLES2/3, Metal, and WebAssembly/WebGL

Primary LanguageC++OtherNOASSERTION

NanoGUI

Docs Travis Build Status Appveyor Build Status

NanoGUI is a minimalistic cross-platform widget library for OpenGL 3+, GLES 2/3, and Metal. It supports automatic layout generation, stateful C++ 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 contains an Enoki-compatible port of the original NanoGUI.

This repository incorporates a number of additional changes that go beyond the choice of vector library:

  1. A different set of naming conventions is used for function and variable names that feels more natural in a mixed C++ & Python environment. (specifically, underscore_case for methods and variables rather than camelCase).
  2. GUI Rendering now provides backends for OpenGL 3+, GLES 2/3, and Metal. GLES 2 support allows NanoGUI to run on ARM devices including the Raspberry Pi and in browsers via WebGL. The Metal backend supports modern Macs, iPhones, etc.

    NanoGUI includes generic wrappers around shaders and textures that work for all of these frameworks.

  3. The event loop is much more conservative by default and only issues redraw calls when explicitly requested by an event callback.
  4. Python integration: the library comes with a pip-compatible setup.py installation script.
  5. WebAssembly code generation works out of the box (requires Emscripten), enabling powerful UI development for the web. See Tekari for an example of such an application.
  6. Significantly revamped tab widget (supports right-click context menus, draggable, and closeable tabs) and image view widget.
  7. The Entypo icon font has been replaced by FontAwesome (v5.10.1).

Contents

Example screenshot

Screenshot of Example 1.

Description

NanoGUI builds on GLFW for cross-platform context creation and event handling, GLAD to access OpenGL functionality on Windows, Enoki for basic vector types, and NanoVG/MetalNanoVG 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 ≥ 2017); it requires a recent C++17 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++17 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.

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

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

"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

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

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

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

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

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.

Note that NanoGUI ships with several fonts that use different (though similarly unencumbered) licenses, in particular Roboto, Inconsolata, and the free version of the Font Awesome icon font (v5.10.1). The latter two are distributed under the SIL Open Font License Version 1.1, while Roboto is distributed under the Apache 2.0 license.