forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorMessageView.swift
More file actions
49 lines (41 loc) · 1.62 KB
/
ErrorMessageView.swift
File metadata and controls
49 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import SwiftUI
public class ErrorMessageView: NSView {
public init(errorMessage: String) {
// Create a custom view for the menu item
let maxWidth: CGFloat = 240
let padding = NSEdgeInsets(top: 8, left: 12, bottom: 8, right: 12)
// Initialize with temporary frame, will be adjusted
super.init(frame: NSRect(x: 0, y: 0, width: maxWidth, height: 0))
let textField = NSTextField(frame: .zero)
textField.stringValue = errorMessage
textField.isEditable = false
textField.isBordered = false
textField.drawsBackground = false
textField.lineBreakMode = .byWordWrapping
textField.usesSingleLineMode = false
textField.cell?.wraps = true
textField.cell?.isScrollable = false
textField.textColor = .secondaryLabelColor
// Calculate the required height
let fittingSize = textField.sizeThatFits(
NSSize(width: maxWidth - padding.left - padding.right,
height: CGFloat.greatestFiniteMagnitude)
)
// Set the final frames
self.frame = NSRect(
x: 0, y: 0,
width: maxWidth,
height: fittingSize.height + padding.top + padding.bottom
)
textField.frame = NSRect(
x: padding.left,
y: padding.bottom,
width: maxWidth - padding.left - padding.right,
height: fittingSize.height
)
addSubview(textField)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}