internal/ui: remove panic in adjustWindowSize

This commit is contained in:
Hajime Hoshi 2024-09-28 02:45:56 +09:00
parent 55308e2d75
commit 2ef823ccd2
4 changed files with 14 additions and 9 deletions

View File

@ -219,8 +219,8 @@ func dipToGLFWPixel(x float64, scale float64) float64 {
return x
}
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
return x, y
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) {
return x, y, nil
}
var (

View File

@ -2113,7 +2113,12 @@ func (u *UserInterface) setWindowPositionInDIP(x, y int, monitor *Monitor) error
s := monitor.DeviceScaleFactor()
xf := dipToGLFWPixel(float64(x), s)
yf := dipToGLFWPixel(float64(y), s)
if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor); f {
x, y, err = u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor)
if err != nil {
return err
}
if f {
u.setOrigWindowPos(x, y)
} else {
if err := u.window.SetPos(x, y); err != nil {

View File

@ -131,8 +131,8 @@ func dipToGLFWPixel(x float64, deviceScaleFactor float64) float64 {
return x * deviceScaleFactor
}
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
return x, y
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) {
return x, y, nil
}
func initialMonitorByOS() (*Monitor, error) {

View File

@ -110,9 +110,9 @@ func dipToGLFWPixel(x float64, deviceScaleFactor float64) float64 {
return x * deviceScaleFactor
}
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int, error) {
if microsoftgdk.IsXbox() {
return x, y
return x, y, nil
}
mx := monitor.boundsInGLFWPixels.Min.X
@ -124,12 +124,12 @@ func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, i
}
t, err := _GetSystemMetrics(_SM_CYCAPTION)
if err != nil {
panic(err)
return 0, 0, err
}
if y < my+int(t) {
y = my + int(t)
}
return x, y
return x, y, nil
}
func initialMonitorByOS() (*Monitor, error) {