Skip to content

Commit 07e91e6

Browse files
committed
Views and Controls: scale the label size
Scale the label size for the DPI. This corrects the rendering of the label when the display is scaled to a value other than 100%.
1 parent 952f1d1 commit 07e91e6

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Sources/SwiftWin32/Views and Controls/Label.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ public class Label: Control {
7979

8080
public override var frame: Rect {
8181
didSet {
82-
let size = self.frame.size
82+
let frame = self.frame.scaled(for: GetDpiForWindow(self.hWnd),
83+
style: Label.style)
8384
_ = SetWindowPos(self.hWnd_, nil,
84-
0, 0, CInt(size.width), CInt(size.height),
85+
0, 0, CInt(frame.size.width), CInt(frame.size.height),
8586
UINT(SWP_NOZORDER | SWP_FRAMECHANGED))
8687
}
8788
}
@@ -91,7 +92,8 @@ public class Label: Control {
9192
_ = SetWindowSubclass(hWnd, SwiftLabelProc, UINT_PTR(1),
9293
unsafeBitCast(self as AnyObject, to: DWORD_PTR.self))
9394

94-
let size = self.frame.size
95+
let size = self.frame.scaled(for: GetDpiForWindow(self.hWnd),
96+
style: Label.style).size
9597
self.hWnd_ = CreateWindowExW(0, WC_STATIC.wide, nil, DWORD(WS_CHILD),
9698
0, 0, CInt(size.width), CInt(size.height),
9799
self.hWnd, nil, GetModuleHandleW(nil), nil)!

0 commit comments

Comments
 (0)