aarzilli/nucular

How to close Master Window inside update()

Closed this issue · 3 comments

I would like to close master window when the user presses Escape key. How do I achieve this?

var masterWindow MasterWindow

func update(w *nucular.Window) {
  //...
  if w.Input().Keyboard.Pressed(key.CodeEscape) {
    // masterWindow.Close() // hangs!
    // w.Close() // doesn't work too
}
package main

import (
	"github.com/aarzilli/nucular"
	"github.com/aarzilli/nucular/style"
)

func main() {
	wnd := nucular.NewMasterWindow(0, "close", updatefn)
	wnd.SetStyle(style.FromTheme(style.DarkTheme, 2.0))
	wnd.Main()
}

func updatefn(w *nucular.Window) {
	w.Row(50).Dynamic(1)
	if w.ButtonText("GOODBYE") {
		go w.Master().Close()
	}
}

Thank you!

You're welcome.