Skip to content

Commit

Permalink
Add setting min and max bounds limits on window
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Ray committed Aug 16, 2024
1 parent 1e73984 commit d00cbe0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion backends/opengl/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions rectangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d00cbe0

Please sign in to comment.