I want to build an application using Go with a GUI baked in. A workable solution for that seems to be webview.
What I have now is this (and it works!):
package main
import (
"github.com/webview/webview"
)
var count int = 0
func main() {
w := webview.New(true)
defer w.Destroy()
w.SetSize(600, 200, webview.HintNone)
w.Bind("btn", func() int {
count++
return count
})
//Create UI with data URI
w.Navigate(`data:text/html,
<!doctype html>
<html>
...
</html>`)
w.Run()
}
What I would like to do is to build the gui in a seperate workspace so that I have working syntax hilighting, intellisense etc. so something like:
w.Navigate("./GUI/gui.html")
However, I can't get it to work. is it possible anyway?
file:///
Using the full path to the file.
w.Navigate("file:////Users/myuser/tempgo/hi.html")
Use ioutil.ReadFile
to read in the data from an HTML file. This can then be converted to a string.
file, _ := ioutil.ReadFile("hi.html")
stringFile := string(file)
w.Navigate(`data:text/html,` + stringFile)
Original code from the question.
package main
import (
"github.com/webview/webview"
"io/ioutil"
)
var count int = 0
func main() {
w := webview.New(true)
defer w.Destroy()
w.SetSize(600, 200, webview.HintNone)
w.Bind("btn", func() int {
count++
return count
})
file, _ := ioutil.ReadFile("hi.html")
stringFile := string(file)
//Create UI with data URI
w.Navigate(`data:text/html,` + stringFile)
w.Run()
}
Directory structure:
main.go
hi.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With