internal/glfw: refactoring: keep the original API when possible

Updates #1804
This commit is contained in:
Hajime Hoshi 2022-02-09 19:36:42 +09:00
parent 623c050537
commit 740dfd5aed
4 changed files with 14 additions and 14 deletions

View File

@ -208,12 +208,8 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
w.w.SetSizeLimits(minw, minh, maxw, maxh) w.w.SetSizeLimits(minw, minh, maxw, maxh)
} }
func (w *Window) SetAspectRatioFixed(fixed bool) { func (w *Window) SetAspectRatio(numer, denom int) {
n, d := glfw.DontCare, glfw.DontCare w.w.SetAspectRatio(numer, denom)
if fixed {
n, d = w.GetSize()
}
w.w.SetAspectRatio(n, d)
} }
func (w *Window) SetIcon(images []image.Image) { func (w *Window) SetIcon(images []image.Image) {

View File

@ -261,12 +261,8 @@ func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
panicError() panicError()
} }
func (w *Window) SetAspectRatioFixed(fixed bool) { func (w *Window) SetAspectRatio(numer, denom int) {
n, d := -1, -1 glfwDLL.call("glfwSetWindowAspectRatio", w.w, uintptr(numer), uintptr(denom))
if fixed {
n, d = w.GetSize()
}
glfwDLL.call("glfwSetWindowAspectRatio", w.w, uintptr(n), uintptr(d))
panicError() panicError()
} }

View File

@ -932,7 +932,7 @@ func (u *UserInterface) init() error {
u.window.Maximize() u.window.Maximize()
} }
u.window.SetAspectRatioFixed(u.isInitWindowAspectRatioFixed()) u.setWindowAspectRatioFixed(u.isInitWindowAspectRatioFixed())
u.window.Show() u.window.Show()
@ -1623,3 +1623,11 @@ func (u *UserInterface) setOrigPos(x, y int) {
u.origPosX = x u.origPosX = x
u.origPosY = y u.origPosY = y
} }
func (u *UserInterface) setWindowAspectRatioFixed(fixed bool) {
n, d := glfw.DontCare, glfw.DontCare
if fixed {
n, d = u.window.GetSize()
}
u.window.SetAspectRatio(n, d)
}

View File

@ -233,7 +233,7 @@ func (w *Window) SetAspectRatioFixed(fixed bool) {
return return
} }
w.ui.t.Call(func() { w.ui.t.Call(func() {
w.ui.window.SetAspectRatioFixed(fixed) w.ui.setWindowAspectRatioFixed(fixed)
}) })
} }