app/window,app/internal/window: allow min/max window size

The app.MinSize and app.MaxSize options restricts the window size:

w := app.NewWindow(
	app.Size(unit.Dp(600), unit.Dp(596)),
	app.MinSize(unit.Dp(600), unit.Dp(596)),
	app.MaxSize(unit.Dp(600), unit.Dp(596)),
	app.Title(APPNAME),
)

Signed-off-by: Jason <sourcehut@sweatyballs.es>
This commit is contained in:
Jason
2020-06-22 12:49:41 +02:00
committed by Elias Naur
parent 20cf570709
commit 9cfbdafe14
7 changed files with 150 additions and 33 deletions
+28
View File
@@ -427,4 +427,32 @@ func Size(w, h unit.Value) Option {
}
}
// MaxSize sets the maximum size of the window.
func MaxSize(w, h unit.Value) Option {
if w.V <= 0 {
panic("width must be larger than or equal to 0")
}
if h.V <= 0 {
panic("height must be larger than or equal to 0")
}
return func(opts *window.Options) {
opts.MaxWidth = w
opts.MaxHeight = h
}
}
// MinSize sets the minimum size of the window.
func MinSize(w, h unit.Value) Option {
if w.V <= 0 {
panic("width must be larger than or equal to 0")
}
if h.V <= 0 {
panic("height must be larger than or equal to 0")
}
return func(opts *window.Options) {
opts.MinWidth = w
opts.MinHeight = h
}
}
func (driverEvent) ImplementsEvent() {}