ui/app: support 0 for window width and height

The zero value means that the client don't care and a sensible
default is chosen.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-09 22:01:25 +02:00
parent e5738481f8
commit 657c40e4bb
+18 -8
View File
@@ -18,9 +18,10 @@ import (
// WindowOptions specifies a set of window properties // WindowOptions specifies a set of window properties
// for creating new Windows. // for creating new Windows.
type WindowOptions struct { type WindowOptions struct {
Width ui.Value // Width and Height of the Window. Use the zero value
Height ui.Value // to choose a default size.
Title string Width, Height ui.Value
Title string
} }
// Window represents an operating system window. // Window represents an operating system window.
@@ -74,19 +75,28 @@ var ackEvent input.Event
// NewWindow creates a new window for a set of window // NewWindow creates a new window for a set of window
// options. The options are hints; the platform is free to // options. The options are hints; the platform is free to
// ignore or adjust them. // ignore or adjust them.
//
// If opts are nil, a set of sensible defaults are used.
//
// If the current program is running on iOS and Android, // If the current program is running on iOS and Android,
// NewWindow returns the window previously created by the // NewWindow returns the window previously created by the
// platform. // platform.
//
// BUG: Calling NewWindow more than once is not yet supported.
func NewWindow(opts *WindowOptions) *Window { func NewWindow(opts *WindowOptions) *Window {
if opts == nil { if opts == nil {
opts = &WindowOptions{ opts = &WindowOptions{
Width: ui.Dp(800), Title: "Gio",
Height: ui.Dp(600),
Title: "Gio",
} }
} }
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 or equal to 0")
}
if opts.Width.V == 0 {
opts.Width = ui.Dp(800)
}
if opts.Height.V == 0 {
opts.Height = ui.Dp(600)
} }
w := &Window{ w := &Window{