Skip to main content

Docs GitHub Actions 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 nanobind. Binary wheels of NanoGUI are available on PyPI.

Note: This repository contains an improved port of the original NanoGUI. The most visible change to developers is that it no longer relies on Eigen or Enoki and ships with its own (absolutely minimal) vector library. Additionally, the repository here incorporates the following changes:

  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. Cross-platform (macOS, Wayland, Windows) support for HDR displays and extended color spaces. See example_hdr

  4. The event loop is much more conservative by default and only issues redraw calls when explicitly requested by an event callback.

  5. Python integration: the library comes with a pip-compatible setup.py installation script.

  6. 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.

  7. Significantly revamped tab widget (supports right-click context menus, draggable, and closeable tabs) and image view widget.

  8. The Entypo icon font has been replaced by FontAwesome (v5.10.1).

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, 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), FreeBSD (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.

Button *b = new Button(window, "Plain button");
b->set_callback([] { 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->set_layout(new BoxLayout(BoxLayout::Horizontal, BoxLayout::Middle, 0, 20));

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

/* Add a textbox and set defaults */
TextBox *tb = new TextBox(panel);
tb->set_fixed_size(Vector2i(60, 25));
tb->set_value("50");
tb->set_units("%");

/* Propagate slider changes to the text box */
slider->set_callback([tb](float value) {
    tb->set_value(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.set_layout(BoxLayout(BoxLayout.Horizontal, BoxLayout.Middle, 0, 20))

# Add a slider and set defaults
slider = Slider(panel)
slider.set_value(0.5)
slider.set_fixed_width(80)

# Add a textbox and set defaults
tb = TextBox(panel)
tb.set_fixed_size(Vector2i(60, 25))
tb.set_value("50")
tb.set_units("%")

# Propagate slider changes to the text box
def cb(value):
    tb.set_value("%i" % int(value * 100))
slider.set_callback(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, bvar, strvar, etc. are double/bool/string/.. variables

FormHelper *gui = new FormHelper(screen);
ref<Window> window = gui->add_window(Vector2i(10, 10), "Form helper example");
gui->add_group("Basic types");
gui->add_variable("bool", bvar);
gui->add_variable("string", strvar);

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

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

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

screen->set_visible(true);
screen->perform_layout();
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.

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanogui-0.4.0.tar.gz (6.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nanogui-0.4.0-cp310-abi3-win_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows ARM64

nanogui-0.4.0-cp310-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

nanogui-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

nanogui-0.4.0-cp310-abi3-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

nanogui-0.4.0-cp310-abi3-macosx_11_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ x86-64

nanogui-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file nanogui-0.4.0.tar.gz.

File metadata

  • Download URL: nanogui-0.4.0.tar.gz
  • Upload date:
  • Size: 6.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nanogui-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7c06d81f685e6232ccc88cbe10d1b54085e93c03bcd9cadf8029a174e904d1c9
MD5 744e96db15f01893a8be846a25c42584
BLAKE2b-256 58e765948e0e809ade4e5396c5cfba585ca32a510e7ac5f3632eacdcfed3e5b3

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: nanogui-0.4.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 07ac70da889e13d68e5229cff108de3d7d2b775f8d1b8c5a39a99c1bcded10f6
MD5 2221a2b5d92caf8d249e55a373287df0
BLAKE2b-256 8e87eecd9a509ab951901d656ec143e2d02f9a1677f0032e6c1115c42fd9b04a

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: nanogui-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4acf78678a4a08232583afded980a60d946f40d1280bd99e426467a854f39f49
MD5 78e82ec8324f9f1fa6a8ae1b2a9ab7af
BLAKE2b-256 75e88acfd784f33c13994b9d4656ed80a6a55490bb1a9a088af78a15d6f1d47b

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e63d04733a8abb22bcde2bac5f6e9c6d4e41c398bfb1500bac5a5cbe86383e5
MD5 e73a6c1c6264e5eb0746a502765e6314
BLAKE2b-256 446d1fd639e746335a9ece46d28de10be27c19a1dc199054bbce72a8a3e49da8

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 505db7f18f8559806a618002975c8e1fffbbf3b4928c15b84ce00f8eb9ac10f0
MD5 6775966fd1581022b8631cd19c545869
BLAKE2b-256 7b41870a628bf4bc7e1ce57cf107cc029220657d27a61f06a73d38b822aa7db4

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 9c9656e8cd96b802b98af87e9683397b985977324e9125004fb4362cfc43becc
MD5 d39e0a3413e8640f9a2928d02ca07868
BLAKE2b-256 e51cc8809e23bda9572b7b205547152a3b19dd737d9c84d476222a441ba6f77e

See more details on using hashes here.

File details

Details for the file nanogui-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nanogui-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e165f91bf2ff6843f6cd0e8a23c4f2f70fb30286e32ee2439e36e2f3deb06457
MD5 c30ef5900ae638cb2e45e8ee8129d0c5
BLAKE2b-256 0717e8eed75e01331f1448946291c90348f43b11814d1adb67b3a8938d546b83

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.0

6 files

This release

0.4.0 This release

7 files

0.3.0

16 files

0.2.0

15 files

0.1.4

13 files

0.1.3

13 files

0.1.2

12 files

0.1.1

9 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page