Nim GUI, TUI, Web interface Overview
Nim has several native GUI, TUI, and web wrapper options.
Here’s a breakdown:
🖥️ Native GUI Libraries
These are directly integrated with Nim (no external dependencies unless specified).
Nigui
Cross-platform (Windows, Linux, macOS) Lightweight (uses native OS widgets) Modern API (similar to Flutter/React) Supports: Buttons, labels, text fields, lists, tables Custom drawing (Canvas) Theming
Example:
import nigui proc main() = var window = newWindow("Hello Nim!") window.width = 400 window.height = 300 var button = newButton("Click me!") button.onClick = proc() = echo "Button clicked!" window.add(button) window.show() main()NimGL (OpenGL-based)
For OpenGL-based GUIs (games, custom rendering) Cross-platform Supports: 2D/3D rendering Widgets (via NimGLWidgets)
Example:
import nimgl/[opengl, glfw]
proc main() =
if glfwInit() != GLFW_TRUE:
quit("Failed to initialize GLFW")
let window = glfwCreateWindow(800, 600, "NimGL Example")
glfwMakeContextCurrent(window)
while glfwWindowShouldClose(window) == GLFW_FALSE:
glClear(GL_COLOR_BUFFER_BIT)
glfwSwapBuffers(window)
glfwPollEvents()
glfwTerminate()
main()IUP (Wrapper for IUP Toolkit)
Cross-platform (Windows, Linux, macOS) Uses IUP (a mature GUI toolkit) Supports: Buttons, menus, dialogs, OpenGL integration
Example:
import iup
proc main() =
let btn = IupButton("Click me!", nil)
let dlg = IupDialog(btn, "Nim + IUP")
discard IupShow(dlg, nil)
discard IupMainLoop()
main()SDL2 / raylib
For game-like GUIs (SDL2) or simple 2D rendering (raylib) Cross-platform
Example (raylib):
import raylib
proc main() =
InitWindow(800, 450, "Raylib + Nim")
while not WindowShouldClose():
BeginDrawing()
ClearBackground(RAYWHITE)
DrawText("Hello Nim!", 190, 200, 20, BLACK)
EndDrawing()
CloseWindow()
main()🖥️ TUI (Terminal UI) Libraries
For text-based interfaces (like ncurses in C).
Ncurses
Wrapper for ncurses (Linux/macOS) and pdcurses (Windows) Supports: Windows, panels, colors, mouse input
Example:
import ncurses
proc main() =
initscr()
cbreak()
noecho()
keypad(stdscr, TRUE)
printw("Press 'q' to quit")
refresh()
while true:
let ch = getch()
if ch == 'q'.int32:
break
printw("You pressed: ", chr(ch))
refresh()
endwin()
main()TerminalTools
Pure Nim (no external dependencies) Supports: Colors, progress bars, tables, input handling
Example:
import terminal
echo fgRed & "Red text" & reset
echo "Progress: ", progressBar(50)- Cligen
For CLI apps (argument parsing, help generation) Similar to Python’s argparse
Example:
import cligen
proc main(name: string) =
echo "Hello, ", name
dispatch(main)Run with:
./your_app --name "Nim"🌐 Web Wrappers (Like Electron)
If you want to build desktop apps with web tech (HTML/CSS/JS), Nim has a few options:
- Nim + WebView (like Electron)
Embeds a WebView (Chromium or WebKit) Cross-platform Example: nim
import webview
proc main() = let w = newWebView() w.title = “Nim + WebView” w.url = “https://nim-lang.org” w.run()
main()
- Nim + Tauri (Rust-based, but Nim can call Rust)
Lightweight alternative to Electron Nim can interface with Rust via nigui or FFI
- Nim + Flutter (via FFI)
Experimental (Nim can call Flutter’s C API) Not as mature as other options
📌 Summary Table
| Type Library | Best For | Dependencies |
|---|---|---|
| GUI Nigui Modern, native-looking apps None | ||
| GUI IUP Traditional desktop apps IUP (C library) | ||
| GUI NimGL OpenGL-based apps/games OpenGL | ||
| GUI SDL2 / raylib Game-like UIs SDL2 / raylib | ||
| TUI Ncurses Terminal-based apps ncurses (C) | ||
| TUI TerminalTools Pure Nim terminal apps None | ||
| Web Wrapper WebView Electron-like apps WebView (C) | ||
| CLI Cligen Command-line apps None |
🚀 Recommendation
* For beginners: Start with Nigui (easiest) or TerminalTools (for TUI).
* For games/rendering: Use NimGL or raylib.
* For web-like apps: Try WebView.
* For CLI tools: Cligen is great.