mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 17:41:24 +08:00
Size() calculates DPIs back to default space. (#2325)
This commit is contained in:
parent
a5ddce2c7c
commit
895d6d4b80
@ -250,6 +250,7 @@ func (cba *ControlBase) Size() (width, height int) {
|
|||||||
rect := w32.GetWindowRect(cba.hwnd)
|
rect := w32.GetWindowRect(cba.hwnd)
|
||||||
width = int(rect.Right - rect.Left)
|
width = int(rect.Right - rect.Left)
|
||||||
height = int(rect.Bottom - rect.Top)
|
height = int(rect.Bottom - rect.Top)
|
||||||
|
width, height = cba.scaleToDefaultDPI(width, height)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,6 +499,14 @@ func (cba *ControlBase) scaleWithWindowDPI(width, height int) (int, int) {
|
|||||||
return scaledWidth, scaledHeight
|
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 {
|
func (cba *ControlBase) tryInvokeOnCurrentGoRoutine(f func()) bool {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -149,3 +149,8 @@ func ScreenToClientRect(hwnd w32.HWND, rect *w32.RECT) *Rect {
|
|||||||
func ScaleWithDPI(pixels int, dpi uint) int {
|
func ScaleWithDPI(pixels int, dpi uint) int {
|
||||||
return (pixels * int(dpi)) / 96
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user