func htmlContent(content *ui.Container) []ui.Activatable { html := bytes.NewBufferString(` <body> <div class=content> <h1 id=heading>UI EXAMPLE!</h1> <img src=testImage></img> <input type=text placeholder="this is a placeholder"></input> <input type=password></input> <button onclick=clickButton></button> <div> </body> `) css := bytes.NewBufferString(` .content img { width: 200; } .content input { background-color: #fff; margin: 10 0 0 0; } .content button { padding: 20; margin: 10 0 0 0; background-color: #a00; } .content button:hover { background-color: #e99; } `) // create assets htmlAssets := ui.NewHtmlAssets() // image img, _ := assets.ImportImageCached("resources/cubemap.png") htmlAssets.AddImage("testImage", img) // button click callback htmlAssets.AddCallback("clickButton", func(element ui.Element, args ...interface{}) { if len(args) >= 2 && !args[1].(bool) { // on release content.TextElementById("heading").SetText("release").SetTextColor(color.NRGBA{254, 0, 0, 254}).ReRender() } else { content.TextElementById("heading").SetText("press").SetTextColor(color.NRGBA{0, 254, 0, 254}).ReRender() } }) // Render the html/css code to the content container activatables, err := ui.LoadHTML(content, html, css, htmlAssets) if err != nil { fmt.Println("Error loading html: ", err) } return activatables }
func New(assetDir string) *Editor { return &Editor{ assetDir: assetDir, uiAssets: ui.NewHtmlAssets(), rootMapNode: renderer.NewNode(), currentMap: &editorModels.MapModel{ Name: "default", Root: editorModels.NewNodeModel("root"), }, mouseMode: "scale", } }