This repository has been archived on 2024-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
burgernotes-app/webkit-4.1/examples/bind/main.go

39 lines
926 B
Go
Raw Normal View History

2024-04-25 17:58:39 +01:00
package main
import webview "github.com/webview/webview_go"
const html = `<button id="increment">Tap me</button>
<div>You tapped <span id="count">0</span> time(s).</div>
<script>
const [incrementElement, countElement] =
document.querySelectorAll("#increment, #count");
document.addEventListener("DOMContentLoaded", () => {
incrementElement.addEventListener("click", () => {
window.increment().then(result => {
countElement.textContent = result.count;
});
});
});
</script>`
type IncrementResult struct {
Count uint `json:"count"`
}
func main() {
var count uint = 0
w := webview.New(false)
defer w.Destroy()
w.SetTitle("Bind Example")
w.SetSize(480, 320, webview.HintNone)
// A binding that increments a value and immediately returns the new value.
w.Bind("increment", func() IncrementResult {
count++
return IncrementResult{Count: count}
})
w.SetHtml(html)
w.Run()
}