feat: cleaner layout and explanation text

This commit is contained in:
louis.pontoise authored and lwouis committed 2020-03-10 14:00:37 +09:00
1 parent a14f96550b
commit fd3e7680f4
2 files changed
+14 -7

No files matched your search

+2 -2
View File
@@ -46,8 +46,8 @@ class FeedbackWindow: NSWindow, NSTextViewDelegate {
buttons.spacing = GridView.interPadding
body = TextArea(80, 20, "I think the app could be improved with…")
body.delegate = self
email = TextArea(80, 1.1, "Optional: email (if you want a reply)")
debugProfile = NSButton(checkboxWithTitle: "Send debug profile", target: nil, action: nil)
email = TextArea(80, 1, "Optional: email (if you want a reply)")
debugProfile = NSButton(checkboxWithTitle: "Send debug profile (CPU, memory, etc)", target: nil, action: nil)
debugProfile.state = .on
let view = GridView.make([
[header],
@@ -1,15 +1,22 @@
import Cocoa
class TextArea: NSTextView {
static let paddingX = CGFloat(5)
static let paddingY = CGFloat(10)
static let padding = CGFloat(10)
static let magicOffset = CGFloat(3)
@objc var placeholderAttributedString: NSAttributedString?
convenience init(_ width: CGFloat, _ height: CGFloat, _ placeholder: String) {
self.init(frame: .zero)
font = NSFont.systemFont(ofSize: NSFont.systemFontSize)
textContainerInset = NSSize(width: TextArea.paddingX, height: TextArea.paddingY)
fit(font!.xHeight * width + TextArea.paddingX * 2, NSFont.systemFontSize * height + TextArea.paddingY * 2)
placeholderAttributedString = NSAttributedString(string: placeholder, attributes: [NSAttributedString.Key.foregroundColor: NSColor.gray])
textContainerInset = NSSize(width: TextArea.padding, height: TextArea.padding)
textContainer!.lineFragmentPadding = 0
let paragraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.maximumLineHeight = NSFont.systemFontSize + TextArea.magicOffset
placeholderAttributedString = NSAttributedString(string: placeholder, attributes: [
NSAttributedString.Key.font : NSFont.systemFont(ofSize: NSFont.systemFontSize),
NSAttributedString.Key.foregroundColor: NSColor.gray,
NSAttributedString.Key.paragraphStyle: paragraphStyle,
])
fit(font!.xHeight * width + TextArea.padding * 2, NSFont.systemFontSize * height + TextArea.padding * 2 + TextArea.magicOffset)
}
}