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 3, 2023
1 parent 885771e commit 242162b
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)
_ = SetWindowPos(self.hWnd_, nil,
0, 0, CInt(size.width), CInt(size.height),
0, 0, CInt(frame.size.width), CInt(frame.size.height),
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 242162b

Please sign in to comment.