Skip to content

Commit

Permalink
add missing procs + configs
Browse files Browse the repository at this point in the history
  • Loading branch information
neroist committed Jun 26, 2024
1 parent 6d16aae commit 5168b95
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
39 changes: 38 additions & 1 deletion webui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ proc browserExist*(browser: bindings.Browser): bool =

bindings.browserExist(browser)

proc setConfig*(option: bindings.WebuiConfigs; status: bool) =
## Control WebUI's behaviour via setting configuration option `option` to either
## `true` or `false`. It's better to this call at the beginning of your program.
##
## :option: The desired option from the `WebuiConfig` enum
## :status: The status of the option, `true` or `false`

bindings.setConfig(option, status)

# ------- Impl funcs --------

# --- Event ---
Expand Down Expand Up @@ -440,7 +449,7 @@ proc `hidden=`*(window: Window; status: bool) =

bindings.setHide(csize_t window, status)

proc `highContrast`*(window: Window; status: bool) =
proc `highContrast=`*(window: Window; status: bool) =
## Setup the window with high-contrast support. Useful when you want to
## build a better high-contrast theme with CSS.
##
Expand All @@ -449,6 +458,25 @@ proc `highContrast`*(window: Window; status: bool) =

bindings.setHighContrast(csize_t window, status)

proc `eventBlocking=`*(window: Window; status: bool) =
## Control if UI events comming from this window should be processed
## one a time in a single blocking thread (`true`), or process every event in
## a new non-blocking thread (`false`). This function only affects a single window
## You may use `setConfig(wcUiEventBlocking, ...)` to update all windows.
##
## :window: The window to configure event blocking for.
## :status: Whether or not to process window events blockingly *(single vs multi-threaded)*.

bindings.setEventBlocking(csize_t window, status)

proc `proxy=`*(window: Window, proxyServer: string) =
## Set the web browser to use `proxyServer`. Must be called before `show()`.
##
## :window: The window to set the proxy server for
## :proxyServer: The proxy server to use

bindings.setProxy(csize_t window, cstring proxyServer)

proc setSize*(window: Window; width, height: int) =
## Set the window size.
##
Expand Down Expand Up @@ -582,6 +610,14 @@ proc `bind`*(window: Window; element: string; `func`: proc (e: Event): int) =
e.returnInt(res)
)

proc `bind`*(window: Window; element: string; `func`: proc (e: Event): float) =
window.bind(
element,
proc (e: Event) =
let res = `func`(e)
e.returnFloat(res)
)

proc `bind`*(window: Window; element: string; `func`: proc (e: Event): bool) =
## Bind `func` to element `element` and automatically pass return value of `func` to Javascript.
##
Expand Down Expand Up @@ -689,5 +725,6 @@ export
bindings.Events,
bindings.Browser,
bindings.Runtime,
bindings.WebuiConfigs,
bindings.WEBUI_VERSION,
bindings.WEBUI_MAX_IDS
32 changes: 25 additions & 7 deletions webui/bindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,19 @@ type
wcShowWaitConnection
## Control if `show()` and `showX()` (e.g. `showBrowser()` & `showWv`) should wait
## for the window to connect before returns or not.
##
## Default: `true`
wcUiEventBlocking
## Control if WebUI should block and process the UI events one a time in a single
## thread (`true`), or process every event in a new non-blocking thread (`false`).
## This updates all windows. You can use `setEventBlocking()` for a specific single
## window update.
##
## Default: `false`
wcFolderMonitor
## Automatically refresh the window UI when any file in the root folder changes
##
## Default: `false`

Event* {.bycopy.} = object
window*: csize_t ## The window object number
Expand Down Expand Up @@ -201,7 +213,7 @@ proc showWv*(window: csize_t; content: cstring): bool {.webui, importc: "webui_s
## Show a WebView window using embedded HTML, or a file. If the window is already
## open, it will be refreshed.
##
## .. note:: Windows needs `WebView2Loader.dll`.
## .. note:: Windows needs `WebView2Loader.dll`.

proc setKiosk*(window: csize_t; status: bool) {.webui, importc: "webui_set_kiosk".}
## Set the window in Kiosk mode (Full screen)
Expand Down Expand Up @@ -249,11 +261,11 @@ proc setIcon*(window: csize_t; icon: cstring; `type`: cstring) {.webui, importc:

proc encode*(str: cstring): cstring {.webui, importc: "webui_encode".}
## Base64 encoding. Use this to safely send text based data to the UI.
## If it fails it will return `nil`.
## If it fails it will return `nil`. The returned buffer must be freed.

proc decode*(str: cstring): cstring {.webui, importc: "webui_decode".}
## Base64 decoding. Use this to safely decode received Base64 text from the UI.
## If it fails it will return `nil`.
## If it fails it will return `nil`. The returned buffer must be freed.

proc free*(`ptr`: pointer) {.webui, importc: "webui_free".}
## Safely free a buffer allocated by WebUI using `malloc()`.
Expand Down Expand Up @@ -282,7 +294,7 @@ proc setProxy*(window: csize_t; proxy_server: cstring) {.webui, importc: "webui_
## Set the web browser to use `proxy_server`. Must be called before `show()`.

proc getUrl*(window: csize_t): cstring {.webui, importc: "webui_get_url".}
## Get the full current URL.
## Get current URL of a running window.

proc setPublic*(window: csize_t; status: bool) {.webui, importc: "webui_set_public".}
## Allow a specific window address to be accessible from a public network
Expand Down Expand Up @@ -311,9 +323,15 @@ proc setPort*(window: csize_t; port: csize_t): bool {.webui, importc: "webui_set
## This can be useful to determine the HTTP link of `webui.js` in case
## you are trying to use WebUI with an external web-server like NGNIX

proc config*(option: WebuiConfigs; status: bool) {.webui, importc: "webui_config".}
proc setConfig*(option: WebuiConfigs; status: bool) {.webui, importc: "webui_set_config".}
## Control WebUI's behaviour. It's better to this call at the beginning.

proc setEventBlocking*(window: csize_t; status: bool) {.webui, importc: "webui_set_event_blocking".}
## Control if UI events comming from this window should be processed
## one a time in a single blocking thread (`true`), or process every event in
## a new non-blocking thread (`false`). This function only updates a single window
## You can use `setConfig(wcUiEventBlocking, ...)` to update all windows.

# -- SSL/TLS -------------------------

proc setTlsCertificate*(certificate_pem: cstring; private_key_pem: cstring): bool {.webui,
Expand Down Expand Up @@ -387,14 +405,14 @@ proc interfaceBind*(window: csize_t; element: cstring; `func`: proc (window: csi
importc: "webui_interface_bind".}
## Bind a specific HTML element click event with a function. Empty element means all events.
##
## :func: The callback as myFunc(Window, EventType, Element, EventNumber, BindID)
## :func: The callback as `myFunc(Window, EventType, Element, EventNumber, BindID)`

proc interfaceSetResponse*(window: csize_t; event_number: csize_t; repsonse: cstring) {.webui,
importc: "webui_interface_set_response".}
## When using `interfaceBind()`, you may need this function to easily set a response.

proc interfaceIsAppRunning*(): bool {.webui, importc: "webui_interface_is_app_running".}
## Check if the app still running or not. This replace `wait()`.
## Check if the app still running or not. This replaces `wait()`.

proc interfaceGetWindowId*(window: csize_t): csize_t {.webui, importc: "webui_interface_get_window_id".}
## Get a unique window ID.
Expand Down

0 comments on commit 5168b95

Please sign in to comment.