Skip to content

Commit

Permalink
UI: add containing View for each Label
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
egorzhdan and compnerd committed Apr 3, 2021
1 parent 1ef46ce commit 8b27859
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions Sources/SwiftWin32/Views and Controls/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,45 @@

import WinSDK

public class Label: Control {
fileprivate class LabelView: View {
private static let `class`: WindowClass = WindowClass(named: WC_STATIC)
private static let style: WindowStyle = (base: 0, extended: 0)

@_Win32WindowText
public var text: String?

public init(frame: Rect) {
super.init(frame: frame, class: LabelView.class, style: LabelView.style)
}
}

public class Label: Control {
private static let `class`: WindowClass =
WindowClass(hInst: GetModuleHandleW(nil), name: "Swift.Label")
private static let style: WindowStyle = (base: WS_TABSTOP, extended: 0)

private let view: LabelView

public override var frame: Rect {
didSet {
self.view.frame = Rect(origin: .zero, size: frame.size)
}
}

public override var font: Font! {
get { return super.font }
set(value) { super.font = value }
get { return self.view.font }
set(value) { self.view.font = value }
}

@_Win32WindowText
public var text: String?
public var text: String? {
get { return self.view.text }
set(value) { self.view.text = value }
}

public init(frame: Rect) {
self.view = LabelView(frame: Rect(origin: .zero, size: frame.size))
super.init(frame: frame, class: Label.class, style: Label.style)
self.addSubview(self.view)
}

// ContentSizeCategoryAdjusting
Expand Down

0 comments on commit 8b27859

Please sign in to comment.