mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
ui/app: (wasm) create and add container div if one is not provided
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+13
-7
@@ -1,7 +1,6 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"image"
|
"image"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
@@ -32,14 +31,11 @@ var mainDone = make(chan struct{})
|
|||||||
|
|
||||||
func createWindow(win *Window, opts *WindowOptions) error {
|
func createWindow(win *Window, opts *WindowOptions) error {
|
||||||
doc := js.Global().Get("document")
|
doc := js.Global().Get("document")
|
||||||
parent := doc.Call("getElementById", "giowindow")
|
cont := getContainer(doc)
|
||||||
if parent == js.Null() {
|
|
||||||
return errors.New("app: #giowindow not found")
|
|
||||||
}
|
|
||||||
cnv := createCanvas(doc)
|
cnv := createCanvas(doc)
|
||||||
parent.Call("appendChild", cnv)
|
cont.Call("appendChild", cnv)
|
||||||
tarea := createTextArea(doc)
|
tarea := createTextArea(doc)
|
||||||
parent.Call("appendChild", tarea)
|
cont.Call("appendChild", tarea)
|
||||||
w := &window{
|
w := &window{
|
||||||
cnv: cnv,
|
cnv: cnv,
|
||||||
tarea: tarea,
|
tarea: tarea,
|
||||||
@@ -64,6 +60,16 @@ func createWindow(win *Window, opts *WindowOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getContainer(doc js.Value) js.Value {
|
||||||
|
cont := doc.Call("getElementById", "giowindow")
|
||||||
|
if cont != js.Null() {
|
||||||
|
return cont
|
||||||
|
}
|
||||||
|
cont = doc.Call("createElement", "DIV")
|
||||||
|
doc.Get("body").Call("appendChild", cont)
|
||||||
|
return cont
|
||||||
|
}
|
||||||
|
|
||||||
func createTextArea(doc js.Value) js.Value {
|
func createTextArea(doc js.Value) js.Value {
|
||||||
tarea := doc.Call("createElement", "input")
|
tarea := doc.Call("createElement", "input")
|
||||||
style := tarea.Get("style")
|
style := tarea.Get("style")
|
||||||
|
|||||||
Reference in New Issue
Block a user