Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/neroist/webui
Browse files Browse the repository at this point in the history
  • Loading branch information
neroist committed Dec 30, 2023
2 parents 339803b + 730dfa3 commit c796201
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 24 deletions.
37 changes: 37 additions & 0 deletions webui.nim
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,43 @@ proc `kiosk=`*(window: Window; status: bool) =

bindings.setKiosk(csize_t window, status)

proc `runtime=`*(window: Window; runtime: bindings.Runtime) =
## Chose a runtime for .js and .ts files.
##
## :window: The window to set the runtime for.
## :runtime: The runtime to set.

bindings.setRuntime(csize_t window, csize_t ord(runtime))

proc `rootFolder=`*(window: Window; path: string): bool {.discardable.} =
## Set the web-server root folder path.
##
## :window: The window to set the root folder for.
## :path: The path to the root folder.

bindings.setRootFolder(csize_t window, cstring path)

proc `hidden=`*(window: Window; status: bool) =
## Run the window in hidden mode
##
## :window: The window to hide or show.
## :status: Whether or not to hide the window. `true` to hide, `false`
## to show.

bindings.setHide(csize_t window, status)

proc `size=`*(window: Window; size: tuple[width, height: int]) =
bindings.setSize(csize_t window, cuint size.width, cuint size.height)

proc `pos=`*(window: Window; pos: tuple[x, y: int]) =
bindings.setPosition(csize_t window, cuint pos.x, cuint pos.y)

proc setSize*(window: Window; width, height: int) =
bindings.setSize(csize_t window, cuint width, cuint height)

proc setPos*(window: Window; x, y: int) =
bindings.setPosition(csize_t window, cuint x, cuint y)

proc close*(window: Window) =
## Close a specific window only. The window object will still exist.
##
Expand Down
73 changes: 50 additions & 23 deletions webui/bindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ type
Events* = enum
EventsDisconnected ## 0. Window disconnection event
EventsConnected ## 1. Window connection event
EventsMultiConnection ## 2. New window connection event
EventsUnwantedConnection ## 3. New unwanted window connection event
EventsMouseClick ## 4. Mouse click event
EventsNavigation ## 5. Window navigation event
EventsCallback ## 6. Function call event
EventsMouseClick ## 2. Mouse click event
EventsNavigation ## 3. Window navigation event
EventsCallback ## 4. Function call event

Event* {.bycopy.} = object
window*: csize_t ## The window object number
eventType*: csize_t ## Event type
element*: cstring ## HTML element ID
eventNumber*: csize_t ## Internal WebUI
bindId*: csize_t ## Bind ID

Runtime* {.pure.} = enum
None ## 0. Prevent WebUI from using any runtime for .js and .ts files
Deno ## 1. Use Deno runtime for .js and .ts files
NodeJS ## 2. Use Nodejs runtime for .js files

# -- Definitions ---------------------

Expand Down Expand Up @@ -178,7 +180,41 @@ proc setTimeout*(second: csize_t) {.cdecl, importc: "webui_set_timeout".}

proc setIcon*(window: csize_t; icon: cstring; `type`: cstring) {.cdecl,
importc: "webui_set_icon".}
## Set the default embedded HTML favicon.
## Set the default embedded HTML favicon

proc setMultiAccess*(window: csize_t; status: bool) {.cdecl,
importc: "webui_set_multi_access".}
## Allow the window URL to be re-used in normal web browsers

# -- JavaScript ----------------------
proc run*(window: csize_t; script: cstring) {.cdecl, importc: "webui_run".}
## Run JavaScript quickly without waiting for the response.

proc script*(window: csize_t; script: cstring; timeout: csize_t; buffer: cstring;
bufferLength: csize_t): bool {.cdecl, importc: "webui_script".}
## Run a JavaScript, and get the response back (Make sure your local buffer can hold the response).

proc setRuntime*(window: csize_t; runtime: csize_t) {.cdecl,
importc: "webui_set_runtime".}
## Chose between Deno and Nodejs runtime for .js and .ts files.

proc getInt*(e: ptr Event): clonglong {.cdecl, importc: "webui_get_int".}
## Parse argument as integer.

proc getString*(e: ptr Event): cstring {.cdecl, importc: "webui_get_string".}
## Parse argument as string.

proc getBool*(e: ptr Event): bool {.cdecl, importc: "webui_get_bool".}
## Parse argument as boolean.

proc returnInt*(e: ptr Event; n: clonglong) {.cdecl, importc: "webui_return_int".}
## Return the response to JavaScript as integer.

proc returnString*(e: ptr Event; s: cstring) {.cdecl, importc: "webui_return_string".}
## Return the response to JavaScript as string.

proc returnBool*(e: ptr Event; b: bool) {.cdecl, importc: "webui_return_bool".}
## Return the response to JavaScript as boolean.

proc encode*(str: cstring): cstring {.cdecl, importc: "webui_encode".}
## Base64 encoding. Use this to safely send text based data to the UI.
Expand Down Expand Up @@ -298,11 +334,9 @@ proc returnBool*(e: ptr Event; b: bool) {.cdecl, importc: "webui_return_bool".}

# -- Interface -----------------------
proc interfaceBind*(window: csize_t; element: cstring; `func`: proc (a1: csize_t;
a2: csize_t; a3: cstring; a5: csize_t; a6: csize_t) {.cdecl.}): csize_t {.cdecl,
a2: csize_t; a3: cstring; a4: cstring; a5: csize_t; a6: csize_t) {.cdecl.}): csize_t {.cdecl,
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)
## Bind a specific html element click event with a function. Empty element means all events. This replace webui_bind(). The func is (Window, EventType, Element, Data, Response)

proc interfaceSetResponse*(window: csize_t, event_number: csize_t, repsonse: cstring) {.cdecl,
importc: "webui_interface_set_response".}
Expand All @@ -314,16 +348,9 @@ proc interfaceIsAppRunning*(): bool {.cdecl,

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

proc interfaceGetIntAt*(window: csize_t, event_number: csize_t, index: csize_t): clonglong {.cdecl, importc: "webui_interface_get_int_at".}
## Get an argument as integer at a specific index

proc interfaceGetStringAt*(window: csize_t, event_number: csize_t, index: csize_t): cstring {.cdecl, importc: "webui_interface_get_string_at".}
## Get an argument as string at a specific index

proc interfaceGetBoolAt*(window: csize_t, event_number: csize_t, index: csize_t): bool {.cdecl, importc: "webui_interface_get_bool_at".}
## Get an argument as boolean at a specific index

proc interfaceGetSizeAt*(window: csize_t, event_number: csize_t, index: csize_t): csize_t {.cdecl, importc: "webui_interface_get_bool_at".}
## Get the size in bytes of an argument at a specific index
# THANK YOU
proc interfaceGetBindId*(window: csize_t; element: cstring): csize_t {.cdecl,
importc: "webui_interface_get_bind_id".}
## Get a unique ID. Same ID as `webui_bind()`. Return > 0 if bind exist.
2 changes: 1 addition & 1 deletion webui/webui
Submodule webui updated 66 files
+14 −0 .clang-format
+8 −0 .editorconfig
+3 −0 .github/workflows/ci.yml
+25 −0 .github/workflows/lint.yml
+4 −4 .github/workflows/linux.yml
+12 −2 .github/workflows/macos.yml
+2 −2 .github/workflows/windows.yml
+5 −0 .pre-commit-config.yaml
+2 −0 .prettierignore
+5 −0 .prettierrc
+146 −0 GNUmakefile
+57 −130 Makefile
+0 −73 Makefile.nmake
+39 −35 README.md
+1 −2 bridge/README.md
+1 −1 bridge/build.ps1
+11 −13 bridge/utils.ts
+946 −1,870 bridge/webui_bridge.h
+372 −513 bridge/webui_bridge.ts
+1 −1 examples/C++/README.md
+120 −0 examples/C++/call_cpp_from_js/GNUmakefile
+42 −107 examples/C++/call_cpp_from_js/Makefile
+0 −55 examples/C++/call_cpp_from_js/Makefile.nmake
+53 −54 examples/C++/call_cpp_from_js/main.cpp
+120 −0 examples/C++/call_js_from_cpp/GNUmakefile
+42 −107 examples/C++/call_js_from_cpp/Makefile
+0 −55 examples/C++/call_js_from_cpp/Makefile.nmake
+51 −42 examples/C++/call_js_from_cpp/main.cpp
+120 −0 examples/C++/minimal/GNUmakefile
+42 −107 examples/C++/minimal/Makefile
+0 −55 examples/C++/minimal/Makefile.nmake
+9 −13 examples/C++/minimal/main.cpp
+120 −0 examples/C++/serve_a_folder/GNUmakefile
+42 −107 examples/C++/serve_a_folder/Makefile
+0 −55 examples/C++/serve_a_folder/Makefile.nmake
+36 −37 examples/C++/serve_a_folder/index.html
+71 −76 examples/C++/serve_a_folder/main.cpp
+23 −23 examples/C++/serve_a_folder/second.html
+1 −1 examples/C/README.md
+120 −0 examples/C/call_c_from_js/GNUmakefile
+42 −107 examples/C/call_c_from_js/Makefile
+0 −55 examples/C/call_c_from_js/Makefile.nmake
+141 −111 examples/C/call_c_from_js/main.c
+120 −0 examples/C/call_js_from_c/GNUmakefile
+42 −107 examples/C/call_js_from_c/Makefile
+0 −55 examples/C/call_js_from_c/Makefile.nmake
+100 −88 examples/C/call_js_from_c/main.c
+120 −0 examples/C/minimal/GNUmakefile
+42 −107 examples/C/minimal/Makefile
+0 −55 examples/C/minimal/Makefile.nmake
+5 −7 examples/C/minimal/main.c
+120 −0 examples/C/serve_a_folder/GNUmakefile
+42 −107 examples/C/serve_a_folder/Makefile
+0 −55 examples/C/serve_a_folder/Makefile.nmake
+7 −7 examples/C/serve_a_folder/deno_test.ts
+101 −68 examples/C/serve_a_folder/index.html
+97 −99 examples/C/serve_a_folder/main.c
+45 −23 examples/C/serve_a_folder/second.html
+0 −0 examples/C/text-editor/GNUmakefile
+18 −20 examples/C/text-editor/text-editor.c
+66 −56 examples/C/text-editor/ui/css/style.css
+37 −37 examples/C/text-editor/ui/index.html
+82 −86 examples/C/text-editor/ui/js/ui.js
+195 −171 include/webui.h
+222 −304 include/webui.hpp
+5,675 −5,118 src/webui.c

0 comments on commit c796201

Please sign in to comment.