exp/textinput: use native pixels for a candidate window position

This commit is contained in:
Hajime Hoshi 2024-03-03 23:31:14 +09:00
parent 3e4c47eb70
commit c0d9954b3e
8 changed files with 31 additions and 3 deletions

View File

@ -47,7 +47,7 @@ type State struct {
//
// Start returns nil and nil if the current environment doesn't support this package.
func Start(x, y int) (states chan State, close func()) {
cx, cy := ui.Get().LogicalPositionToClientPosition(float64(x), float64(y))
cx, cy := ui.Get().LogicalPositionToClientPositionInNativePixels(float64(x), float64(y))
return theTextInput.Start(int(cx), int(cy))
}

View File

@ -285,6 +285,10 @@ func (c *context) screenScaleAndOffsets() (scale, offsetX, offsetY float64) {
return
}
func (u *UserInterface) LogicalPositionToClientPosition(x, y float64) (float64, float64) {
return u.context.logicalPositionToClientPosition(x, y, u.Monitor().DeviceScaleFactor())
func (u *UserInterface) LogicalPositionToClientPositionInNativePixels(x, y float64) (float64, float64) {
s := u.Monitor().DeviceScaleFactor()
x, y = u.context.logicalPositionToClientPosition(x, y, s)
x = dipToNativePixels(x, s)
y = dipToNativePixels(y, s)
return x, y
}

View File

@ -129,3 +129,7 @@ func deviceScaleFactorImpl() float64 {
}
return s
}
func dipToNativePixels(x float64, scale float64) float64 {
return x * scale
}

View File

@ -2131,3 +2131,7 @@ func IsScreenTransparentAvailable() bool {
func (u *UserInterface) RunOnMainThread(f func()) {
u.mainThread.Call(f)
}
func dipToNativePixels(x float64, scale float64) float64 {
return dipToGLFWPixel(x, scale)
}

View File

@ -92,3 +92,7 @@ func deviceScaleFactorImpl() float64 {
// TODO: Can this be called from non-main threads?
return float64(C.devicePixelRatio())
}
func dipToNativePixels(x float64, scale float64) float64 {
return x
}

View File

@ -811,3 +811,7 @@ func (u *UserInterface) updateIconIfNeeded() error {
func IsScreenTransparentAvailable() bool {
return true
}
func dipToNativePixels(x float64, scale float64) float64 {
return x
}

View File

@ -181,3 +181,7 @@ func (u *UserInterface) Monitor() *Monitor {
func IsScreenTransparentAvailable() bool {
return false
}
func dipToNativePixels(x float64, scale float64) float64 {
return x
}

View File

@ -174,3 +174,7 @@ func (u *UserInterface) Monitor() *Monitor {
func IsScreenTransparentAvailable() bool {
return false
}
func dipToNativePixels(x float64, scale float64) float64 {
return x
}