From 486445929155cbc5c46d6998db1ef64cca12815a Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 7 Oct 2019 12:00:17 +0200 Subject: [PATCH] app: rename WindowOption to Option, and leave out "With" from options While we're here, replace Height and Width options with just a Size; the value of separate width and height options is not clear to me. Finally, leave out the wrapping struct from the Option type, the function is enough. Signed-off-by: Elias Naur --- app/window.go | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/app/window.go b/app/window.go index f0302e51..3b6ab41d 100644 --- a/app/window.go +++ b/app/window.go @@ -17,9 +17,7 @@ import ( ) // WindowOption configures a Window. -type WindowOption struct { - apply func(opts *windowOptions) -} +type Option func(opts *windowOptions) type windowOptions struct { Width, Height unit.Value @@ -84,7 +82,7 @@ var ackEvent event.Event // platform. // // BUG: Calling NewWindow more than once is not yet supported. -func NewWindow(options ...WindowOption) *Window { +func NewWindow(options ...Option) *Window { opts := &windowOptions{ Width: unit.Dp(800), Height: unit.Dp(600), @@ -92,7 +90,7 @@ func NewWindow(options ...WindowOption) *Window { } for _, o := range options { - o.apply(opts) + o(opts) } w := &Window{ @@ -329,36 +327,24 @@ func (q *Queue) Events(k event.Key) []event.Event { return q.q.Events(k) } -// WithTitle returns an option that sets the window title. -func WithTitle(t string) WindowOption { - return WindowOption{ - apply: func(opts *windowOptions) { - opts.Title = t - }, +// Title sets the title of the window. +func Title(t string) Option { + return func(opts *windowOptions) { + opts.Title = t } } -// WithWidth returns an option that sets the window width. -func WithWidth(w unit.Value) WindowOption { +// Size sets the size of the window. +func Size(w, h unit.Value) Option { if w.V <= 0 { panic("width must be larger than or equal to 0") } - return WindowOption{ - apply: func(opts *windowOptions) { - opts.Width = w - }, - } -} - -// WithHeight returns an option that sets the window height. -func WithHeight(h unit.Value) WindowOption { if h.V <= 0 { panic("height must be larger than or equal to 0") } - return WindowOption{ - apply: func(opts *windowOptions) { - opts.Height = h - }, + return func(opts *windowOptions) { + opts.Width = w + opts.Height = h } }