@@ -20,22 +20,53 @@ private let SwiftLabelProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSub
20
20
return DefSubclassProc ( hWnd, uMsg, wParam, lParam)
21
21
}
22
22
23
- public class Label : Control {
23
+ fileprivate class LabelView : View {
24
24
private static let `class` : WindowClass = WindowClass ( named: WC_STATIC)
25
- private static let style : WindowStyle = ( base: WS_TABSTOP | DWORD ( SS_NOTIFY) , extended: 0 )
25
+ private static let style : WindowStyle = ( base: 0 , extended: 0 )
26
+
27
+ @_Win32WindowText
28
+ public var text : String ?
29
+
30
+ public init ( frame: Rect ) {
31
+ super. init ( frame: frame, class: LabelView . class, style: LabelView . style)
32
+ }
33
+ }
34
+
35
+ public class Label : Control {
36
+ private static let `class` : WindowClass =
37
+ WindowClass ( hInst: GetModuleHandleW ( nil ) , name: " Swift.Label " )
38
+ private static let style : WindowStyle = ( base: WS_TABSTOP, extended: 0 )
39
+
40
+ private let view : LabelView
41
+
42
+ public override var frame : Rect {
43
+ didSet {
44
+ self . view. frame = Rect ( origin: . zero, size: frame. size)
45
+ }
46
+ }
26
47
27
48
public override var font : Font ! {
28
- get { return super . font }
29
- set ( value) { super . font = value }
49
+ get { return self . view . font }
50
+ set ( value) { self . view . font = value }
30
51
}
31
52
32
- @_Win32WindowText
33
- public var text : String ?
53
+ public var text : String ? {
54
+ get { return self . view. text }
55
+ set ( value) { self . view. text = value }
56
+ }
57
+
58
+ public override var subviews : [ View ] {
59
+ get {
60
+ return super. subviews. filter { $0 !== view }
61
+ }
62
+ }
34
63
35
64
public init ( frame: Rect ) {
65
+ self . view = LabelView ( frame: Rect ( origin: . zero, size: frame. size) )
36
66
super. init ( frame: frame, class: Label . class, style: Label . style)
37
67
_ = SetWindowSubclass ( hWnd, SwiftLabelProc, UINT_PTR ( 1 ) ,
38
68
unsafeBitCast ( self as AnyObject , to: DWORD_PTR . self) )
69
+ self . addSubview ( self . view)
39
70
}
40
71
41
72
// ContentSizeCategoryAdjusting
0 commit comments