Skip to content

Commit 8b27859

Browse files
egorzhdancompnerd
andcommitted
UI: add containing View for each Label
`WC_STATIC` control doesn't receive events like `WM_CONTEXTMENU`. To be able to handle those events, let's create containing views for `WC_STATIC` instances. Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent 1ef46ce commit 8b27859

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

Sources/SwiftWin32/Views and Controls/Label.swift

+30-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,45 @@
77

88
import WinSDK
99

10-
public class Label: Control {
10+
fileprivate class LabelView: View {
1111
private static let `class`: WindowClass = WindowClass(named: WC_STATIC)
12+
private static let style: WindowStyle = (base: 0, extended: 0)
13+
14+
@_Win32WindowText
15+
public var text: String?
16+
17+
public init(frame: Rect) {
18+
super.init(frame: frame, class: LabelView.class, style: LabelView.style)
19+
}
20+
}
21+
22+
public class Label: Control {
23+
private static let `class`: WindowClass =
24+
WindowClass(hInst: GetModuleHandleW(nil), name: "Swift.Label")
1225
private static let style: WindowStyle = (base: WS_TABSTOP, extended: 0)
1326

27+
private let view: LabelView
28+
29+
public override var frame: Rect {
30+
didSet {
31+
self.view.frame = Rect(origin: .zero, size: frame.size)
32+
}
33+
}
34+
1435
public override var font: Font! {
15-
get { return super.font }
16-
set(value) { super.font = value }
36+
get { return self.view.font }
37+
set(value) { self.view.font = value }
1738
}
1839

19-
@_Win32WindowText
20-
public var text: String?
40+
public var text: String? {
41+
get { return self.view.text }
42+
set(value) { self.view.text = value }
43+
}
2144

2245
public init(frame: Rect) {
46+
self.view = LabelView(frame: Rect(origin: .zero, size: frame.size))
2347
super.init(frame: frame, class: Label.class, style: Label.style)
48+
self.addSubview(self.view)
2449
}
2550

2651
// ContentSizeCategoryAdjusting

0 commit comments

Comments
 (0)