C++ Wrapper Update

* Now the C++ wrapper has its own class instead of direct C calls.
This commit is contained in:
Albert Shown 2023-05-05 17:41:20 -04:00
parent ca7b4f50ed
commit e116261130
41 changed files with 771 additions and 628 deletions

View File

@ -129,7 +129,7 @@ namespace webui {
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, EventNumber)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -130,7 +130,7 @@ enum webui_events {
// -- Structs -------------------------
typedef struct webui_event_t {
size_t window; // Pointer to the window object
size_t window; // The window object number
unsigned int event_type; // Event type
char* element; // HTML element ID
char* data; // JavaScript data
@ -194,5 +194,7 @@ WEBUI_EXPORT void webui_interface_set_response(size_t window, unsigned int event
WEBUI_EXPORT bool webui_interface_is_app_running(void);
// Get window unique ID
WEBUI_EXPORT unsigned int webui_interface_get_window_id(size_t window);
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
WEBUI_EXPORT unsigned int webui_interface_get_bind_id(size_t window, const char* element);
#endif /* _WEBUI_H */

View File

@ -129,7 +129,7 @@ namespace webui {
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, EventNumber)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -53,9 +53,6 @@ cp -f "build/Linux/GCC/webui-2-x64.so" "examples/TypeScript/Deno/webui-2-x64.so"
# Python
cp -f "build/Linux/GCC/webui-2-x64.so" "examples/Python/PyPI/Package/src/webui/webui-2-x64.so"
# C++ (Minimal)
cp -f "include/webui.hpp" "examples/C++/minimal/webui.hpp"
echo "";
if [ "$ARG1" = "" ]; then

View File

@ -44,9 +44,6 @@ cp -f "build/macOS/Clang/webui-2-x64.dyn" "examples/TypeScript/Deno/webui-2-x64.
# Python
cp -f "build/macOS/Clang/webui-2-x64.dyn" "examples/Python/PyPI/Package/src/webui/webui-2-x64.dyn"
# C++ (Minimal)
cp -f "include/webui.hpp" "examples/C++/minimal/webui.hpp"
echo "";
if [ "$ARG1" = "" ]; then

View File

@ -61,9 +61,6 @@ copy /Y "build\Windows\MSVC\webui-2-x64.dll" "examples\TypeScript\Deno\webui-2-x
REM Python
copy /Y "build\Windows\MSVC\webui-2-x64.dll" "examples\Python\PyPI\Package\src\webui\webui-2-x64.dll"
REM C++ (Minimal)
copy /Y "include\webui.hpp" "examples\C++\minimal\webui.hpp"
REM C++ (Visual Studio 2022)
copy /Y "include\webui.h" "examples\C++\VS2022\serve_a_folder\my_webui_app\webui.h"
copy /Y "include\webui.hpp" "examples\C++\VS2022\serve_a_folder\my_webui_app\webui.hpp"

View File

@ -5,7 +5,7 @@
#include <iostream>
// Making this object global so show_second_window() can access it.
size_t my_second_window;
webui::window my_second_window;
// Example of a simple Class
class MyClass {
@ -13,38 +13,38 @@ class MyClass {
// This method gets called every time the
// user clicks on "OpenNewWindow"
void show_second_window(webui_event_t* e) {
void show_second_window(webui::event* e) {
// Show a new window, and navigate to `/second.html`
// if the window is already opened, then switch in the same window
webui::show(my_second_window, "second.html");
my_second_window.show("second.html");
}
// This method gets called every time the
// user clicks on "SwitchToSecondPage"
void switch_to_second_page(webui_event_t* e) {
void switch_to_second_page(webui::event* e) {
// Switch to `/second.html` in the same opened window.
webui::show(e->window, "second.html");
e->window.show("second.html");
}
// Example of a simple function (Not a method)
// This function receives all events because
// it's get bind with an empty HTML ID.
void events(webui_event_t* e) {
void events(webui::event* e) {
if (e->event_type == WEBUI_EVENT_CONNECTED)
if (e->event_type == webui::CONNECTED)
std::cout << "Window Connected." << std::endl;
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
else if (e->event_type == webui::DISCONNECTED)
std::cout << "Window Disconnected." << std::endl;
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
else if (e->event_type == webui::MOUSE_CLICK)
std::cout << "Click on element: " << e->element << std::endl;
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
else if (e->event_type == webui::NAVIGATION)
std::cout << "Starting navigation to: " << e->data << std::endl;
}
// Example of a simple function (Not a method)
void exit_app(webui_event_t* e) {
void exit_app(webui::event* e) {
// Close all opened windows
webui::exit();
@ -56,10 +56,10 @@ class MyClass {
// access `MyClass` directly. That's why we should
// create a simple C++ wrapper.
MyClass obj;
void show_second_window_wrp(webui_event_t* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui_event_t* e) { obj.switch_to_second_page(e); }
void events_wrp(webui_event_t* e) { obj.events(e); }
void exit_app_wrp(webui_event_t* e) { obj.exit_app(e); }
void show_second_window_wrp(webui::event* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui::event* e) { obj.switch_to_second_page(e); }
void events_wrp(webui::event* e) { obj.events(e); }
void exit_app_wrp(webui::event* e) { obj.exit_app(e); }
int main() {
@ -67,20 +67,19 @@ int main() {
std::cout << "Starting..." << std::endl;
// Create a new window
size_t my_window = webui::new_window();
my_second_window = webui::new_window();
webui::window my_window;
// Bind HTML element IDs with a C functions
webui::bind(my_window, "SwitchToSecondPage", switch_to_second_page_wrp);
webui::bind(my_window, "OpenNewWindow", show_second_window_wrp);
webui::bind(my_window, "Exit", exit_app_wrp);
webui::bind(my_second_window, "Exit", exit_app_wrp);
my_window.bind("SwitchToSecondPage", switch_to_second_page_wrp);
my_window.bind("OpenNewWindow", show_second_window_wrp);
my_window.bind("Exit", exit_app_wrp);
my_second_window.bind("Exit", exit_app_wrp);
// Bind events
webui::bind(my_window, "", events_wrp);
// Bind all events
my_window.bind("", events_wrp);
// Show a new window
webui::show(my_window, "index.html"); // webui::show_browser(my_window, "index.html", Chrome);
my_window.show("index.html"); // webui::show_browser(my_window, "index.html", Chrome);
// Wait until all windows get closed
webui::wait();

View File

@ -130,7 +130,7 @@ enum webui_events {
// -- Structs -------------------------
typedef struct webui_event_t {
size_t window; // Pointer to the window object
size_t window; // The window object number
unsigned int event_type; // Event type
char* element; // HTML element ID
char* data; // JavaScript data
@ -194,5 +194,7 @@ WEBUI_EXPORT void webui_interface_set_response(size_t window, unsigned int event
WEBUI_EXPORT bool webui_interface_is_app_running(void);
// Get window unique ID
WEBUI_EXPORT unsigned int webui_interface_get_window_id(size_t window);
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
WEBUI_EXPORT unsigned int webui_interface_get_bind_id(size_t window, const char* element);
#endif /* _WEBUI_H */

View File

@ -16,138 +16,217 @@
// WebUI C Header
extern "C" {
#include "webui.h"
#include "webui.h"
}
namespace webui {
// Create a new webui window object.
size_t new_window(void) {
return webui_new_window();
}
const int DISCONNECTED = 0; // 0. Window disconnection event
const int CONNECTED = 1; // 1. Window connection event
const int MULTI_CONNECTION = 2; // 2. New window connection event
const int UNWANTED_CONNECTION = 3; // 3. New unwanted window connection event
const int MOUSE_CLICK = 4; // 4. Mouse click event
const int NAVIGATION = 5; // 5. Window navigation event
const int CALLBACKS = 6; // 6. Function call event
// Bind a specific html element click event with a function. Empty element means all events.
unsigned int bind(size_t window, std::string element, void (*func)(webui_event_t* e)) {
return webui_bind(window, element.c_str(), func);
}
class window;
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(size_t window, std::string content) {
return webui_show(window, content.c_str());
}
// Event struct
struct event {
webui::window& window; // The window object
unsigned int event_type; // Event type
std::string element; // HTML element ID
std::string data; // JavaScript data
unsigned int event_number; // Internal WebUI
// Same as show(). But with a specific web browser.
bool show_browser(size_t window, std::string content, unsigned int browser) {
return webui_show_browser(window, content.c_str(), browser);
}
// Window object constructor that
// initializes the reference, This
// is to avoid creating copies.
event(webui::window& window_obj) : window(window_obj) {}
};
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// List of callbacks: user_function(webui::event* e)
void (*callback_list[512])(webui::event*);
// Close a specific window.
void close(size_t window) {
webui_close(window);
}
// List of window objects: webui::window
webui::window* window_list[512];
// Set the window in Kiosk mode (Full screen)
void set_kiosk(size_t window, bool status) {
webui_set_kiosk(window, status);
}
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown(size_t window) {
return webui_is_shown(window);
}
// Event handler
// WebUI is written in C. So there is no way
// to make C call a C++ class member. That's
// why this function should be outside class
void event_handler(webui_event_t* c_e) {
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
unsigned int id = webui_interface_get_bind_id(c_e->window, c_e->element);
// Set the default embedded HTML favicon
void set_icon(size_t window, std::string icon, std::string icon_type) {
webui_set_icon(window, icon.c_str(), icon_type.c_str());
}
if(id < 1)
return;
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(size_t window, bool status) {
webui_set_multi_access(window, status);
}
// Create a new event struct
webui::event e(*window_list[id]);
// `e.window` is already initialized by `e` constructor
e.event_type = c_e->event_type;
e.element = (c_e->element != NULL ? std::string(c_e->element) : std::string(""));
e.data = (c_e->data != NULL ? std::string(c_e->data) : std::string(""));
e.event_number = c_e->event_number;
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(size_t window, std::string script) {
return webui_run(window, script.c_str());
}
// Call the user callback
if(callback_list[id] != NULL)
callback_list[id](&e);
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(size_t window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
}
class window {
private:
size_t webui_window = 0;
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(size_t window, unsigned int runtime) {
webui_set_runtime(window, runtime);
}
webui_event_t* convert_event_to_webui_event(webui::event* e) {
// Convert C++ `webui::event` to C `webui_event_t`
webui_event_t* c_e = new webui_event_t;
c_e->window = this->webui_window;
c_e->event_type = e->event_type;
c_e->element = (char*)e->element.c_str();
c_e->data = (char*)e->data.c_str();
c_e->event_number = e->event_number;
return c_e;
}
public:
// Constructor
window() {
this->webui_window = webui_new_window();
}
// Parse argument as integer.
long long int get_int(webui_event_t* e) {
return webui_get_int(e);
}
// Destructor
~window() {
// Nothing to do.
// No needs to call `webui_close()`
}
// Parse argument as string.
std::string get_string(webui_event_t* e) {
return std::string(webui_get_string(e));
}
// Bind a specific html element click event with a function. Empty element means all events.
void bind(std::string element, void (*func)(webui::event* e)) {
// Parse argument as boolean.
bool get_bool(webui_event_t* e) {
return webui_get_bool(e);
}
// Get unique ID
unsigned int id = webui_bind(this->webui_window, element.c_str(), webui::event_handler);
// Return the response to JavaScript as integer.
void return_int(webui_event_t* e, long long int n) {
webui_return_int(e, n);
}
// Save window object
window_list[id] = this;
// Return the response to JavaScript as string.
void return_string(webui_event_t* e, std::string s) {
webui_return_string(e, &s[0]);
}
// Save callback
callback_list[id] = func;
}
// Return the response to JavaScript as boolean.
void return_bool(webui_event_t* e, bool b) {
webui_return_bool(e, b);
}
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(std::string content) {
return webui_show(this->webui_window, content.c_str());
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}
// Same as show(). But with a specific web browser.
bool show_browser(std::string content, unsigned int browser) {
return webui_show_browser(this->webui_window, content.c_str(), browser);
}
// When using `interface_bind()` you need this function to easily set your callback response.
void interface_set_response(size_t window, webui_event_t* e, std::string response) {
webui_interface_set_response(window, e->event_number, response.c_str());
}
// Close a specific window.
void close() {
webui_close(this->webui_window);
}
// Check if the app still running or not. This replace wait().
bool interface_is_app_running(void) {
return webui_interface_is_app_running();
}
// Set the window in Kiosk mode (Full screen)
void set_kiosk(bool status) {
webui_set_kiosk(this->webui_window, status);
}
// Get window unique ID
unsigned int interface_get_window_id(size_t window) {
return webui_interface_get_window_id(window);
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown() {
return webui_is_shown(this->webui_window);
}
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Set the default embedded HTML favicon
void set_icon(std::string icon, std::string icon_type) {
webui_set_icon(this->webui_window, icon.c_str(), icon_type.c_str());
}
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(bool status) {
webui_set_multi_access(this->webui_window, status);
}
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(std::string script) {
return webui_run(this->webui_window, script.c_str());
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(this->webui_window, script.c_str(), timeout, buffer, buffer_length);
}
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(unsigned int runtime) {
webui_set_runtime(this->webui_window, runtime);
}
// Parse argument as integer.
long long int get_int(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
long long int ret = webui_get_int(c_e);
delete c_e;
return ret;
}
// Parse argument as string.
std::string get_string(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
std::string ret = std::string(webui_get_string(c_e));
delete c_e;
return ret;
}
// Parse argument as boolean.
bool get_bool(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
bool ret = webui_get_bool(c_e);
delete c_e;
return ret;
}
// Return the response to JavaScript as integer.
void return_int(webui::event* e, long long int n) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_int(c_e, n);
delete c_e;
}
// Return the response to JavaScript as string.
void return_string(webui::event* e, std::string s) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_string(c_e, &s[0]);
delete c_e;
}
// Return the response to JavaScript as boolean.
void return_bool(webui::event* e, bool b) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_bool(c_e, b);
delete c_e;
}
};
}
#endif /* _WEBUI_HPP */

View File

@ -5,7 +5,7 @@
#include <iostream>
// Making this object global so show_second_window() can access it.
size_t my_second_window;
webui::window my_second_window;
// Example of a simple Class
class MyClass {
@ -13,38 +13,38 @@ class MyClass {
// This method gets called every time the
// user clicks on "OpenNewWindow"
void show_second_window(webui_event_t* e) {
void show_second_window(webui::event* e) {
// Show a new window, and navigate to `/second.html`
// if the window is already opened, then switch in the same window
webui::show(my_second_window, "second.html");
my_second_window.show("second.html");
}
// This method gets called every time the
// user clicks on "SwitchToSecondPage"
void switch_to_second_page(webui_event_t* e) {
void switch_to_second_page(webui::event* e) {
// Switch to `/second.html` in the same opened window.
webui::show(e->window, "second.html");
e->window.show("second.html");
}
// Example of a simple function (Not a method)
// This function receives all events because
// it's get bind with an empty HTML ID.
void events(webui_event_t* e) {
void events(webui::event* e) {
if (e->event_type == WEBUI_EVENT_CONNECTED)
if (e->event_type == webui::CONNECTED)
std::cout << "Window Connected." << std::endl;
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
else if (e->event_type == webui::DISCONNECTED)
std::cout << "Window Disconnected." << std::endl;
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
else if (e->event_type == webui::MOUSE_CLICK)
std::cout << "Click on element: " << e->element << std::endl;
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
else if (e->event_type == webui::NAVIGATION)
std::cout << "Starting navigation to: " << e->data << std::endl;
}
// Example of a simple function (Not a method)
void exit_app(webui_event_t* e) {
void exit_app(webui::event* e) {
// Close all opened windows
webui::exit();
@ -56,10 +56,10 @@ class MyClass {
// access `MyClass` directly. That's why we should
// create a simple C++ wrapper.
MyClass obj;
void show_second_window_wrp(webui_event_t* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui_event_t* e) { obj.switch_to_second_page(e); }
void events_wrp(webui_event_t* e) { obj.events(e); }
void exit_app_wrp(webui_event_t* e) { obj.exit_app(e); }
void show_second_window_wrp(webui::event* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui::event* e) { obj.switch_to_second_page(e); }
void events_wrp(webui::event* e) { obj.events(e); }
void exit_app_wrp(webui::event* e) { obj.exit_app(e); }
int main() {
@ -67,20 +67,19 @@ int main() {
std::cout << "Starting..." << std::endl;
// Create a new window
size_t my_window = webui::new_window();
my_second_window = webui::new_window();
webui::window my_window;
// Bind HTML element IDs with a C functions
webui::bind(my_window, "SwitchToSecondPage", switch_to_second_page_wrp);
webui::bind(my_window, "OpenNewWindow", show_second_window_wrp);
webui::bind(my_window, "Exit", exit_app_wrp);
webui::bind(my_second_window, "Exit", exit_app_wrp);
my_window.bind("SwitchToSecondPage", switch_to_second_page_wrp);
my_window.bind("OpenNewWindow", show_second_window_wrp);
my_window.bind("Exit", exit_app_wrp);
my_second_window.bind("Exit", exit_app_wrp);
// Bind events
webui::bind(my_window, "", events_wrp);
// Bind all events
my_window.bind("", events_wrp);
// Show a new window
webui::show(my_window, "index.html"); // webui::show_browser(my_window, "index.html", Chrome);
my_window.show("index.html"); // webui::show_browser(my_window, "index.html", Chrome);
// Wait until all windows get closed
webui::wait();

View File

@ -130,7 +130,7 @@ enum webui_events {
// -- Structs -------------------------
typedef struct webui_event_t {
size_t window; // Pointer to the window object
size_t window; // The window object number
unsigned int event_type; // Event type
char* element; // HTML element ID
char* data; // JavaScript data
@ -194,5 +194,7 @@ WEBUI_EXPORT void webui_interface_set_response(size_t window, unsigned int event
WEBUI_EXPORT bool webui_interface_is_app_running(void);
// Get window unique ID
WEBUI_EXPORT unsigned int webui_interface_get_window_id(size_t window);
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
WEBUI_EXPORT unsigned int webui_interface_get_bind_id(size_t window, const char* element);
#endif /* _WEBUI_H */

View File

@ -16,138 +16,217 @@
// WebUI C Header
extern "C" {
#include "webui.h"
#include "webui.h"
}
namespace webui {
// Create a new webui window object.
size_t new_window(void) {
return webui_new_window();
}
const int DISCONNECTED = 0; // 0. Window disconnection event
const int CONNECTED = 1; // 1. Window connection event
const int MULTI_CONNECTION = 2; // 2. New window connection event
const int UNWANTED_CONNECTION = 3; // 3. New unwanted window connection event
const int MOUSE_CLICK = 4; // 4. Mouse click event
const int NAVIGATION = 5; // 5. Window navigation event
const int CALLBACKS = 6; // 6. Function call event
// Bind a specific html element click event with a function. Empty element means all events.
unsigned int bind(size_t window, std::string element, void (*func)(webui_event_t* e)) {
return webui_bind(window, element.c_str(), func);
}
class window;
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(size_t window, std::string content) {
return webui_show(window, content.c_str());
}
// Event struct
struct event {
webui::window& window; // The window object
unsigned int event_type; // Event type
std::string element; // HTML element ID
std::string data; // JavaScript data
unsigned int event_number; // Internal WebUI
// Same as show(). But with a specific web browser.
bool show_browser(size_t window, std::string content, unsigned int browser) {
return webui_show_browser(window, content.c_str(), browser);
}
// Window object constructor that
// initializes the reference, This
// is to avoid creating copies.
event(webui::window& window_obj) : window(window_obj) {}
};
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// List of callbacks: user_function(webui::event* e)
void (*callback_list[512])(webui::event*);
// Close a specific window.
void close(size_t window) {
webui_close(window);
}
// List of window objects: webui::window
webui::window* window_list[512];
// Set the window in Kiosk mode (Full screen)
void set_kiosk(size_t window, bool status) {
webui_set_kiosk(window, status);
}
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown(size_t window) {
return webui_is_shown(window);
}
// Event handler
// WebUI is written in C. So there is no way
// to make C call a C++ class member. That's
// why this function should be outside class
void event_handler(webui_event_t* c_e) {
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
unsigned int id = webui_interface_get_bind_id(c_e->window, c_e->element);
// Set the default embedded HTML favicon
void set_icon(size_t window, std::string icon, std::string icon_type) {
webui_set_icon(window, icon.c_str(), icon_type.c_str());
}
if(id < 1)
return;
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(size_t window, bool status) {
webui_set_multi_access(window, status);
}
// Create a new event struct
webui::event e(*window_list[id]);
// `e.window` is already initialized by `e` constructor
e.event_type = c_e->event_type;
e.element = (c_e->element != NULL ? std::string(c_e->element) : std::string(""));
e.data = (c_e->data != NULL ? std::string(c_e->data) : std::string(""));
e.event_number = c_e->event_number;
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(size_t window, std::string script) {
return webui_run(window, script.c_str());
}
// Call the user callback
if(callback_list[id] != NULL)
callback_list[id](&e);
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(size_t window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
}
class window {
private:
size_t webui_window = 0;
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(size_t window, unsigned int runtime) {
webui_set_runtime(window, runtime);
}
webui_event_t* convert_event_to_webui_event(webui::event* e) {
// Convert C++ `webui::event` to C `webui_event_t`
webui_event_t* c_e = new webui_event_t;
c_e->window = this->webui_window;
c_e->event_type = e->event_type;
c_e->element = (char*)e->element.c_str();
c_e->data = (char*)e->data.c_str();
c_e->event_number = e->event_number;
return c_e;
}
public:
// Constructor
window() {
this->webui_window = webui_new_window();
}
// Parse argument as integer.
long long int get_int(webui_event_t* e) {
return webui_get_int(e);
}
// Destructor
~window() {
// Nothing to do.
// No needs to call `webui_close()`
}
// Parse argument as string.
std::string get_string(webui_event_t* e) {
return std::string(webui_get_string(e));
}
// Bind a specific html element click event with a function. Empty element means all events.
void bind(std::string element, void (*func)(webui::event* e)) {
// Parse argument as boolean.
bool get_bool(webui_event_t* e) {
return webui_get_bool(e);
}
// Get unique ID
unsigned int id = webui_bind(this->webui_window, element.c_str(), webui::event_handler);
// Return the response to JavaScript as integer.
void return_int(webui_event_t* e, long long int n) {
webui_return_int(e, n);
}
// Save window object
window_list[id] = this;
// Return the response to JavaScript as string.
void return_string(webui_event_t* e, std::string s) {
webui_return_string(e, &s[0]);
}
// Save callback
callback_list[id] = func;
}
// Return the response to JavaScript as boolean.
void return_bool(webui_event_t* e, bool b) {
webui_return_bool(e, b);
}
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(std::string content) {
return webui_show(this->webui_window, content.c_str());
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}
// Same as show(). But with a specific web browser.
bool show_browser(std::string content, unsigned int browser) {
return webui_show_browser(this->webui_window, content.c_str(), browser);
}
// When using `interface_bind()` you need this function to easily set your callback response.
void interface_set_response(size_t window, webui_event_t* e, std::string response) {
webui_interface_set_response(window, e->event_number, response.c_str());
}
// Close a specific window.
void close() {
webui_close(this->webui_window);
}
// Check if the app still running or not. This replace wait().
bool interface_is_app_running(void) {
return webui_interface_is_app_running();
}
// Set the window in Kiosk mode (Full screen)
void set_kiosk(bool status) {
webui_set_kiosk(this->webui_window, status);
}
// Get window unique ID
unsigned int interface_get_window_id(size_t window) {
return webui_interface_get_window_id(window);
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown() {
return webui_is_shown(this->webui_window);
}
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Set the default embedded HTML favicon
void set_icon(std::string icon, std::string icon_type) {
webui_set_icon(this->webui_window, icon.c_str(), icon_type.c_str());
}
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(bool status) {
webui_set_multi_access(this->webui_window, status);
}
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(std::string script) {
return webui_run(this->webui_window, script.c_str());
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(this->webui_window, script.c_str(), timeout, buffer, buffer_length);
}
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(unsigned int runtime) {
webui_set_runtime(this->webui_window, runtime);
}
// Parse argument as integer.
long long int get_int(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
long long int ret = webui_get_int(c_e);
delete c_e;
return ret;
}
// Parse argument as string.
std::string get_string(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
std::string ret = std::string(webui_get_string(c_e));
delete c_e;
return ret;
}
// Parse argument as boolean.
bool get_bool(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
bool ret = webui_get_bool(c_e);
delete c_e;
return ret;
}
// Return the response to JavaScript as integer.
void return_int(webui::event* e, long long int n) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_int(c_e, n);
delete c_e;
}
// Return the response to JavaScript as string.
void return_string(webui::event* e, std::string s) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_string(c_e, &s[0]);
delete c_e;
}
// Return the response to JavaScript as boolean.
void return_bool(webui::event* e, bool b) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_bool(c_e, b);
delete c_e;
}
};
}
#endif /* _WEBUI_HPP */

View File

@ -6,7 +6,7 @@
// Include C++ STD
#include <iostream>
void my_function_string(webui_event_t* e) {
void my_function_string(webui::event* e) {
// JavaScript:
// webui_fn('MyID_One', 'Hello');
@ -25,7 +25,7 @@ void my_function_string(webui_event_t* e) {
// bar = my_json[1];
}
void my_function_integer(webui_event_t* e) {
void my_function_integer(webui::event* e) {
// JavaScript:
// webui_fn('MyID_Two', 123456789);
@ -34,7 +34,7 @@ void my_function_integer(webui_event_t* e) {
std::cout << "my_function_integer: " << number << std::endl; // 123456789
}
void my_function_boolean(webui_event_t* e) {
void my_function_boolean(webui::event* e) {
// JavaScript:
// webui_fn('MyID_Three', true);
@ -46,7 +46,7 @@ void my_function_boolean(webui_event_t* e) {
std::cout << "my_function_boolean: False" << std::endl;
}
void my_function_with_response(webui_event_t* e) {
void my_function_with_response(webui::event* e) {
// JavaScript:
// const result = webui_fn('MyID_Four', number);
@ -109,16 +109,16 @@ int main() {
)V0G0N";
// Create a window
size_t my_window = webui::new_window();
webui::window my_window;
// Bind HTML elements with C++ functions
webui::bind(my_window, "MyID_One", my_function_string);
webui::bind(my_window, "MyID_Two", my_function_integer);
webui::bind(my_window, "MyID_Three", my_function_boolean);
webui::bind(my_window, "MyID_Four", my_function_with_response);
my_window.bind("MyID_One", my_function_string);
my_window.bind("MyID_Two", my_function_integer);
my_window.bind("MyID_Three", my_function_boolean);
my_window.bind("MyID_Four", my_function_with_response);
// Show the window
webui::show(my_window, my_html); // webui_show_browser(my_window, my_html, Chrome);
my_window.show(my_html); // webui_show_browser(my_window, my_html, Chrome);
// Wait until all windows get closed
webui::wait();

View File

@ -9,13 +9,13 @@
#include <string>
#include <stdexcept>
void my_function_exit(webui_event_t* e) {
void my_function_exit(webui::event* e) {
// Close all opened windows
webui::exit();
}
void my_function_count(webui_event_t* e) {
void my_function_count(webui::event* e) {
// This function gets called every time the user clicks on "MyButton1"
@ -91,14 +91,14 @@ int main() {
)V0G0N";
// Create a window
size_t my_window = webui::new_window();
webui::window my_window;
// Bind HTML elements with C++ functions
webui::bind(my_window, "MyButton1", my_function_count);
webui::bind(my_window, "MyButton2", my_function_exit);
my_window.bind("MyButton1", my_function_count);
my_window.bind("MyButton2", my_function_exit);
// Show the window
webui::show(my_window, my_html); // webui::show_browser(my_window, my_html, Chrome);
my_window.show(my_html); // webui::show_browser(my_window, my_html, Chrome);
// Wait until all windows get closed
webui::wait();

View File

@ -2,8 +2,8 @@
#include <iostream>
int main() {
size_t my_window = webui::new_window();
webui::show(my_window, "<html>Hello World!</html>");
webui::window my_window;
my_window.show("<html>Hello World!</html>");
webui::wait();
return 0;
}

View File

@ -1,153 +0,0 @@
/*
WebUI Library 2.3.0
http://webui.me
https://github.com/alifcommunity/webui
Copyright (c) 2020-2023 Hassan Draga.
Licensed under MIT License.
All rights reserved.
Canada.
*/
#ifndef _WEBUI_HPP
#define _WEBUI_HPP
// C++ STD
#include <string>
// WebUI C Header
extern "C" {
#include "webui.h"
}
namespace webui {
// Create a new webui window object.
size_t new_window(void) {
return webui_new_window();
}
// Bind a specific html element click event with a function. Empty element means all events.
unsigned int bind(size_t window, std::string element, void (*func)(webui_event_t* e)) {
return webui_bind(window, element.c_str(), func);
}
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(size_t window, std::string content) {
return webui_show(window, content.c_str());
}
// Same as show(). But with a specific web browser.
bool show_browser(size_t window, std::string content, unsigned int browser) {
return webui_show_browser(window, content.c_str(), browser);
}
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// Close a specific window.
void close(size_t window) {
webui_close(window);
}
// Set the window in Kiosk mode (Full screen)
void set_kiosk(size_t window, bool status) {
webui_set_kiosk(window, status);
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown(size_t window) {
return webui_is_shown(window);
}
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Set the default embedded HTML favicon
void set_icon(size_t window, std::string icon, std::string icon_type) {
webui_set_icon(window, icon.c_str(), icon_type.c_str());
}
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(size_t window, bool status) {
webui_set_multi_access(window, status);
}
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(size_t window, std::string script) {
return webui_run(window, script.c_str());
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(size_t window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
}
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(size_t window, unsigned int runtime) {
webui_set_runtime(window, runtime);
}
// Parse argument as integer.
long long int get_int(webui_event_t* e) {
return webui_get_int(e);
}
// Parse argument as string.
std::string get_string(webui_event_t* e) {
return std::string(webui_get_string(e));
}
// Parse argument as boolean.
bool get_bool(webui_event_t* e) {
return webui_get_bool(e);
}
// Return the response to JavaScript as integer.
void return_int(webui_event_t* e, long long int n) {
webui_return_int(e, n);
}
// Return the response to JavaScript as string.
void return_string(webui_event_t* e, std::string s) {
webui_return_string(e, &s[0]);
}
// Return the response to JavaScript as boolean.
void return_bool(webui_event_t* e, bool b) {
webui_return_bool(e, b);
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}
// When using `interface_bind()` you need this function to easily set your callback response.
void interface_set_response(size_t window, webui_event_t* e, std::string response) {
webui_interface_set_response(window, e->event_number, response.c_str());
}
// Check if the app still running or not. This replace wait().
bool interface_is_app_running(void) {
return webui_interface_is_app_running();
}
// Get window unique ID
unsigned int interface_get_window_id(size_t window) {
return webui_interface_get_window_id(window);
}
}
#endif /* _WEBUI_HPP */

View File

@ -5,7 +5,7 @@
#include <iostream>
// Making this object global so show_second_window() can access it.
size_t my_second_window;
webui::window my_second_window;
// Example of a simple Class
class MyClass {
@ -13,38 +13,38 @@ class MyClass {
// This method gets called every time the
// user clicks on "OpenNewWindow"
void show_second_window(webui_event_t* e) {
void show_second_window(webui::event* e) {
// Show a new window, and navigate to `/second.html`
// if the window is already opened, then switch in the same window
webui::show(my_second_window, "second.html");
my_second_window.show("second.html");
}
// This method gets called every time the
// user clicks on "SwitchToSecondPage"
void switch_to_second_page(webui_event_t* e) {
void switch_to_second_page(webui::event* e) {
// Switch to `/second.html` in the same opened window.
webui::show(e->window, "second.html");
e->window.show("second.html");
}
// Example of a simple function (Not a method)
// This function receives all events because
// it's get bind with an empty HTML ID.
void events(webui_event_t* e) {
void events(webui::event* e) {
if (e->event_type == WEBUI_EVENT_CONNECTED)
if (e->event_type == webui::CONNECTED)
std::cout << "Window Connected." << std::endl;
else if (e->event_type == WEBUI_EVENT_DISCONNECTED)
else if (e->event_type == webui::DISCONNECTED)
std::cout << "Window Disconnected." << std::endl;
else if (e->event_type == WEBUI_EVENT_MOUSE_CLICK)
else if (e->event_type == webui::MOUSE_CLICK)
std::cout << "Click on element: " << e->element << std::endl;
else if (e->event_type == WEBUI_EVENT_NAVIGATION)
else if (e->event_type == webui::NAVIGATION)
std::cout << "Starting navigation to: " << e->data << std::endl;
}
// Example of a simple function (Not a method)
void exit_app(webui_event_t* e) {
void exit_app(webui::event* e) {
// Close all opened windows
webui::exit();
@ -56,10 +56,10 @@ class MyClass {
// access `MyClass` directly. That's why we should
// create a simple C++ wrapper.
MyClass obj;
void show_second_window_wrp(webui_event_t* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui_event_t* e) { obj.switch_to_second_page(e); }
void events_wrp(webui_event_t* e) { obj.events(e); }
void exit_app_wrp(webui_event_t* e) { obj.exit_app(e); }
void show_second_window_wrp(webui::event* e) { obj.show_second_window(e); }
void switch_to_second_page_wrp(webui::event* e) { obj.switch_to_second_page(e); }
void events_wrp(webui::event* e) { obj.events(e); }
void exit_app_wrp(webui::event* e) { obj.exit_app(e); }
int main() {
@ -67,20 +67,19 @@ int main() {
std::cout << "Starting..." << std::endl;
// Create a new window
size_t my_window = webui::new_window();
my_second_window = webui::new_window();
webui::window my_window;
// Bind HTML element IDs with a C functions
webui::bind(my_window, "SwitchToSecondPage", switch_to_second_page_wrp);
webui::bind(my_window, "OpenNewWindow", show_second_window_wrp);
webui::bind(my_window, "Exit", exit_app_wrp);
webui::bind(my_second_window, "Exit", exit_app_wrp);
my_window.bind("SwitchToSecondPage", switch_to_second_page_wrp);
my_window.bind("OpenNewWindow", show_second_window_wrp);
my_window.bind("Exit", exit_app_wrp);
my_second_window.bind("Exit", exit_app_wrp);
// Bind events
webui::bind(my_window, "", events_wrp);
// Bind all events
// my_window.bind("", events_wrp);
// Show a new window
webui::show(my_window, "index.html"); // webui::show_browser(my_window, "index.html", Chrome);
my_window.show("index.html"); // webui::show_browser(my_window, "index.html", Chrome);
// Wait until all windows get closed
webui::wait();

View File

@ -130,7 +130,7 @@ enum webui_events {
// -- Structs -------------------------
typedef struct webui_event_t {
size_t window; // Pointer to the window object
size_t window; // The window object number
unsigned int event_type; // Event type
char* element; // HTML element ID
char* data; // JavaScript data
@ -194,5 +194,7 @@ WEBUI_EXPORT void webui_interface_set_response(size_t window, unsigned int event
WEBUI_EXPORT bool webui_interface_is_app_running(void);
// Get window unique ID
WEBUI_EXPORT unsigned int webui_interface_get_window_id(size_t window);
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
WEBUI_EXPORT unsigned int webui_interface_get_bind_id(size_t window, const char* element);
#endif /* _WEBUI_H */

View File

@ -130,7 +130,7 @@ enum webui_events {
// -- Structs -------------------------
typedef struct webui_event_t {
size_t window; // Pointer to the window object
size_t window; // The window object number
unsigned int event_type; // Event type
char* element; // HTML element ID
char* data; // JavaScript data
@ -194,5 +194,7 @@ WEBUI_EXPORT void webui_interface_set_response(size_t window, unsigned int event
WEBUI_EXPORT bool webui_interface_is_app_running(void);
// Get window unique ID
WEBUI_EXPORT unsigned int webui_interface_get_window_id(size_t window);
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
WEBUI_EXPORT unsigned int webui_interface_get_bind_id(size_t window, const char* element);
#endif /* _WEBUI_H */

View File

@ -16,138 +16,217 @@
// WebUI C Header
extern "C" {
#include "webui.h"
#include "webui.h"
}
namespace webui {
// Create a new webui window object.
size_t new_window(void) {
return webui_new_window();
}
const int DISCONNECTED = 0; // 0. Window disconnection event
const int CONNECTED = 1; // 1. Window connection event
const int MULTI_CONNECTION = 2; // 2. New window connection event
const int UNWANTED_CONNECTION = 3; // 3. New unwanted window connection event
const int MOUSE_CLICK = 4; // 4. Mouse click event
const int NAVIGATION = 5; // 5. Window navigation event
const int CALLBACKS = 6; // 6. Function call event
// Bind a specific html element click event with a function. Empty element means all events.
unsigned int bind(size_t window, std::string element, void (*func)(webui_event_t* e)) {
return webui_bind(window, element.c_str(), func);
}
class window;
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(size_t window, std::string content) {
return webui_show(window, content.c_str());
}
// Event struct
struct event {
webui::window& window; // The window object
unsigned int event_type; // Event type
std::string element; // HTML element ID
std::string data; // JavaScript data
unsigned int event_number; // Internal WebUI
// Same as show(). But with a specific web browser.
bool show_browser(size_t window, std::string content, unsigned int browser) {
return webui_show_browser(window, content.c_str(), browser);
}
// Window object constructor that
// initializes the reference, This
// is to avoid creating copies.
event(webui::window& window_obj) : window(window_obj) {}
};
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// List of callbacks: user_function(webui::event* e)
void (*callback_list[512])(webui::event*);
// Close a specific window.
void close(size_t window) {
webui_close(window);
}
// List of window objects: webui::window
webui::window* window_list[512];
// Set the window in Kiosk mode (Full screen)
void set_kiosk(size_t window, bool status) {
webui_set_kiosk(window, status);
}
// Wait until all opened windows get closed.
void wait(void) {
webui_wait();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// Close all opened windows. wait() will break.
void exit(void) {
webui_exit();
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown(size_t window) {
return webui_is_shown(window);
}
// Event handler
// WebUI is written in C. So there is no way
// to make C call a C++ class member. That's
// why this function should be outside class
void event_handler(webui_event_t* c_e) {
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
unsigned int id = webui_interface_get_bind_id(c_e->window, c_e->element);
// Set the default embedded HTML favicon
void set_icon(size_t window, std::string icon, std::string icon_type) {
webui_set_icon(window, icon.c_str(), icon_type.c_str());
}
if(id < 1)
return;
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(size_t window, bool status) {
webui_set_multi_access(window, status);
}
// Create a new event struct
webui::event e(*window_list[id]);
// `e.window` is already initialized by `e` constructor
e.event_type = c_e->event_type;
e.element = (c_e->element != NULL ? std::string(c_e->element) : std::string(""));
e.data = (c_e->data != NULL ? std::string(c_e->data) : std::string(""));
e.event_number = c_e->event_number;
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(size_t window, std::string script) {
return webui_run(window, script.c_str());
}
// Call the user callback
if(callback_list[id] != NULL)
callback_list[id](&e);
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(size_t window, std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(window, script.c_str(), timeout, buffer, buffer_length);
}
class window {
private:
size_t webui_window = 0;
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(size_t window, unsigned int runtime) {
webui_set_runtime(window, runtime);
}
webui_event_t* convert_event_to_webui_event(webui::event* e) {
// Convert C++ `webui::event` to C `webui_event_t`
webui_event_t* c_e = new webui_event_t;
c_e->window = this->webui_window;
c_e->event_type = e->event_type;
c_e->element = (char*)e->element.c_str();
c_e->data = (char*)e->data.c_str();
c_e->event_number = e->event_number;
return c_e;
}
public:
// Constructor
window() {
this->webui_window = webui_new_window();
}
// Parse argument as integer.
long long int get_int(webui_event_t* e) {
return webui_get_int(e);
}
// Destructor
~window() {
// Nothing to do.
// No needs to call `webui_close()`
}
// Parse argument as string.
std::string get_string(webui_event_t* e) {
return std::string(webui_get_string(e));
}
// Bind a specific html element click event with a function. Empty element means all events.
void bind(std::string element, void (*func)(webui::event* e)) {
// Parse argument as boolean.
bool get_bool(webui_event_t* e) {
return webui_get_bool(e);
}
// Get unique ID
unsigned int id = webui_bind(this->webui_window, element.c_str(), webui::event_handler);
// Return the response to JavaScript as integer.
void return_int(webui_event_t* e, long long int n) {
webui_return_int(e, n);
}
// Save window object
window_list[id] = this;
// Return the response to JavaScript as string.
void return_string(webui_event_t* e, std::string s) {
webui_return_string(e, &s[0]);
}
// Save callback
callback_list[id] = func;
}
// Return the response to JavaScript as boolean.
void return_bool(webui_event_t* e, bool b) {
webui_return_bool(e, b);
}
// Show a window using a embedded HTML, or a file. If the window is already opened then it will be refreshed.
bool show(std::string content) {
return webui_show(this->webui_window, content.c_str());
}
// -- Interface -----------------------
// Bind a specific html element click event with a function. Empty element means all events. This replace bind(). The func is (Window, EventType, Element, Data, Response)
unsigned int interface_bind(size_t window, std::string element, void (*func)(size_t, unsigned int, char*, char*, unsigned int)) {
return webui_interface_bind(window, element.c_str(), func);
}
// Same as show(). But with a specific web browser.
bool show_browser(std::string content, unsigned int browser) {
return webui_show_browser(this->webui_window, content.c_str(), browser);
}
// When using `interface_bind()` you need this function to easily set your callback response.
void interface_set_response(size_t window, webui_event_t* e, std::string response) {
webui_interface_set_response(window, e->event_number, response.c_str());
}
// Close a specific window.
void close() {
webui_close(this->webui_window);
}
// Check if the app still running or not. This replace wait().
bool interface_is_app_running(void) {
return webui_interface_is_app_running();
}
// Set the window in Kiosk mode (Full screen)
void set_kiosk(bool status) {
webui_set_kiosk(this->webui_window, status);
}
// Get window unique ID
unsigned int interface_get_window_id(size_t window) {
return webui_interface_get_window_id(window);
}
// -- Other ---------------------------
// Check a specific window if it's still running
bool is_shown() {
return webui_is_shown(this->webui_window);
}
// Set the maximum time in seconds to wait for browser to start
void set_timeout(unsigned int second) {
webui_set_timeout(second);
}
// Set the default embedded HTML favicon
void set_icon(std::string icon, std::string icon_type) {
webui_set_icon(this->webui_window, icon.c_str(), icon_type.c_str());
}
// Allow the window URL to be re-used in normal web browsers
void set_multi_access(bool status) {
webui_set_multi_access(this->webui_window, status);
}
// -- JavaScript ----------------------
// Quickly run a JavaScript (no response waiting).
bool run(std::string script) {
return webui_run(this->webui_window, script.c_str());
}
// Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).
bool script(std::string script, unsigned int timeout, char* buffer, size_t buffer_length) {
return webui_script(this->webui_window, script.c_str(), timeout, buffer, buffer_length);
}
// Chose between Deno and Nodejs runtime for .js and .ts files.
void set_runtime(unsigned int runtime) {
webui_set_runtime(this->webui_window, runtime);
}
// Parse argument as integer.
long long int get_int(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
long long int ret = webui_get_int(c_e);
delete c_e;
return ret;
}
// Parse argument as string.
std::string get_string(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
std::string ret = std::string(webui_get_string(c_e));
delete c_e;
return ret;
}
// Parse argument as boolean.
bool get_bool(webui::event* e) {
webui_event_t* c_e = convert_event_to_webui_event(e);
bool ret = webui_get_bool(c_e);
delete c_e;
return ret;
}
// Return the response to JavaScript as integer.
void return_int(webui::event* e, long long int n) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_int(c_e, n);
delete c_e;
}
// Return the response to JavaScript as string.
void return_string(webui::event* e, std::string s) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_string(c_e, &s[0]);
delete c_e;
}
// Return the response to JavaScript as boolean.
void return_bool(webui::event* e, bool b) {
webui_event_t* c_e = convert_event_to_webui_event(e);
webui_return_bool(c_e, b);
delete c_e;
}
};
}
#endif /* _WEBUI_HPP */

View File

@ -299,13 +299,13 @@ bool webui_run(size_t window, const char* script) {
printf("[User] webui_run([%s])...\n", script);
#endif
size_t js_len = strlen(script);
size_t js_len = _webui_strlen(script);
if(js_len < 1)
return false;
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return false;
_webui_window_t* win = _webui_core.wins[window];
// Initializing pipe
@ -334,7 +334,7 @@ bool webui_run(size_t window, const char* script) {
bool webui_script(size_t window, const char* script, unsigned int timeout_second, char* buffer, size_t buffer_length) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return false;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -350,7 +350,7 @@ bool webui_script(size_t window, const char* script, unsigned int timeout_second
if(buffer_length > 0)
memset(buffer, 0, buffer_length);
size_t js_len = strlen(script);
size_t js_len = _webui_strlen(script);
if(js_len < 1) {
@ -413,7 +413,7 @@ bool webui_script(size_t window, const char* script, unsigned int timeout_second
if(buffer != NULL && buffer_length > 1) {
// Copy response to the user's response buffer
size_t response_len = strlen(_webui_core.run_responses[run_id]) + 1;
size_t response_len = _webui_strlen(_webui_core.run_responses[run_id]) + 1;
size_t bytes_to_cpy = (response_len <= buffer_length ? response_len : buffer_length);
memcpy(buffer, _webui_core.run_responses[run_id], bytes_to_cpy);
}
@ -461,7 +461,7 @@ size_t webui_new_window(void) {
void webui_set_kiosk(size_t window, bool status) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
win->kiosk_mode = status;
@ -470,11 +470,11 @@ void webui_set_kiosk(size_t window, bool status) {
void webui_close(size_t window) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
printf("[User] webui_close()...\n");
printf("[User] webui_close([%zu])...\n", window);
#endif
_webui_init();
@ -497,7 +497,7 @@ void webui_close(size_t window) {
bool webui_is_shown(size_t window) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return false;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -510,7 +510,7 @@ bool webui_is_shown(size_t window) {
void webui_set_multi_access(size_t window, bool status) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -523,7 +523,7 @@ void webui_set_multi_access(size_t window, bool status) {
void webui_set_icon(size_t window, const char* icon, const char* icon_type) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -537,7 +537,7 @@ void webui_set_icon(size_t window, const char* icon, const char* icon_type) {
bool webui_show(size_t window, const char* content) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return false;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -554,7 +554,7 @@ bool webui_show(size_t window, const char* content) {
bool webui_show_browser(size_t window, const char* content, unsigned int browser) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return false;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -567,7 +567,7 @@ bool webui_show_browser(size_t window, const char* content, unsigned int browser
unsigned int webui_bind(size_t window, const char* element, void (*func)(webui_event_t* e)) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return 0;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -580,7 +580,7 @@ unsigned int webui_bind(size_t window, const char* element, void (*func)(webui_e
if(_webui_is_empty(element))
win->has_events = true;
else
len = strlen(element);
len = _webui_strlen(element);
// [win num][/][element]
char* webui_internal_id = _webui_malloc(3 + 1 + len);
@ -616,7 +616,7 @@ const char* webui_get_string(webui_event_t* e) {
#endif
if(e->data != NULL) {
size_t len = strlen(e->data);
size_t len = _webui_strlen(e->data);
if(len > 0 && len <= WEBUI_MAX_BUF)
return (const char* ) e->data;
}
@ -633,7 +633,7 @@ long long int webui_get_int(webui_event_t* e) {
char* endptr;
if(e->data != NULL) {
size_t len = strlen(e->data);
size_t len = _webui_strlen(e->data);
if(len > 0 && len <= 20) // 64-bit max is -9,223,372,036,854,775,808 (20 character)
return strtoll((const char* ) e->data, &endptr, 10);
}
@ -661,7 +661,7 @@ void webui_return_int(webui_event_t* e, long long int n) {
#endif
// Dereference
if(_webui_core.wins[e->window] == NULL) _webui_panic();
if(_webui_core.wins[e->window] == NULL) return;
_webui_window_t* win = _webui_core.wins[e->window];
// Get buffer
@ -692,7 +692,7 @@ void webui_return_string(webui_event_t* e, char* s) {
return;
// Dereference
if(_webui_core.wins[e->window] == NULL) _webui_panic();
if(_webui_core.wins[e->window] == NULL) return;
_webui_window_t* win = _webui_core.wins[e->window];
// Get buffer
@ -705,7 +705,7 @@ void webui_return_string(webui_event_t* e, char* s) {
_webui_free_mem((void*)*response);
// Copy Str
int len = strlen(s);
int len = _webui_strlen(s);
char* buf = (char*) _webui_malloc(len);
memcpy(buf, s, len);
@ -720,7 +720,7 @@ void webui_return_bool(webui_event_t* e, bool b) {
#endif
// Dereference
if(_webui_core.wins[e->window] == NULL) _webui_panic();
if(_webui_core.wins[e->window] == NULL) return;
_webui_window_t* win = _webui_core.wins[e->window];
// Get buffer
@ -819,7 +819,7 @@ void webui_set_timeout(unsigned int second) {
void webui_set_runtime(size_t window, unsigned int runtime) {
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
#ifdef WEBUI_LOG
@ -842,7 +842,7 @@ static void _webui_interface_bind_handler(webui_event_t* e) {
#endif
// Dereference
if(_webui_core.wins[e->window] == NULL) _webui_panic();
if(_webui_core.wins[e->window] == NULL) return;
_webui_window_t* win = _webui_core.wins[e->window];
// Generate WebUI internal id
@ -860,6 +860,9 @@ static void _webui_interface_bind_handler(webui_event_t* e) {
#endif
// Call cb
#ifdef WEBUI_LOG
printf("[Core]\t\t_webui_interface_bind_handler() -> Calling user callback...\n\n");
#endif
_webui_core.cb_interface[cb_index](e->window, e->event_type, e->element, e->data, e->event_number);
}
@ -896,7 +899,7 @@ void webui_interface_set_response(size_t window, unsigned int event_number, cons
#endif
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return;
_webui_window_t* win = _webui_core.wins[window];
// Get internal response buffer
@ -906,7 +909,7 @@ void webui_interface_set_response(size_t window, unsigned int event_number, cons
buffer = &win->event_core[event_number]->response;
// Set the response
size_t len = strlen(response);
size_t len = _webui_strlen(response);
*buffer = (char*) _webui_malloc(len);
strcpy(*buffer, response);
@ -958,12 +961,36 @@ unsigned int webui_interface_get_window_id(size_t window) {
#endif
// Dereference
if(_webui_core.wins[window] == NULL) _webui_panic();
if(_webui_core.wins[window] == NULL) return 0;
_webui_window_t* win = _webui_core.wins[window];
return win->window_number;
}
unsigned int webui_interface_get_bind_id(size_t window, const char* element) {
#ifdef WEBUI_LOG
printf("[User] webui_interface_get_bind_id([%zu], [%s])...\n", window, element);
#endif
// Dereference
if(_webui_core.wins[window] == NULL) return 0;
_webui_window_t* win = _webui_core.wins[window];
size_t len = _webui_strlen(element);
if(len < 1)
element = webui_empty_string;
// [win num][/][element]
char* webui_internal_id = _webui_malloc(3 + 1 + len);
sprintf(webui_internal_id, "%u/%s", win->window_number, element);
unsigned int cb_index = _webui_get_cb_index(webui_internal_id);
_webui_free_mem((void*)webui_internal_id);
return cb_index;
}
// -- Core's Functions ----------------
static bool _webui_ptr_exist(void* ptr) {
@ -1243,6 +1270,24 @@ static bool _webui_is_empty(const char* s) {
return true;
}
static size_t _webui_strlen(const char* s) {
#ifdef WEBUI_LOG
printf("[Core]\t\t_webui_strlen()...\n");
#endif
if(_webui_is_empty(s))
return 0;
size_t length = 0;
while ((s[length] != '\0') && (length < WEBUI_MAX_BUF)) {
length++;
}
return length;
}
static bool _webui_file_exist_mg(struct mg_connection *conn) {
#ifdef WEBUI_LOG
@ -1254,7 +1299,7 @@ static bool _webui_file_exist_mg(struct mg_connection *conn) {
const struct mg_request_info *ri = mg_get_request_info(conn);
const char* url = ri->local_uri;
size_t url_len = strlen(url);
size_t url_len = _webui_strlen(url);
// Get file name
file = (char*) _webui_malloc(url_len);
@ -1264,7 +1309,7 @@ static bool _webui_file_exist_mg(struct mg_connection *conn) {
// Get full path
// [current folder][/][file]
full_path = (char*) _webui_malloc(strlen(_webui_core.executable_path) + 1 + strlen(file));
full_path = (char*) _webui_malloc(_webui_strlen(_webui_core.executable_path) + 1 + _webui_strlen(file));
sprintf(full_path, "%s%s%s", _webui_core.executable_path, webui_sep, file);
bool exist = _webui_file_exist(full_path);
@ -1426,11 +1471,11 @@ static char* _webui_get_full_path_from_url(const char* url) {
if(file == NULL)
return NULL;
size_t url_len = strlen(url);
size_t url_len = _webui_strlen(url);
// Get full path
// [current folder][/][file]
char* full_path = (char*) _webui_malloc(strlen(_webui_core.executable_path) + 1 + strlen(file));
char* full_path = (char*) _webui_malloc(_webui_strlen(_webui_core.executable_path) + 1 + _webui_strlen(file));
sprintf(full_path, "%s%s%s", _webui_core.executable_path, webui_sep, file);
// Clean
@ -1581,7 +1626,7 @@ static int _webui_interpret_file(_webui_window_t* win, struct mg_connection *con
const struct mg_request_info *ri = mg_get_request_info(conn);
const char* url = ri->local_uri;
size_t url_len = strlen(url);
size_t url_len = _webui_strlen(url);
// Get file full path
if(index != NULL && !_webui_is_empty(index)) {
@ -1638,7 +1683,7 @@ static int _webui_interpret_file(_webui_window_t* win, struct mg_connection *con
// Set command
// [disable coloring][file]
char* cmd = (char*) _webui_malloc(64 + strlen(full_path));
char* cmd = (char*) _webui_malloc(64 + _webui_strlen(full_path));
#ifdef _WIN32
sprintf(cmd, "Set NO_COLOR=1 & Set DENO_NO_UPDATE_CHECK=1 & deno run --quiet --allow-all --unstable \"%s\" \"%s\"", full_path, query);
#else
@ -1691,7 +1736,7 @@ static int _webui_interpret_file(_webui_window_t* win, struct mg_connection *con
// Set command
// [node][file]
char* cmd = (char*) _webui_malloc(16 + strlen(full_path));
char* cmd = (char*) _webui_malloc(16 + _webui_strlen(full_path));
sprintf(cmd, "node \"%s\" \"%s\"", full_path, query);
// Run command
@ -1762,7 +1807,7 @@ static const char* _webui_generate_js_bridge(_webui_window_t* win) {
size_t cb_mem_size = 64; // To hold 'const _webui_bind_list = ["elem1", "elem2",];'
for(unsigned int i = 1; i < WEBUI_MAX_ARRAY; i++)
if(_webui_core.html_elements[i] != NULL && !_webui_is_empty(_webui_core.html_elements[i]))
cb_mem_size += strlen(_webui_core.html_elements[i]) + 3;
cb_mem_size += _webui_strlen(_webui_core.html_elements[i]) + 3;
// Generate the cb array
char* event_cb_js_array = (char*) _webui_malloc(cb_mem_size);
@ -1777,7 +1822,7 @@ static const char* _webui_generate_js_bridge(_webui_window_t* win) {
strcat(event_cb_js_array, "]; \n");
// Generate the full WebUI JS-Bridge
size_t len = cb_mem_size + strlen(webui_javascript_bridge);
size_t len = cb_mem_size + _webui_strlen(webui_javascript_bridge);
char* js = (char*) _webui_malloc(len);
sprintf(js,
"_webui_port = %u; \n_webui_win_num = %u; \n%s \n%s \n",
@ -1932,7 +1977,7 @@ static char* _webui_generate_internal_id(_webui_window_t* win, const char* eleme
#endif
// Generate WebUI internal id
size_t element_len = strlen(element);
size_t element_len = _webui_strlen(element);
size_t internal_id_size = 3 + 1 + element_len; // [win num][/][name]
char* webui_internal_id = (char*) _webui_malloc(internal_id_size);
sprintf(webui_internal_id, "%u/%s", win->window_number, element);
@ -3069,7 +3114,7 @@ static bool _webui_set_root_folder(_webui_window_t* win, const char* path) {
printf("[Core]\t\t_webui_set_root_folder([%s])...\n", path);
#endif
if((path == NULL) || (strlen(path) > WEBUI_MAX_PATH))
if((path == NULL) || (_webui_strlen(path) > WEBUI_MAX_PATH))
return false;
win->is_embedded_html = true;
@ -3237,7 +3282,7 @@ static bool _webui_show(_webui_window_t* win, const char* content, unsigned int
// Some wrappers does not guarantee `content` to
// stay valid, so, let's make our copy right now
size_t content_len = strlen(content);
size_t content_len = _webui_strlen(content);
const char* content_cpy = (const char*)_webui_malloc(content_len);
memcpy((char*)content_cpy, content, content_len);
@ -3304,7 +3349,7 @@ static bool _webui_show_window(_webui_window_t* win, const char* content, bool i
win->html = NULL;
// Generate the URL
size_t url_len = 32 + strlen(content); // [http][domain][port][file]
size_t url_len = 32 + _webui_strlen(content); // [http][domain][port][file]
url = (char*) _webui_malloc(url_len);
sprintf(url, "http://localhost:%u/%s", port, content);
}
@ -3347,12 +3392,12 @@ static bool _webui_show_window(_webui_window_t* win, const char* content, bool i
// Refresh an existing running window
// Prepare packets
size_t packet_len = 3 + strlen(url); // [header][url]
size_t packet_len = 3 + _webui_strlen(url); // [header][url]
char* packet = (char*) _webui_malloc(packet_len);
packet[0] = WEBUI_HEADER_SIGNATURE; // Signature
packet[1] = WEBUI_HEADER_SWITCH; // Type
packet[2] = 0; // ID
for(unsigned int i = 0; i < strlen(win->url); i++) // URL
for(unsigned int i = 0; i < _webui_strlen(win->url); i++) // URL
packet[i + 3] = win->url[i];
// Send the packet
@ -3411,17 +3456,20 @@ static void _webui_window_send(_webui_window_t* win, char* packet, size_t packet
if(!win->connected || packet == NULL || packets_size < 4)
return;
struct mg_connection* conn = _webui_core.mg_connections[win->window_number];
int ret = 0;
if(conn != NULL) {
if(win->window_number > 0 && win->window_number < WEBUI_MAX_ARRAY) {
ret = mg_websocket_write(
conn,
MG_WEBSOCKET_OPCODE_BINARY,
packet,
packets_size
);
struct mg_connection* conn = _webui_core.mg_connections[win->window_number];
if(conn != NULL) {
ret = mg_websocket_write(
conn,
MG_WEBSOCKET_OPCODE_BINARY,
packet,
packets_size
);
}
}
#ifdef WEBUI_LOG
@ -3443,7 +3491,7 @@ static bool _webui_get_data(const char* packet, size_t packet_len, unsigned int
}
// Calculat the data part size
size_t data_size = strlen(&packet[pos]);
size_t data_size = _webui_strlen(&packet[pos]);
if(data_size < 1) {
*data = (char*)webui_empty_string;
@ -3469,7 +3517,7 @@ static bool _webui_get_data(const char* packet, size_t packet_len, unsigned int
}
// Check data size
*data_len = strlen(*data);
*data_len = _webui_strlen(*data);
if(*data_len < 1) {
_webui_free_mem((void*)data);
@ -3668,6 +3716,9 @@ static void _webui_window_receive(_webui_window_t* win, const char* packet, size
if(cb_index > 0 && _webui_core.cb[cb_index] != NULL) {
// Call user cb
#ifdef WEBUI_LOG
printf("[Core]\t\t_webui_window_receive() -> Calling user callback...\n\n");
#endif
_webui_core.cb[cb_index](&e);
}
@ -3685,7 +3736,7 @@ static void _webui_window_receive(_webui_window_t* win, const char* packet, size
// 3: [Data]
// Prepare response packet
size_t response_len = strlen(*response);
size_t response_len = _webui_strlen(*response);
size_t response_packet_len = 3 + response_len + 1;
char* response_packet = (char*) _webui_malloc(response_packet_len);
response_packet[0] = WEBUI_HEADER_SIGNATURE; // Signature
@ -3763,7 +3814,10 @@ static unsigned int _webui_get_new_window_number(void) {
printf("[Core]\t\t_webui_get_new_window_number()...\n");
#endif
return ++_webui_core.last_window;
unsigned int num = ++_webui_core.last_window;
if(num >= WEBUI_MAX_ARRAY)
_webui_panic();
return num;
}
static unsigned int _webui_get_free_port(void) {
@ -3895,7 +3949,7 @@ static void _webui_http_send(struct mg_connection *conn, const char* mime_type,
printf("[Core]\t\t_webui_http_send()...\n");
#endif
size_t len = strlen(body);
size_t len = _webui_strlen(body);
if(len < 1)
return;
@ -4011,7 +4065,7 @@ static int _webui_http_handler(struct mg_connection *conn, void *_win) {
const char* js = _webui_generate_js_bridge(win);
// Inject WebUI JS-Bridge into HTML
size_t len = strlen(win->html) + strlen(js) + 128;
size_t len = _webui_strlen(win->html) + _webui_strlen(js) + 128;
html = (char*) _webui_malloc(len);
sprintf(html,
"%s \n <script type = \"text/javascript\"> \n %s \n </script>",
@ -4043,7 +4097,7 @@ static int _webui_http_handler(struct mg_connection *conn, void *_win) {
// Set full path
// [Path][Sep][File Name]
char* index = (char*) _webui_malloc(strlen(_webui_core.executable_path) + 1 + 8);
char* index = (char*) _webui_malloc(_webui_strlen(_webui_core.executable_path) + 1 + 8);
// Index.ts
sprintf(index, "%s%sindex.ts", _webui_core.executable_path, webui_sep);
@ -4564,6 +4618,9 @@ static WEBUI_CB
if(events_cb_index > 0 && _webui_core.cb[events_cb_index] != NULL) {
// Call user all events cb
#ifdef WEBUI_LOG
printf("[Core]\t\t[Thread] _webui_cb() -> Calling user callback...\n\n");
#endif
_webui_core.cb[events_cb_index](&e);
}
}
@ -4575,6 +4632,9 @@ static WEBUI_CB
if(cb_index > 0 && _webui_core.cb[cb_index] != NULL) {
// Call user cb
#ifdef WEBUI_LOG
printf("[Core]\t\t[Thread] _webui_cb() -> Calling user callback...\n\n");
#endif
_webui_core.cb[cb_index](&e);
}
}

View File

@ -175,6 +175,7 @@ static void _webui_free_all_mem(void);
static bool _webui_show_window(_webui_window_t* win, const char* content, bool is_embedded_html, unsigned int browser);
static char* _webui_generate_internal_id(_webui_window_t* win, const char* element);
static bool _webui_is_empty(const char* s);
static size_t _webui_strlen(const char* s);
static unsigned char _webui_get_run_id(void);
static void* _webui_malloc(int size);
static void _webui_sleep(long unsigned int ms);

View File

@ -163,7 +163,7 @@ Please visit [C++ Examples](https://github.com/alifcommunity/webui/tree/main/exa
To create a new window object, you can use `webui::new_window()`, which returns a void pointer. Please note that this pointer does *NOT* need to be freed.
```cpp
size_t my_window = webui::new_window();
webui::window my_window = webui::window();
```
---