mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +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
|
go 1.12
|
||||||
|
|
||||||
replace gioui.org/ui => ../ui
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org/ui v0.0.0-20190331090026-ca5204fcb8b3
|
gioui.org/ui v0.0.0-20190331090026-ca5204fcb8b3
|
||||||
github.com/google/go-github/v24 v24.0.1
|
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=
|
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/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 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
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.italic = mustLoadFont(goitalic.TTF)
|
||||||
fonts.mono = mustLoadFont(gomono.TTF)
|
fonts.mono = mustLoadFont(gomono.TTF)
|
||||||
go func() {
|
go func() {
|
||||||
w, err := app.NewWindow(app.WindowOptions{
|
w, err := app.NewWindow(&app.WindowOptions{
|
||||||
Width: ui.Dp(400),
|
Width: ui.Dp(400),
|
||||||
Height: ui.Dp(800),
|
Height: ui.Dp(800),
|
||||||
Title: "Gophers",
|
Title: "Gophers",
|
||||||
|
|||||||
+1
-5
@@ -30,11 +30,7 @@ func init() {
|
|||||||
black := &image.Uniform{color.Black}
|
black := &image.Uniform{color.Black}
|
||||||
face := faces.For(regular, ui.Dp(50))
|
face := faces.For(regular, ui.Dp(50))
|
||||||
go func() {
|
go func() {
|
||||||
w, err := app.NewWindow(app.WindowOptions{
|
w, err := app.NewWindow(nil)
|
||||||
Width: ui.Dp(400),
|
|
||||||
Height: ui.Dp(800),
|
|
||||||
Title: "Hello World",
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -64,7 +64,14 @@ var extraArgs string
|
|||||||
// ignore or adjust them.
|
// ignore or adjust them.
|
||||||
// If the current program is running on iOS and Android,
|
// If the current program is running on iOS and Android,
|
||||||
// NewWindow the window previously created by the platform.
|
// 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 {
|
if opts.Width.V <= 0 || opts.Height.V <= 0 {
|
||||||
panic("window width and height must be larger than 0")
|
panic("window width and height must be larger than 0")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,6 +381,6 @@ func Main() {
|
|||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWindow(opts WindowOptions) (*Window, error) {
|
func createWindow(opts *WindowOptions) (*Window, error) {
|
||||||
return <- windows, nil
|
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
|
return <-windows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -40,7 +40,7 @@ type windowError struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
var windowOpts = make(chan WindowOptions)
|
var windowOpts = make(chan *WindowOptions)
|
||||||
|
|
||||||
var windows = make(chan windowError)
|
var windows = make(chan windowError)
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ func gio_onCreate(view C.CFTypeRef) {
|
|||||||
windows <- windowError{window: ow}
|
windows <- windowError{window: ow}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWindow(opts WindowOptions) (*Window, error) {
|
func createWindow(opts *WindowOptions) (*Window, error) {
|
||||||
windowOpts <- opts
|
windowOpts <- opts
|
||||||
werr := <-windows
|
werr := <-windows
|
||||||
return werr.window, werr.err
|
return werr.window, werr.err
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func Main() {
|
|||||||
<-mainDone
|
<-mainDone
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWindow(opts WindowOptions) (*Window, error) {
|
func createWindow(opts *WindowOptions) (*Window, error) {
|
||||||
connMu.Lock()
|
connMu.Lock()
|
||||||
defer connMu.Unlock()
|
defer connMu.Unlock()
|
||||||
if len(winMap) > 0 {
|
if len(winMap) > 0 {
|
||||||
@@ -165,7 +165,7 @@ func createWindow(opts WindowOptions) (*Window, error) {
|
|||||||
return w.w, nil
|
return w.w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNativeWindow(opts WindowOptions) (*window, error) {
|
func createNativeWindow(opts *WindowOptions) (*window, error) {
|
||||||
pipe := make([]int, 2)
|
pipe := make([]int, 2)
|
||||||
if err := syscall.Pipe2(pipe, syscall.O_NONBLOCK|syscall.O_CLOEXEC); err != nil {
|
if err := syscall.Pipe2(pipe, syscall.O_NONBLOCK|syscall.O_CLOEXEC); err != nil {
|
||||||
return nil, fmt.Errorf("createNativeWindow: failed to create pipe: %v", err)
|
return nil, fmt.Errorf("createNativeWindow: failed to create pipe: %v", err)
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func Main() {
|
|||||||
<-mainDone
|
<-mainDone
|
||||||
}
|
}
|
||||||
|
|
||||||
func createWindow(opts WindowOptions) (*Window, error) {
|
func createWindow(opts *WindowOptions) (*Window, error) {
|
||||||
onceMu.Lock()
|
onceMu.Lock()
|
||||||
defer onceMu.Unlock()
|
defer onceMu.Unlock()
|
||||||
if len(winMap) > 0 {
|
if len(winMap) > 0 {
|
||||||
@@ -190,7 +190,7 @@ func createWindow(opts WindowOptions) (*Window, error) {
|
|||||||
return werr.window, werr.err
|
return werr.window, werr.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNativeWindow(opts WindowOptions) (*window, error) {
|
func createNativeWindow(opts *WindowOptions) (*window, error) {
|
||||||
setProcessDPIAware()
|
setProcessDPIAware()
|
||||||
screenDC, err := getDC(0)
|
screenDC, err := getDC(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user