Loading repository data…
Loading repository data…
darkyboys / repository
HTMLUI2 is a lightweight C++ library for creating graphical user interfaces (GUIs) using HTML, CSS, and JavaScript. It leverages GTK and WebKit to provide a seamless way to build native-like applications with web technologies. HTMLUI is designed for developers who prefer to use web-based UI components in their C++ applications.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
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
Install dependencies on Arch Linux:
sudo pacman -S gtk3 webkit2gtk
Or on Ubuntu/Debian:
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev
You 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>
HTMLUI(const std::string& title, int width, int height)Creates a new window with the given title and dimensions.
void loadHTML(const std::string& html)Loads raw HTML content into the window.
void loadFile(const std::string& filepath)Loads a local .html file using a full or relative path.
void loadURL(const std::string& url)Loads a remote or local URL (e.g., http://example.com or file:///path/to/file.html).
void run()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).
void executeJS(const std::string& script)Executes a JavaScript string. If DOM isn't ready yet, it will be queued and run after load.
void setWebKitSetting(const std::string& setting, bool value)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.