Skip to content

Commit d814235

Browse files
committed
updated comments on bindings, all examples should reflect odin instead of C now
1 parent 60c9b28 commit d814235

File tree

13 files changed

+228
-229
lines changed

13 files changed

+228
-229
lines changed

examples/call_js.odin

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ button {
7171
</html>`
7272

7373

74-
my_function_exit :: proc "c" (e: ^ui.EventType) {
74+
my_function_exit :: proc "c" (e: ^ui.Event) {
7575
context = runtime.default_context()
7676
ui.exit()
7777
}
7878

7979

80-
my_function_count :: proc "c" (e: ^ui.EventType) {
80+
my_function_count :: proc "c" (e: ^ui.Event) {
8181
context = runtime.default_context()
8282

8383
count, err := ui.script(e.window, "return GetCount();")
@@ -107,7 +107,7 @@ main :: proc() {
107107

108108

109109
// Show the HTML UI.
110-
ui.show_browser(w, MY_HTML, cast(uint)ui.Browser.Firefox)
110+
ui.show_browser(w, MY_HTML, .AnyBrowser)
111111

112112
// Wait until all windows get closed.
113113
ui.wait()

examples/call_odin.odin

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ DOC :: `<!DOCTYPE html>
4949
</html>`
5050

5151
// JavaScript: `webui.handleStr('Hello', 'World');`
52-
handle_string :: proc "c" (e: ^ui.EventType) {
52+
handle_string :: proc "c" (e: ^ui.Event) {
5353
context = runtime.default_context()
5454
str1, _ := ui.get_arg(string, e)
5555
str2, _ := ui.get_arg(string, e, 1)
@@ -61,7 +61,7 @@ handle_string :: proc "c" (e: ^ui.EventType) {
6161
}
6262

6363
// JavaScript: `webui.handleInt(123, 456, 789);`
64-
handle_int :: proc "c" (e: ^ui.EventType) {
64+
handle_int :: proc "c" (e: ^ui.Event) {
6565
context = runtime.default_context()
6666
num1, _ := ui.get_arg(int, e)
6767
num2, _ := ui.get_arg(int, e, 1)
@@ -73,7 +73,7 @@ handle_int :: proc "c" (e: ^ui.EventType) {
7373
}
7474

7575
// JavaScript: webui.handleBool(true, false);
76-
handle_bool :: proc "c" (e: ^ui.EventType) {
76+
handle_bool :: proc "c" (e: ^ui.Event) {
7777
context = runtime.default_context()
7878
status1, _ := ui.get_arg(bool, e)
7979
status2, _ := ui.get_arg(bool, e, 1)
@@ -83,7 +83,7 @@ handle_bool :: proc "c" (e: ^ui.EventType) {
8383
}
8484

8585
// JavaScript: webui.handleObj(JSON.stringify({ name: 'Bob', age: 30 }), JSON.stringify({ email: '[email protected]', hash: 'abc' }));
86-
handle_struct :: proc "c" (e: ^ui.EventType) {
86+
handle_struct :: proc "c" (e: ^ui.Event) {
8787
context = runtime.default_context()
8888
Person :: struct {
8989
name: string,
@@ -102,7 +102,7 @@ handle_struct :: proc "c" (e: ^ui.EventType) {
102102
}
103103

104104
// JavaScript: `const result = await webui.getResponse(number);`
105-
get_response :: proc "c" (e: ^ui.EventType) {
105+
get_response :: proc "c" (e: ^ui.Event) {
106106
context = runtime.default_context()
107107
num, _ := ui.get_arg(int, e)
108108

-985 KB
Binary file not shown.

examples/customer_web_server/main.odin

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ import "base:runtime"
88
import "core:c"
99

1010

11-
events :: proc "c" (e: ^ui.EventType) {
11+
events :: proc "c" (e: ^ui.Event) {
1212
context = runtime.default_context()
13-
if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_CONNECTED {
13+
14+
switch e.event_type {
15+
case .Connected:
1416
fmt.printfln("\nConnected. \n")
15-
} else if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_DISCONNECTED {
17+
case .Disconnected:
1618
fmt.printfln("\nDisconnected. \n")
17-
} else if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_CALLBACK {
19+
case .MouseClick:
1820
fmt.printfln("\nClick. \n")
19-
} else if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_NAVIGATION {
21+
case .Navigation:
2022
url: cstring = ui.get_string(e)
21-
fmt.printfln("\nStarting navigation to: %s \n", cast(string)url)
23+
fmt.printfln("\nStarting navigation to: %s \n", string(url))
2224

23-
// Because we used `webui_bind(MyWindow, "", events);`
24-
// WebUI will block all `href` link clicks and sent here instead.
25+
// Because we used `bind(MyWindow, "", events)`
26+
// WebUI will block all `href` link clicks and send here instead.
2527
// We can then control the behaviour of links as needed.
2628
ui.webui_navigate(e.window, url)
29+
case .Callback:
30+
fmt.println("Callback")
2731
}
2832
}
2933

3034

31-
my_backend_func :: proc "c" (e: ^ui.EventType) {
35+
my_backend_func :: proc "c" (e: ^ui.Event) {
3236
context = runtime.default_context()
3337

3438
// JavaScript

examples/public_network_access/main.odin

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@ private_window: c.size_t
1010
public_window: c.size_t
1111

1212

13-
app_exit :: proc "c" (e: ^ui.EventType) {
13+
app_exit :: proc "c" (e: ^ui.Event) {
1414
context = runtime.default_context()
1515
ui.exit()
1616
}
1717

1818

19-
public_window_events :: proc "c" (e: ^ui.EventType) {
19+
public_window_events :: proc "c" (e: ^ui.Event) {
2020
context = runtime.default_context()
21-
if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_CONNECTED {
21+
if e.event_type == ui.EventType.Connected {
2222
// New connection
2323
ui.run(private_window, "document.getElementById(\"Logs\").value += \"New connection.\\n\";")
24-
} else if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_DISCONNECTED {
24+
} else if e.event_type == ui.EventType.Disconnected {
2525
// Disconnection
2626
ui.run(private_window, "document.getElementById(\"Logs\").value += \"Disconnected.\\n\";")
2727
}
28+
2829
}
2930

3031

31-
private_window_events :: proc "c" (e: ^ui.EventType) {
32+
private_window_events :: proc "c" (e: ^ui.Event) {
3233
context = runtime.default_context()
33-
if e.event_type == cast(uint)ui.Event.WEBUI_EVENT_CONNECTED {
34+
if e.event_type == ui.EventType.Connected {
3435
public_win_url: string = string(ui.get_url(public_window))
3536
ui.run(private_window, fmt.aprintf( "document.getElementById('urlSpan').innerHTML = '%s';", public_win_url))
3637
}
@@ -113,7 +114,7 @@ main :: proc() {
113114
// Public Window
114115
ui.set_public(public_window, true) // Make URL accessible from public networks
115116
ui.bind(public_window, "", public_window_events) // Bind all events
116-
ui.show_browser(public_window, PUBLIC_HTML, cast(uint)ui.Browser.NoBrowser) // Set public window HTML
117+
ui.show_browser(public_window, PUBLIC_HTML, .NoBrowser) // Set public window HTML
117118

118119
// Private Window
119120
ui.bind(private_window, "", private_window_events); // Run JS

examples/react/main.odin

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import "base:runtime"
55
import "core:c"
66

77

8-
exit_app :: proc "c" (e: ^ui.EventType) {
8+
exit_app :: proc "c" (e: ^ui.Event) {
99
context = runtime.default_context()
1010
ui.exit()
1111
}
1212

13+
// use the build_react.bat/.sh file to build npm files and create the odin executable in one go.
1314
main :: proc() {
14-
1515
// Create new windows
1616
react_window := ui.new_window()
1717

@@ -29,29 +29,23 @@ main :: proc() {
2929

3030
// VSF (Virtual File System) Example
3131
//
32-
// 1. Run Python script to generate header file of a folder
33-
// python vfs.py "/path/to/folder" "vfs.h"
34-
//
35-
// 2. Include header file in your C project
36-
// #include "vfs.h"
32+
// 1. Make sure to run the `build_virtual_file_system()`
33+
// function and include a string path to the npm files
34+
// build directory.
3735
//
38-
// 3. use vfs in your custom files handler `ui.set_file_handler()`
39-
// ui.set_file_handler(react_window, vfs);
40-
36+
// 2. use vfs in your custom files handler `ui.set_file_handler()`
37+
// ui.set_file_handler(react_window, vfs)
4138
build_virtual_file_system("./webui-react-example/build")
4239

43-
4440
// Set a custom files handler
4541
ui.set_file_handler(react_window, vfs)
4642

4743
// Show the React window
48-
// ui.show_browser(react_window, "index.html", Chrome);
49-
ui.show_browser(react_window, "index.html", cast(uint)ui.Browser.Firefox)
44+
ui.show_browser(react_window, "index.html", .AnyBrowser)
5045

5146
// Wait until all windows get closed
5247
ui.wait()
5348

5449
// Free all memory resources (Optional)
5550
ui.clean()
56-
5751
}

examples/react/react.exe

-1.02 MB
Binary file not shown.

examples/react/webui-react-example/public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<body>
3030
<noscript>You need to enable JavaScript to run this app.</noscript>
3131
<div id="root"></div>
32-
<p>This is some text i wrote here.s</p>
3332
<!--
3433
This HTML file is a template.
3534
If you open it directly in the browser, you will see an empty page.

examples/serve_a_folder/main.odin

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ package main
55
import ui "../../"
66
import "base:runtime"
77
import "core:fmt"
8+
import "core:c"
89

9-
w :: ui.Window(1)
10-
w2 :: ui.Window(2)
10+
w : c.size_t : 1
11+
w2 : c.size_t : 2
1112

1213
// // This function gets called every time there is an event.
1314
events :: proc "c" (e: ^ui.Event) {
1415
context = runtime.default_context()
15-
if e.event_type == .Connected {
16-
fmt.println("Connected.")
17-
} else if e.event_type == .Disconnected {
18-
fmt.println("Disconnected.")
19-
} else if e.event_type == .MouseClick {
20-
fmt.println("Click.")
21-
} else if e.event_type == .Navigation {
22-
target, _ := ui.get_arg(string, e)
23-
fmt.println("Starting navigation to:", target)
24-
ui.navigate(e.window, target)
16+
17+
switch e.event_type {
18+
case .Connected:
19+
fmt.println("Connected.")
20+
case .Disconnected:
21+
fmt.println("Disconnected.")
22+
case .MouseClick:
23+
fmt.println("Click.")
24+
case .Navigation:
25+
target, _ := ui.get_arg(string, e)
26+
fmt.println("Starting navigation to:", target)
27+
ui.navigate(e.window, target)
28+
case .Callback:
29+
fmt.println("Callback")
2530
}
2631
}
2732

examples/text_editor/main.odin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "core:fmt"
88
import "core:c"
99

1010

11-
close_app :: proc "c" (e: ^ui.EventType) {
11+
close_app :: proc "c" (e: ^ui.Event) {
1212
context = runtime.default_context()
1313
fmt.printfln("Exit.")
1414

@@ -28,7 +28,7 @@ main :: proc() {
2828
ui.bind(main_window, "close_app", close_app)
2929

3030
// Show the window, preferably in a chromium based browser
31-
if !ui.show_browser(main_window, "index.html", cast(uint)ui.Browser.AnyBrowser) {
31+
if !ui.show_browser(main_window, "index.html", .AnyBrowser) {
3232
ui.show(main_window, "index.html")
3333
}
3434

0 commit comments

Comments
 (0)