mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
ui/app,apps/gophers,apps/hello: accept nil WindowOptions in NewWindow
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=
|
||||
|
||||
@@ -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",
|
||||
|
||||
+1
-5
@@ -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)
|
||||
}
|
||||
|
||||
+8
-1
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user