mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
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 <mail@eliasnaur.com>
This commit is contained in:
+12
-26
@@ -17,9 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// WindowOption configures a Window.
|
// WindowOption configures a Window.
|
||||||
type WindowOption struct {
|
type Option func(opts *windowOptions)
|
||||||
apply func(opts *windowOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
type windowOptions struct {
|
type windowOptions struct {
|
||||||
Width, Height unit.Value
|
Width, Height unit.Value
|
||||||
@@ -84,7 +82,7 @@ var ackEvent event.Event
|
|||||||
// platform.
|
// platform.
|
||||||
//
|
//
|
||||||
// BUG: Calling NewWindow more than once is not yet supported.
|
// BUG: Calling NewWindow more than once is not yet supported.
|
||||||
func NewWindow(options ...WindowOption) *Window {
|
func NewWindow(options ...Option) *Window {
|
||||||
opts := &windowOptions{
|
opts := &windowOptions{
|
||||||
Width: unit.Dp(800),
|
Width: unit.Dp(800),
|
||||||
Height: unit.Dp(600),
|
Height: unit.Dp(600),
|
||||||
@@ -92,7 +90,7 @@ func NewWindow(options ...WindowOption) *Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range options {
|
for _, o := range options {
|
||||||
o.apply(opts)
|
o(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
w := &Window{
|
w := &Window{
|
||||||
@@ -329,36 +327,24 @@ func (q *Queue) Events(k event.Key) []event.Event {
|
|||||||
return q.q.Events(k)
|
return q.q.Events(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithTitle returns an option that sets the window title.
|
// Title sets the title of the window.
|
||||||
func WithTitle(t string) WindowOption {
|
func Title(t string) Option {
|
||||||
return WindowOption{
|
return func(opts *windowOptions) {
|
||||||
apply: func(opts *windowOptions) {
|
opts.Title = t
|
||||||
opts.Title = t
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithWidth returns an option that sets the window width.
|
// Size sets the size of the window.
|
||||||
func WithWidth(w unit.Value) WindowOption {
|
func Size(w, h unit.Value) Option {
|
||||||
if w.V <= 0 {
|
if w.V <= 0 {
|
||||||
panic("width must be larger than or equal to 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 {
|
if h.V <= 0 {
|
||||||
panic("height must be larger than or equal to 0")
|
panic("height must be larger than or equal to 0")
|
||||||
}
|
}
|
||||||
return WindowOption{
|
return func(opts *windowOptions) {
|
||||||
apply: func(opts *windowOptions) {
|
opts.Width = w
|
||||||
opts.Height = h
|
opts.Height = h
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user