From 1d67fad0c3785fc9327e8b6c878fb3478f0af138 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 31 Mar 2019 13:55:05 +0200 Subject: [PATCH] ui/app,apps/gophers,apps/hello: accept nil WindowOptions in NewWindow Signed-off-by: Elias Naur --- apps/go.mod | 2 -- apps/go.sum | 2 ++ apps/gophers/main.go | 2 +- apps/hello/hello.go | 6 +----- ui/app/app.go | 9 ++++++++- ui/app/os_android.go | 4 ++-- ui/app/os_ios.go | 2 +- ui/app/os_macos.go | 4 ++-- ui/app/os_wayland.go | 4 ++-- ui/app/os_windows.go | 4 ++-- 10 files changed, 21 insertions(+), 18 deletions(-) diff --git a/apps/go.mod b/apps/go.mod index dad10aa3..ff90edba 100644 --- a/apps/go.mod +++ b/apps/go.mod @@ -2,8 +2,6 @@ module gioui.org/apps go 1.12 -replace gioui.org/ui => ../ui - require ( gioui.org/ui v0.0.0-20190331090026-ca5204fcb8b3 github.com/google/go-github/v24 v24.0.1 diff --git a/apps/go.sum b/apps/go.sum index 10eb2054..a645078a 100644 --- a/apps/go.sum +++ b/apps/go.sum @@ -1,4 +1,6 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +gioui.org/ui v0.0.0-20190331090026-ca5204fcb8b3 h1:+iSMCchOrM75QcNH8czjwCXVbwYLofiPeKHl/8Nxxck= +gioui.org/ui v0.0.0-20190331090026-ca5204fcb8b3/go.mod h1:FBjAd/bO8PFxAPY49SiMXkF7Mj677k+KYut4glYlhnM= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/apps/gophers/main.go b/apps/gophers/main.go index f98ce211..1820a956 100644 --- a/apps/gophers/main.go +++ b/apps/gophers/main.go @@ -139,7 +139,7 @@ func init() { fonts.italic = mustLoadFont(goitalic.TTF) fonts.mono = mustLoadFont(gomono.TTF) go func() { - w, err := app.NewWindow(app.WindowOptions{ + w, err := app.NewWindow(&app.WindowOptions{ Width: ui.Dp(400), Height: ui.Dp(800), Title: "Gophers", diff --git a/apps/hello/hello.go b/apps/hello/hello.go index 0d5cf473..faffb3e6 100644 --- a/apps/hello/hello.go +++ b/apps/hello/hello.go @@ -30,11 +30,7 @@ func init() { black := &image.Uniform{color.Black} face := faces.For(regular, ui.Dp(50)) go func() { - w, err := app.NewWindow(app.WindowOptions{ - Width: ui.Dp(400), - Height: ui.Dp(800), - Title: "Hello World", - }) + w, err := app.NewWindow(nil) if err != nil { log.Fatal(err) } diff --git a/ui/app/app.go b/ui/app/app.go index 35d2f387..73ec9c57 100644 --- a/ui/app/app.go +++ b/ui/app/app.go @@ -64,7 +64,14 @@ var extraArgs string // ignore or adjust them. // If the current program is running on iOS and Android, // NewWindow the window previously created by the platform. -func NewWindow(opts WindowOptions) (*Window, error) { +func NewWindow(opts *WindowOptions) (*Window, error) { + if opts == nil { + opts = &WindowOptions{ + Width: ui.Dp(800), + Height: ui.Dp(600), + Title: "Gio program", + } + } if opts.Width.V <= 0 || opts.Height.V <= 0 { panic("window width and height must be larger than 0") } diff --git a/ui/app/os_android.go b/ui/app/os_android.go index 0a391a67..c8640921 100644 --- a/ui/app/os_android.go +++ b/ui/app/os_android.go @@ -381,6 +381,6 @@ func Main() { panic("unreachable") } -func createWindow(opts WindowOptions) (*Window, error) { - return <- windows, nil +func createWindow(opts *WindowOptions) (*Window, error) { + return <-windows, nil } diff --git a/ui/app/os_ios.go b/ui/app/os_ios.go index 4d241829..7f4010f0 100644 --- a/ui/app/os_ios.go +++ b/ui/app/os_ios.go @@ -235,7 +235,7 @@ func (w *window) setTextInput(s key.TextInputState) { } } -func createWindow(opts WindowOptions) (*Window, error) { +func createWindow(opts *WindowOptions) (*Window, error) { return <-windows, nil } diff --git a/ui/app/os_macos.go b/ui/app/os_macos.go index e4eb58aa..b07e5e90 100644 --- a/ui/app/os_macos.go +++ b/ui/app/os_macos.go @@ -40,7 +40,7 @@ type windowError struct { err error } -var windowOpts = make(chan WindowOptions) +var windowOpts = make(chan *WindowOptions) var windows = make(chan windowError) @@ -188,7 +188,7 @@ func gio_onCreate(view C.CFTypeRef) { windows <- windowError{window: ow} } -func createWindow(opts WindowOptions) (*Window, error) { +func createWindow(opts *WindowOptions) (*Window, error) { windowOpts <- opts werr := <-windows return werr.window, werr.err diff --git a/ui/app/os_wayland.go b/ui/app/os_wayland.go index ef70db8d..54e400ec 100644 --- a/ui/app/os_wayland.go +++ b/ui/app/os_wayland.go @@ -141,7 +141,7 @@ func Main() { <-mainDone } -func createWindow(opts WindowOptions) (*Window, error) { +func createWindow(opts *WindowOptions) (*Window, error) { connMu.Lock() defer connMu.Unlock() if len(winMap) > 0 { @@ -165,7 +165,7 @@ func createWindow(opts WindowOptions) (*Window, error) { return w.w, nil } -func createNativeWindow(opts WindowOptions) (*window, error) { +func createNativeWindow(opts *WindowOptions) (*window, error) { pipe := make([]int, 2) if err := syscall.Pipe2(pipe, syscall.O_NONBLOCK|syscall.O_CLOEXEC); err != nil { return nil, fmt.Errorf("createNativeWindow: failed to create pipe: %v", err) diff --git a/ui/app/os_windows.go b/ui/app/os_windows.go index 88fea26f..651d11a7 100644 --- a/ui/app/os_windows.go +++ b/ui/app/os_windows.go @@ -157,7 +157,7 @@ func Main() { <-mainDone } -func createWindow(opts WindowOptions) (*Window, error) { +func createWindow(opts *WindowOptions) (*Window, error) { onceMu.Lock() defer onceMu.Unlock() if len(winMap) > 0 { @@ -190,7 +190,7 @@ func createWindow(opts WindowOptions) (*Window, error) { return werr.window, werr.err } -func createNativeWindow(opts WindowOptions) (*window, error) { +func createNativeWindow(opts *WindowOptions) (*window, error) { setProcessDPIAware() screenDC, err := getDC(0) if err != nil {