Skip to main content

A minimalistic GUI library for OpenGL, GLES 2, and Metal

Project description

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

nanogui-0.3.0-cp312-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

nanogui-0.3.0-cp312-abi3-manylinux_2_28_x86_64.whl (3.6 MB view details)

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

nanogui-0.3.0-cp312-abi3-macosx_11_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12+macOS 11.0+ x86-64

nanogui-0.3.0-cp312-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

nanogui-0.3.0-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

nanogui-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

nanogui-0.3.0-cp311-cp311-macosx_11_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ x86-64

nanogui-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

nanogui-0.3.0-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

nanogui-0.3.0-cp310-cp310-macosx_11_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

nanogui-0.3.0-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9Windows x86-64

nanogui-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

nanogui-0.3.0-cp39-cp39-macosx_11_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

nanogui-0.3.0-cp39-cp39-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file nanogui-0.3.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: nanogui-0.3.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanogui-0.3.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 659843118d3d2e6ce74168e8caebec7b3e2af18332675633776b13fb1709f33f
MD5 fc687cab76e3cf0b53dab064dc041bd0
BLAKE2b-256 5f398c1955a97c1e6e01230cb2526acbd11b539d968a27b0f7d28ce46e1edcd5

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 577687177519cc2b8ed6545d38af35a0fc98894c275f7dd232dc01f6531eebff
MD5 a1e1282e4458b8ad50f3dd510ed0625b
BLAKE2b-256 21fc3e0f4b5dcf0387becfa80dca1aaea763d06d0b02ff57051be0cc7779bfeb

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp312-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp312-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 efcdf0b568a0a0310790f061039ac6aa675c3ce816a16e603c2833242d3d801d
MD5 e35e5eaea71f422695cd5cc2ecf5f8b7
BLAKE2b-256 52d82be90288e52df63c84c0508e9ec08edbe7e1722a2e4fbd0fcd60be88ee5e

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cae976a0da9882ff254149ee6e4e3a5d2c0b0dee8fa610b5cc6636f396f6e827
MD5 186a8612463cd52c08a10a3ec5d2dd8f
BLAKE2b-256 ca4df3755ab626fe7e05bd031cb3833444416d40e7b290143ec0a96237fa7814

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: nanogui-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanogui-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 795c2f34e3e12cc483ae22315453889d0ae10444ddb0db63da622bfb967347e1
MD5 690adc7747d8310785942c56b480e020
BLAKE2b-256 e5d688e057b01b93258065adbb43846417d7f7e95c4dc624d28738e5434e45e5

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 05ea243f5784a992053d5b133dc210240333bfe51808011d09ae3c2390b99ca4
MD5 859f06240f2574135b240de5fdcc2615
BLAKE2b-256 a5f4c5fdff740b17931d494ec78205772736fb4dbe18b314839a209f27580145

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp311-cp311-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp311-cp311-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 2f16e7a8a51aeb98dd6b7bc68313758cce73678d1fafd7b5a1d61455c37c09d6
MD5 2fbbf212f2535ae076ebd59187ef1c53
BLAKE2b-256 4d1daafec33a40a2dacfe11a9713f36e5c2ef7da3fa5ed8784c54e0cc73360e8

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9c2b93be7421f668c3486c677105aa6aa857e1a84ce0eb2c4b9de60f4e8f4b1
MD5 86961e77272d07d91c9f58d3526030c5
BLAKE2b-256 5a70ca3444ed59e18677641daa5cf158dce138d7df88749bad35e3f96f361f0a

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nanogui-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanogui-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 15c48bf48ba049ce5351a0fb0ffb03ca6bc1f5d0de6ebefc504caa119a6376cc
MD5 66b723d61aaab8ec9dc6e93fb15478de
BLAKE2b-256 0faf57b94524f3cda6ffae86b440a9d5b0915ef308a7efc63fa18f0f3082a845

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47ac890bfc6f4069e58978699f5c5197c727a26b93e4584058dc0edb36c00e99
MD5 f0c08d4bce89b1354403d8f0327caae9
BLAKE2b-256 3793cf971134ca82738a41c039624bfb69ae9a7f8b453eb156ef949371ffc5ff

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 d77af81402f5b3ab2cb612e6e797626ee847c91e92d9a147454eefcda32da1f9
MD5 386f45227bee1775a74b22ecb6f115be
BLAKE2b-256 a0f23ab32b38117af16d81eb01ed6cdbdbaeaffe95b1dcd4af96deb05300553d

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 42a84cde4e4dfc029862780f1d0db46d6b1cd6aad41a7fda04b5f931f2822e87
MD5 1c13c7c87077ce337cec91ff83095b1d
BLAKE2b-256 62ffef107b71893e7c699ed0efcfc7f010f50638b77692c292070dc225c3dcd5

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: nanogui-0.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanogui-0.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 84077a4009f4403b04d47167dca04c2be7f90b8687433f4c0a5e859a2517e7ae
MD5 8f28279eaf36121a4e6cc5a4fea1cdd2
BLAKE2b-256 dcbbad1a4836a84b39b16c6395c42cc1b558000fdbf18c60a4091bfde61d83d6

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a9cb504aecbfb940d4515f173dcd904c24d28366d3961278f6ccb2388dbe3ca5
MD5 90ebc83c7e2429c1ba35bee4fe9451ff
BLAKE2b-256 a34adc2a5aaaacba3c3146cb6db95054351cc9e7b8b1b8731392410a909c6ea9

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 730297051157fbf41cdd00be6f509c176dcd19ed24148e1a2fb6ad62d177bd24
MD5 808559447e8407dc1b4dc5477c1b7678
BLAKE2b-256 12da241941ed86291fa8b6085e85002c65f7ecb352981552e383059fdd8bc874

See more details on using hashes here.

File details

Details for the file nanogui-0.3.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nanogui-0.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 573611ea86f5aedd097f96bd20f3fb6ae9af965dd15bf4e73551fd87ee263844
MD5 f9f68e7084e83d8e6f5d903e51c0781e
BLAKE2b-256 240ce6ec1d818aa0f63f8637fca4d858451ecb7eacce0d19699aaa6f1ab034f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page