app: [API] add minimized window mode, change methods to options

The window modes are extended, following microsoft conventions.
We have Fullscreen, Overlapping, Maximized and Minimized.
These modes can be set via options when a new window is creates,
or modified later by calling helper functions like w.Maximize() and w.Center()

The window configuration is automatically updated when a user
modifies the window by dragging or clicking the icons on the window's title-bar,
minimizing or maximizing the window.

Any change, either by the user or the application will emit a ConfigChange event.

This is implemented and tested on Windows only.

API change. the app.Window methods Maximize and Center are replaced with similar
options. For example, to maximize a window use

    w.Option(app.Maximized.Option())

Also, Maximize and Center implementations for X11 and macOS are left for a future
change.

Fixes: https://todo.sr.ht/~eliasnaur/gio/315
Signed-off-by: Jan Kåre Vatne <jkvatne@online.no>
This commit is contained in:
Jan Kåre Vatne
2022-01-12 20:41:44 +01:00
committed by Elias Naur
parent 13183522dd
commit c4f98d3c1e
8 changed files with 161 additions and 224 deletions
+11 -18
View File
@@ -321,22 +321,6 @@ func (w *Window) Close() {
})
}
// Maximize the window.
// Note: only implemented on Windows, macOS and X11.
func (w *Window) Maximize() {
w.driverDefer(func(d driver) {
d.Maximize()
})
}
// Center the window.
// Note: only implemented on Windows, macOS and X11.
func (w *Window) Center() {
w.driverDefer(func(d driver) {
d.Center()
})
}
// Run f in the same thread as the native window event loop, and wait for f to
// return or the window to close. Run is guaranteed not to deadlock if it is
// invoked during the handling of a ViewEvent, system.FrameEvent,
@@ -703,8 +687,7 @@ func Title(t string) Option {
}
}
// Size sets the size of the window. The option is ignored
// in Fullscreen mode.
// Size sets the size of the window. The mode will be changed to Windowed.
func Size(w, h unit.Value) Option {
if w.V <= 0 {
panic("width must be larger than or equal to 0")
@@ -713,6 +696,7 @@ func Size(w, h unit.Value) Option {
panic("height must be larger than or equal to 0")
}
return func(m unit.Metric, cnf *Config) {
cnf.Mode = Windowed
cnf.Size = image.Point{
X: m.Px(w),
Y: m.Px(h),
@@ -720,6 +704,15 @@ func Size(w, h unit.Value) Option {
}
}
// Center is an option to center the window on the screen.
// The option is ignored in Fullscreen mode.
func Centered() Option {
return func(m unit.Metric, cnf *Config) {
// Set the flag so the driver can later do the actual centering.
cnf.center = true
}
}
// MaxSize sets the maximum size of the window.
func MaxSize(w, h unit.Value) Option {
if w.V <= 0 {