diff --git a/backends/opengl/window.go b/backends/opengl/window.go index 3cb5af3..8e37645 100644 --- a/backends/opengl/window.go +++ b/backends/opengl/window.go @@ -79,8 +79,12 @@ type WindowConfig struct { // You can make the window visible later using Window.Show(). Invisible bool - //SamplesMSAA specifies the level of MSAA to be used. Must be one of 0, 2, 4, 8, 16. 0 to disable. + // SamplesMSAA specifies the level of MSAA to be used. Must be one of 0, 2, 4, 8, 16. 0 to disable. SamplesMSAA int + + // BoundsLimits specifies the minimum and maximum bounds of the resizable window. + // If the window is full screen or not resizable, this has no effect. + BoundsLimits pixel.Rect } // Window is a window handler. Use this type to manipulate a window (input, drawing, etc.). @@ -173,6 +177,10 @@ func NewWindow(cfg WindowConfig) (*Window, error) { w.window.Show() } + if !cfg.BoundsLimits.Empty() { + w.SetBoundsLimits(cfg.BoundsLimits) + } + // enter the OpenGL context w.begin() glhf.Init() @@ -338,6 +346,14 @@ func (w *Window) Bounds() pixel.Rect { return w.bounds } +// SetBoundsLimits sets the minimum and maximum bounds of the window. +// If the window is full screen or not resizable, this function does nothing. +func (w *Window) SetBoundsLimits(limits pixel.Rect) { + mainthread.Call(func() { + w.window.SetSizeLimits(int(limits.Min.X), int(limits.Min.Y), int(limits.Max.X), int(limits.Max.Y)) + }) +} + func (w *Window) setFullscreen(monitor *Monitor) { mainthread.Call(func() { w.restore.xpos, w.restore.ypos = w.window.GetPos() diff --git a/rectangle.go b/rectangle.go index 34f30db..0093de7 100644 --- a/rectangle.go +++ b/rectangle.go @@ -50,6 +50,11 @@ func (r Rect) Norm() Rect { } } +// Empty returns whether the Rect's Min and Max vectors are equal to ZV. +func (r Rect) Empty() bool { + return r.Min.Eq(ZV) && r.Max.Eq(ZV) +} + // W returns the width of the Rect. func (r Rect) W() float64 { return r.Max.X - r.Min.X