HTMLUI is a modern, lightweight C++ UI library that lets you build powerful native GUI applications using HTML, CSS, and JavaScript. It leverages GTK and WebKit2 to render HTML content and seamlessly integrate JavaScript callbacks into native C++ logic.
Created by ghgltggamer — Licensed under the MIT License
- Render HTML and CSS in native C++ windows
- Load HTML from strings, files, or URLs
- Call native C++ functions from JavaScript
- Execute JavaScript from C++
- Fine-tune WebKit settings for performance or security
- Auto flush queued JS when DOM is ready
- MIT licensed and fully open-source
- GTK 3
- WebKit2GTK
- C++17 or newer
Install dependencies on Arch Linux:
sudo pacman -S gtk3 webkit2gtkOr on Ubuntu/Debian:
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-devYou can build your application with any build system. Example using g++:
g++ main.cpp -o app `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`#include "htmlui.h"
int main() {
HTMLUI app("My HTMLUI App", 800, 600);
app.loadFile("index.html");
app.registerFunction("sayHello", [](const std::string& name) {
std::cout << "Hello, " << name << "!" << std::endl;
});
app.run();
}Then in your index.html:
<button onclick="sayHello('World')">Click Me</button>Creates a new window with the given title and dimensions.
Loads raw HTML content into the window.
Loads a local .html file using a full or relative path.
Loads a remote or local URL (e.g., http://example.com or file:///path/to/file.html).
Starts the GTK main loop.
void registerFunction(const std::string& functionName, std::function<void(const std::string&)> callback)
Exposes a C++ function to JavaScript with a given name. JavaScript can then call window.functionName(arg).
Executes a JavaScript string. If DOM isn't ready yet, it will be queued and run after load.
Changes WebKit settings dynamically.
Supported setting strings:
"javascript""developer_extras""webgl""file_access""universal_access""resizable_text_areas""smooth_scrolling"
You can invoke C++ functions from JS like so:
window.nativeBridge.invoke ("sayHello", "yourargs");Behind the scenes, HTMLUI injects:
window.nativeBridge = {
invoke: function(funcName, arg) {
window.webkit.messageHandlers.nativeCallback.postMessage(funcName + ':' + arg);
}
};When you register a function in C++, it's automatically exposed to JS.
This project is licensed under the MIT License.