5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 04:42:00 +08:00

Size() calculates DPIs back to default space. (#2325)

This commit is contained in:
Sebastian Bauer 2023-01-22 05:25:26 +01:00 committed by GitHub
parent a5ddce2c7c
commit 895d6d4b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -250,6 +250,7 @@ func (cba *ControlBase) Size() (width, height int) {
rect := w32.GetWindowRect(cba.hwnd)
width = int(rect.Right - rect.Left)
height = int(rect.Bottom - rect.Top)
width, height = cba.scaleToDefaultDPI(width, height)
return
}
@ -498,6 +499,14 @@ func (cba *ControlBase) scaleWithWindowDPI(width, height int) (int, int) {
return scaledWidth, scaledHeight
}
func (cba *ControlBase) scaleToDefaultDPI(width, height int) (int, int) {
dpix, dpiy := cba.GetWindowDPI()
scaledWidth := ScaleToDefaultDPI(width, dpix)
scaledHeight := ScaleToDefaultDPI(height, dpiy)
return scaledWidth, scaledHeight
}
func (cba *ControlBase) tryInvokeOnCurrentGoRoutine(f func()) bool {
runtime.LockOSThread()
defer runtime.UnlockOSThread()

View File

@ -149,3 +149,8 @@ func ScreenToClientRect(hwnd w32.HWND, rect *w32.RECT) *Rect {
func ScaleWithDPI(pixels int, dpi uint) int {
return (pixels * int(dpi)) / 96
}
// ScaleToDefaultDPI scales the pixels from scaled DPI-Space to default DPI-Space (96).
func ScaleToDefaultDPI(pixels int, dpi uint) int {
return (pixels * 96) / int(dpi)
}