@@ -20,22 +20,53 @@ private let SwiftLabelProc: SUBCLASSPROC = { (hWnd, uMsg, wParam, lParam, uIdSub
2020 return DefSubclassProc ( hWnd, uMsg, wParam, lParam)
2121}
2222
23- public class Label : Control {
23+ fileprivate class LabelView : View {
2424 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+ }
2647
2748 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 }
3051 }
3152
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+ }
3463
3564 public init ( frame: Rect ) {
65+ self . view = LabelView ( frame: Rect ( origin: . zero, size: frame. size) )
3666 super. init ( frame: frame, class: Label . class, style: Label . style)
3767 _ = SetWindowSubclass ( hWnd, SwiftLabelProc, UINT_PTR ( 1 ) ,
3868 unsafeBitCast ( self as AnyObject , to: DWORD_PTR . self) )
69+ self . addSubview ( self . view)
3970 }
4071
4172 // ContentSizeCategoryAdjusting
0 commit comments