Skip to content

Commit

Permalink
Views and Controls: scale the label size
Browse files Browse the repository at this point in the history
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%.
  • Loading branch information
compnerd committed Oct 8, 2023
1 parent 952f1d1 commit 5f823d5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/SwiftWin32/Views and Controls/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public class Label: Control {

public override var frame: Rect {
didSet {
let size = self.frame.size
let frame = self.frame.scaled(for: GetDpiForWindow(self.hWnd),
style: Label.style)

Check warning on line 83 in Sources/SwiftWin32/Views and Controls/Label.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SwiftWin32/Views and Controls/Label.swift#L82-L83

Added lines #L82 - L83 were not covered by tests
_ = SetWindowPos(self.hWnd_, nil,
0, 0, CInt(size.width), CInt(size.height),
0, 0, CInt(frame.size.width), CInt(frame.size.height),

Check warning on line 85 in Sources/SwiftWin32/Views and Controls/Label.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SwiftWin32/Views and Controls/Label.swift#L85

Added line #L85 was not covered by tests
UINT(SWP_NOZORDER | SWP_FRAMECHANGED))
}
}
Expand All @@ -91,7 +92,8 @@ public class Label: Control {
_ = SetWindowSubclass(hWnd, SwiftLabelProc, UINT_PTR(1),
unsafeBitCast(self as AnyObject, to: DWORD_PTR.self))

let size = self.frame.size
let size = self.frame.scaled(for: GetDpiForWindow(self.hWnd),
style: Label.style).size
self.hWnd_ = CreateWindowExW(0, WC_STATIC.wide, nil, DWORD(WS_CHILD),
0, 0, CInt(size.width), CInt(size.height),
self.hWnd, nil, GetModuleHandleW(nil), nil)!
Expand Down

0 comments on commit 5f823d5

Please sign in to comment.