app/internal/window: [macOS] simplify NewWindow

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-07 14:48:54 +02:00
parent 78565c9232
commit 65078cdece
+8 -11
View File
@@ -292,26 +292,23 @@ func gio_onFinishLaunching() {
func NewWindow(win Callbacks, opts *Options) error { func NewWindow(win Callbacks, opts *Options) error {
<-launched <-launched
errch := make(chan error) errch := make(chan error)
var window *window
runOnMain(func() { runOnMain(func() {
w, err := newWindow(win, opts) w, err := newWindow(win, opts)
window = w if err != nil {
errch <- err errch <- err
}) return
if err := <-errch; err != nil { }
return err
}
runOnMain(func() {
// Window sizes is in unscaled screen coordinates, not device pixels. // Window sizes is in unscaled screen coordinates, not device pixels.
cfg := configFor(1.0) cfg := configFor(1.0)
width := cfg.Px(opts.Width) width := cfg.Px(opts.Width)
height := cfg.Px(opts.Height) height := cfg.Px(opts.Height)
title := C.CString(opts.Title) title := C.CString(opts.Title)
defer C.free(unsafe.Pointer(title)) defer C.free(unsafe.Pointer(title))
nextTopLeft = C.gio_createWindow(window.view, title, C.CGFloat(width), C.CGFloat(height), nextTopLeft) errch <- nil
win.SetDriver(window) nextTopLeft = C.gio_createWindow(w.view, title, C.CGFloat(width), C.CGFloat(height), nextTopLeft)
win.SetDriver(w)
}) })
return nil return <-errch
} }
func newWindow(win Callbacks, opts *Options) (*window, error) { func newWindow(win Callbacks, opts *Options) (*window, error) {