Created
January 22, 2020 21:51
-
-
Save grantstephens/da5f7f947a4edaec725c6c88fedf8f30 to your computer and use it in GitHub Desktop.
Example of wasm freezing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"gioui.org/app" | |
"gioui.org/io/system" | |
"gioui.org/layout" | |
"gioui.org/unit" | |
"gioui.org/widget/material" | |
"gioui.org/font/gofont" | |
) | |
type scaledConfig struct { | |
Scale float32 | |
} | |
func main() { | |
gofont.Register() | |
go func() { | |
w := app.NewWindow() | |
if err := loop(w); err != nil { | |
log.Fatal(err) | |
} | |
}() | |
app.Main() | |
} | |
func loop(w *app.Window) error { | |
th := material.NewTheme() | |
gtx := layout.NewContext(w.Queue()) | |
for { | |
e := <-w.Events() | |
switch e := e.(type) { | |
case system.DestroyEvent: | |
return e.Err | |
case system.FrameEvent: | |
gtx.Reset(e.Config, e.Size) | |
kitchen(gtx, th) | |
e.Frame(gtx.Ops) | |
} | |
} | |
} | |
var ( | |
list = &layout.List{ | |
Axis: layout.Vertical, | |
} | |
topLabel = "Hello, Gio" | |
) | |
func kitchen(gtx *layout.Context, th *material.Theme) { | |
cl := &http.Client{} | |
response, err := cl.Get("http://localhost:8080/health") | |
if err != nil { | |
log.Fatalf("%w", err) | |
} else { | |
defer response.Body.Close() | |
contents, err := ioutil.ReadAll(response.Body) | |
if err != nil { | |
log.Fatalf("%w", err) | |
} | |
fmt.Printf("This is a test %s\n", string(contents)) | |
} | |
widgets := []func(){ | |
func() { | |
th.H3(topLabel).Layout(gtx) | |
}, | |
} | |
list.Layout(gtx, len(widgets), func(i int) { | |
layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i]) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment