2015-08-07 01:04:05 -05:00
|
|
|
// 31 july 2015
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class tEntry : tControl {
|
2015-08-07 13:45:01 -05:00
|
|
|
private var t: NSTextField
|
|
|
|
private var parent: tControl?
|
2015-08-07 01:04:05 -05:00
|
|
|
private var horzpri, vertpri: NSLayoutPriority
|
|
|
|
|
|
|
|
init() {
|
2015-08-07 13:45:01 -05:00
|
|
|
var cell: NSTextFieldCell
|
|
|
|
|
2015-08-07 09:46:34 -05:00
|
|
|
self.t = NSTextField(frame: NSZeroRect)
|
2015-08-07 01:04:05 -05:00
|
|
|
self.t.selectable = true
|
2015-08-07 13:45:01 -05:00
|
|
|
self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
|
2015-08-07 01:04:05 -05:00
|
|
|
self.t.bordered = false
|
2015-08-07 13:45:01 -05:00
|
|
|
self.t.bezelStyle = NSTextFieldBezelStyle.SquareBezel
|
2015-08-07 01:04:05 -05:00
|
|
|
self.t.bezeled = true
|
2015-08-07 13:45:01 -05:00
|
|
|
cell = self.t.cell() as! NSTextFieldCell
|
|
|
|
cell.lineBreakMode = NSLineBreakMode.ByClipping
|
|
|
|
cell.scrollable = true
|
2015-08-07 01:04:05 -05:00
|
|
|
self.t.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
self.parent = nil
|
|
|
|
|
2015-08-07 09:46:34 -05:00
|
|
|
self.horzpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal)
|
|
|
|
self.vertpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical)
|
2015-08-07 01:04:05 -05:00
|
|
|
}
|
|
|
|
|
2015-08-07 09:46:34 -05:00
|
|
|
func tSetParent(p: tControl, addToView v: NSView) {
|
2015-08-07 01:04:05 -05:00
|
|
|
self.parent = p
|
|
|
|
v.addSubview(self.t)
|
|
|
|
}
|
|
|
|
|
2015-08-07 13:45:01 -05:00
|
|
|
func tFillAutoLayout(inout p: tAutoLayoutParams) {
|
2015-08-07 01:04:05 -05:00
|
|
|
// reset the hugging priority
|
2015-08-07 09:46:34 -05:00
|
|
|
self.t.setContentHuggingPriority(self.horzpri, forOrientation:NSLayoutConstraintOrientation.Horizontal)
|
|
|
|
self.t.setContentHuggingPriority(self.vertpri, forOrientation:NSLayoutConstraintOrientation.Vertical)
|
2015-08-07 01:04:05 -05:00
|
|
|
|
|
|
|
p.view = self.t
|
|
|
|
p.attachLeft = true
|
|
|
|
p.attachTop = true
|
|
|
|
p.attachRight = true
|
|
|
|
p.attachBottom = true
|
|
|
|
p.nonStretchyWidthPredicate = "(==96)" // TODO verify against Interface Builder
|
|
|
|
}
|
|
|
|
|
|
|
|
func tRelayout() {
|
2015-08-07 09:46:34 -05:00
|
|
|
if self.parent != nil {
|
2015-08-07 13:45:01 -05:00
|
|
|
self.parent?.tRelayout()
|
2015-08-07 01:04:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|