Skip to content

Commit

Permalink
examples: update bind procs to updated calling convention
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed May 31, 2024
1 parent 692bc8b commit bf44aa3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions examples/call_odin.odin
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import ui "../"
import "base:runtime"
import "core:fmt"

DOC :: `<!DOCTYPE html>
Expand Down Expand Up @@ -46,7 +47,8 @@ DOC :: `<!DOCTYPE html>
</html>`

// JavaScript: `webui.handleStr('Hello', 'World');`
handle_string :: proc(e: ^ui.Event) {
handle_string :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
str1 := ui.get_arg(string, e)
str2 := ui.get_arg(string, e, 1)

Expand All @@ -55,7 +57,8 @@ handle_string :: proc(e: ^ui.Event) {
}

// JavaScript: `webui.handleInt(123, 456, 789);`
handle_int :: proc(e: ^ui.Event) {
handle_int :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
num1 := ui.get_arg(int, e)
num2 := ui.get_arg(int, e, 1)
num3 := ui.get_arg(int, e, 2)
Expand All @@ -66,7 +69,8 @@ handle_int :: proc(e: ^ui.Event) {
}

// JavaScript: webui.handleBool(true, false);
handle_bool :: proc(e: ^ui.Event) {
handle_bool :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
status1 := ui.get_arg(bool, e)
status2 := ui.get_arg(bool, e, 1)

Expand All @@ -75,7 +79,8 @@ handle_bool :: proc(e: ^ui.Event) {
}

// JavaScript: `const result = await webui.getResponse(number);`
get_response :: proc(e: ^ui.Event) {
get_response :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
num := ui.get_arg(int, e)

resp := num * 2
Expand Down
13 changes: 9 additions & 4 deletions examples/serve_a_folder/main.odin
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
package main

import ui "../../"
import "base:runtime"
import "core:fmt"

w :: ui.Window(1)
w2 :: ui.Window(2)

// // This function gets called every time there is an event.
events :: proc(e: ^ui.Event) {
events :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
if e.event_type == .Connected {
fmt.println("Connected.")
} else if e.event_type == .Disconnected {
Expand All @@ -24,17 +26,20 @@ events :: proc(e: ^ui.Event) {
}

// Switch to `/second.html` in the same opened window.
switch_to_second_page :: proc(e: ^ui.Event) {
switch_to_second_page :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
ui.show(e.window, "second.html")
}

show_second_window :: proc(e: ^ui.Event) {
show_second_window :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
ui.show(w2, "second.html", await = true)
// Remove the Go Back button when showing the second page in another window.
ui.run(w2, "document.getElementById('go-back').remove();")
}

close_window :: proc(e: ^ui.Event) {
close_window :: proc "c" (e: ^ui.Event) {
context = runtime.default_context()
ui.close(e.window)
}

Expand Down

0 comments on commit bf44aa3

Please sign in to comment.