Skip to content

Commit c5f4b24

Browse files
committed
Update APIs
1 parent 20d0bfa commit c5f4b24

File tree

2 files changed

+149
-1
lines changed

2 files changed

+149
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ setup
2828
.idea/
2929
.vscode/
3030
*.iml
31+
CLAUDE.md
32+
/.claude

webui.odin

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,19 @@ foreign webui {
313313
*
314314
* @example ui.set_kiosk(myWindow, true)
315315
*/
316-
@(link_name = "webui_set_kisok")
316+
@(link_name = "webui_set_kiosk")
317317
set_kiosk :: proc(window: c.size_t, status: c.bool) ---
318318

319+
/**
320+
* @brief Bring a window to the front and focus it.
321+
*
322+
* @param window The window number
323+
*
324+
* @example ui.focus(myWindow)
325+
*/
326+
@(link_name = "webui_focus")
327+
focus :: proc(window: c.size_t) ---
328+
319329
/**
320330
* @brief Add a user-defined web browser's CLI parameters.
321331
*
@@ -367,6 +377,17 @@ foreign webui {
367377
@(link_name = "webui_wait")
368378
wait :: proc() ---
369379

380+
/**
381+
* @brief Wait asynchronously until all opened windows get closed.
382+
* Note: In WebView mode, you need to call this from the main thread.
383+
*
384+
* @return Returns True if more windows are still opened, False otherwise.
385+
*
386+
* @example for ui.wait_async() { /* main thread code here */ }
387+
*/
388+
@(link_name = "webui_wait_async")
389+
wait_async :: proc() -> c.bool ---
390+
370391
/**
371392
* @brief Close a specific window only. The window object will still exist.
372393
* All clients.
@@ -378,6 +399,26 @@ foreign webui {
378399
@(link_name = "webui_close")
379400
close :: proc(window: c.size_t) ---
380401

402+
/**
403+
* @brief Minimize a WebView window.
404+
*
405+
* @param window The window number
406+
*
407+
* @example ui.minimize(myWindow)
408+
*/
409+
@(link_name = "webui_minimize")
410+
minimize :: proc(window: c.size_t) ---
411+
412+
/**
413+
* @brief Maximize a WebView window.
414+
*
415+
* @param window The window number
416+
*
417+
* @example ui.maximize(myWindow)
418+
*/
419+
@(link_name = "webui_maximize")
420+
maximize :: proc(window: c.size_t) ---
421+
381422
/**
382423
* @brief Close a specific client.
383424
*
@@ -417,6 +458,16 @@ foreign webui {
417458
@(link_name = "webui_set_root_folder")
418459
set_root_folder :: proc(window: c.size_t, path: cstring) -> c.bool ---
419460

461+
/**
462+
* @brief Set custom browser folder path.
463+
*
464+
* @param path The browser folder path
465+
*
466+
* @example ui.set_browser_folder("/home/Foo/Bar/")
467+
*/
468+
@(link_name = "webui_set_browser_folder")
469+
set_browser_folder :: proc(path: cstring) ---
470+
420471
/**
421472
* @brief Set the web-server root folder path for all windows. Should be used
422473
* before `show()`.
@@ -428,6 +479,18 @@ foreign webui {
428479
@(link_name = "webui_set_default_root_folder")
429480
set_default_root_folder :: proc(path: cstring) -> c.bool ---
430481

482+
/**
483+
* @brief Set a callback to catch the close event of the WebView window.
484+
* Must return `false` to prevent the close event, `true` otherwise.
485+
*
486+
* @param window The window number
487+
* @param close_handler The callback function: `proc(window: c.size_t) -> bool`
488+
*
489+
* @example ui.set_close_handler_wv(myWindow, myCloseEvent)
490+
*/
491+
@(link_name = "webui_set_close_handler_wv")
492+
set_close_handler_wv :: proc(window: c.size_t, close_handler: proc(window: c.size_t) -> c.bool) ---
493+
431494
/**
432495
* @brief Set a custom handler to serve files. This custom handler should
433496
* return full HTTP header and body.
@@ -457,6 +520,19 @@ foreign webui {
457520
set_file_handler_window :: proc(window: c.size_t, handler: proc(window: c.size_t, filename: cstring, length: ^c.int) -> rawptr) ---
458521

459522

523+
/**
524+
* @brief Use this API to set a file handler response if your backend needs async
525+
* response for `set_file_handler()`.
526+
*
527+
* @param window The window number
528+
* @param response The response buffer
529+
* @param length The response size
530+
*
531+
* @example ui.interface_set_response_file_handler(myWindow, buffer, 1024)
532+
*/
533+
@(link_name = "webui_interface_set_response_file_handler")
534+
interface_set_response_file_handler :: proc(window: c.size_t, response: rawptr, length: c.int) ---
535+
460536
/**
461537
* @brief Check if the specified window is still running.
462538
*
@@ -535,6 +611,18 @@ foreign webui {
535611
@(link_name = "webui_malloc")
536612
malloc :: proc(size: c.size_t) -> rawptr ---
537613

614+
/**
615+
* @brief Copy raw data.
616+
*
617+
* @param dest Destination memory pointer
618+
* @param src Source memory pointer
619+
* @param count Bytes to copy
620+
*
621+
* @example ui.memcpy(myBuffer, myData, 64)
622+
*/
623+
@(link_name = "webui_memcpy")
624+
memcpy :: proc(dest: rawptr, src: rawptr, count: c.size_t) ---
625+
538626
/**
539627
* @brief Safely send raw data to the UI. All clients.
540628
*
@@ -764,6 +852,33 @@ foreign webui {
764852
@(link_name = "webui_get_child_process_id")
765853
get_child_process_id :: proc(window: c.size_t) -> c.size_t ---
766854

855+
/**
856+
* @brief Gets Win32 window `HWND`. More reliable with WebView
857+
* than web browser window, as browser PIDs may change on launch.
858+
*
859+
* @param window The window number
860+
*
861+
* @return Returns the window `hwnd` as `rawptr`
862+
*
863+
* @example hwnd := ui.win32_get_hwnd(myWindow)
864+
*/
865+
@(link_name = "webui_win32_get_hwnd")
866+
win32_get_hwnd :: proc(window: c.size_t) -> rawptr ---
867+
868+
/**
869+
* @brief Get window handle. More reliable with WebView
870+
* than web browser window, as browser PIDs may change on launch.
871+
* Returns `HWND` on Win32, `GtkWindow*` on Linux.
872+
*
873+
* @param window The window number
874+
*
875+
* @return Returns the window handle as `rawptr`
876+
*
877+
* @example hwnd := ui.get_hwnd(myWindow)
878+
*/
879+
@(link_name = "webui_get_hwnd")
880+
get_hwnd :: proc(window: c.size_t) -> rawptr ---
881+
767882
/**
768883
* @brief Get the network port of a running window.
769884
* This can be useful to determine the HTTP link of `webui.js`
@@ -802,6 +917,17 @@ foreign webui {
802917
@(link_name = "webui_get_free_port")
803918
get_free_port :: proc() -> c.size_t ---
804919

920+
/**
921+
* @brief Set a custom logger function.
922+
*
923+
* @param func The logger callback: `proc(level: c.size_t, log: cstring, user_data: rawptr)`
924+
* @param user_data User data pointer passed to the callback
925+
*
926+
* @example ui.set_logger(myLogger, nil)
927+
*/
928+
@(link_name = "webui_set_logger")
929+
set_logger :: proc(func: proc(level: c.size_t, log: cstring, user_data: rawptr), user_data: rawptr) ---
930+
805931
/**
806932
* @brief Control the WebUI behaviour. It's recommended to be called at the beginning.
807933
*
@@ -1140,6 +1266,26 @@ foreign webui {
11401266
@(link_name = "webui_return_bool")
11411267
return_bool :: proc(e: ^Event, b: c.bool) ---
11421268

1269+
/**
1270+
* @brief Get the last WebUI error code.
1271+
*
1272+
* @return Returns the last error number
1273+
*
1274+
* @example err_num: c.size_t = ui.get_last_error_number()
1275+
*/
1276+
@(link_name = "webui_get_last_error_number")
1277+
get_last_error_number :: proc() -> c.size_t ---
1278+
1279+
/**
1280+
* @brief Get the last WebUI error message.
1281+
*
1282+
* @return Returns the last error message string
1283+
*
1284+
* @example err_msg: cstring = ui.get_last_error_message()
1285+
*/
1286+
@(link_name = "webui_get_last_error_message")
1287+
get_last_error_message :: proc() -> cstring ---
1288+
11431289
// == Wrapper's Interface =================================================
11441290

11451291
/**

0 commit comments

Comments
 (0)