Migrated Spinbox back.
This commit is contained in:
parent
a6b16d6473
commit
43e3d538e0
|
@ -13,7 +13,7 @@ func appLaunched() {
|
|||
var mainwin = Window()
|
||||
mainwin.SetMargined(spaced)
|
||||
|
||||
var control = Label()
|
||||
var control = Spinbox()
|
||||
mainwin.SetControl(control)
|
||||
|
||||
mainwin.Show()
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
// 31 july 2015
|
||||
import Cocoa
|
||||
|
||||
var nspinbox = 0
|
||||
|
||||
class Spinbox : NSView, Control {
|
||||
private var t: NSTextField
|
||||
private var s: NSStepper
|
||||
private var parent: Control?
|
||||
|
||||
init() {
|
||||
var cell: NSTextFieldCell
|
||||
|
||||
self.t = NSTextField(frame: NSZeroRect)
|
||||
self.t.stringValue = "\(nspinbox)"
|
||||
nspinbox++
|
||||
self.t.selectable = true
|
||||
self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
|
||||
self.t.bordered = false
|
||||
self.t.bezelStyle = NSTextFieldBezelStyle.SquareBezel
|
||||
self.t.bezeled = true
|
||||
cell = self.t.cell() as! NSTextFieldCell
|
||||
cell.lineBreakMode = NSLineBreakMode.ByClipping
|
||||
cell.scrollable = true
|
||||
self.t.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.s = NSStepper(frame: NSZeroRect)
|
||||
self.s.increment = 1
|
||||
self.s.valueWraps = false
|
||||
self.s.autorepeat = true
|
||||
self.s.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.parent = nil
|
||||
|
||||
super.init(frame: NSZeroRect)
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.addSubview(self.t)
|
||||
self.addSubview(self.s)
|
||||
var views = [
|
||||
"t": self.t,
|
||||
"s": self.s,
|
||||
]
|
||||
var constraints = mkconstraints("H:|[t]-[s]|", views)
|
||||
self.addConstraints(constraints)
|
||||
constraints = mkconstraints("V:|[t]|", views)
|
||||
self.addConstraints(constraints)
|
||||
constraints = mkconstraints("V:|[s]|", views)
|
||||
self.addConstraints(constraints)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("can't use this constructor, sorry")
|
||||
}
|
||||
|
||||
// TODO leave only the required amount of space around the alignment rect
|
||||
override var alignmentRectInsets: NSEdgeInsets {
|
||||
get {
|
||||
return NSEdgeInsetsMake(50, 50, 50, 50)
|
||||
}
|
||||
}
|
||||
|
||||
func View() -> NSView {
|
||||
return self
|
||||
}
|
||||
|
||||
func SetParent(p: Control) {
|
||||
self.parent = p
|
||||
}
|
||||
|
||||
func Relayout() {
|
||||
if self.parent != nil {
|
||||
self.parent?.Relayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO p.nonStretchyWidthPredicate = "(==96)" // TODO on the text field only
|
|
@ -1,89 +0,0 @@
|
|||
// 31 july 2015
|
||||
import Cocoa
|
||||
|
||||
// leave a whole lot of space around the alignment rect, just to be safe
|
||||
class tSpinboxContainer : NSView {
|
||||
override var alignmentRectInsets: NSEdgeInsets {
|
||||
get {
|
||||
return NSEdgeInsetsMake(50, 50, 50, 50)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var nspinbox = 0
|
||||
|
||||
class tSpinbox : tControl {
|
||||
private var c: tSpinboxContainer
|
||||
private var t: NSTextField
|
||||
private var s: NSStepper
|
||||
private var parent: tControl?
|
||||
private var horzpri, vertpri: NSLayoutPriority
|
||||
|
||||
init() {
|
||||
var cell: NSTextFieldCell
|
||||
|
||||
self.c = tSpinboxContainer(frame: NSZeroRect)
|
||||
self.c.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.t = NSTextField(frame: NSZeroRect)
|
||||
self.t.stringValue = "\(nspinbox)"
|
||||
nspinbox++
|
||||
self.t.selectable = true
|
||||
self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
|
||||
self.t.bordered = false
|
||||
self.t.bezelStyle = NSTextFieldBezelStyle.SquareBezel
|
||||
self.t.bezeled = true
|
||||
cell = self.t.cell() as! NSTextFieldCell
|
||||
cell.lineBreakMode = NSLineBreakMode.ByClipping
|
||||
cell.scrollable = true
|
||||
self.t.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.c.addSubview(self.t)
|
||||
|
||||
self.s = NSStepper(frame: NSZeroRect)
|
||||
self.s.increment = 1
|
||||
self.s.valueWraps = false
|
||||
self.s.autorepeat = true
|
||||
self.s.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.c.addSubview(self.s)
|
||||
|
||||
var views = [
|
||||
"t": self.t,
|
||||
"s": self.s,
|
||||
]
|
||||
var constraints = mkconstraints("H:|[t]-[s]|", views)
|
||||
self.c.addConstraints(constraints)
|
||||
constraints = mkconstraints("V:|[t]|", views)
|
||||
self.c.addConstraints(constraints)
|
||||
constraints = mkconstraints("V:|[s]|", views)
|
||||
self.c.addConstraints(constraints)
|
||||
|
||||
self.parent = nil
|
||||
|
||||
self.horzpri = self.c.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal)
|
||||
self.vertpri = self.c.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical)
|
||||
}
|
||||
|
||||
func tSetParent(p: tControl, addToView v: NSView) {
|
||||
self.parent = p
|
||||
v.addSubview(self.c)
|
||||
}
|
||||
|
||||
func tFillAutoLayout(inout p: tAutoLayoutParams) {
|
||||
// reset the hugging priority
|
||||
self.c.setContentHuggingPriority(self.horzpri, forOrientation:NSLayoutConstraintOrientation.Horizontal)
|
||||
self.c.setContentHuggingPriority(self.vertpri, forOrientation:NSLayoutConstraintOrientation.Vertical)
|
||||
|
||||
p.view = self.c
|
||||
p.attachLeft = true
|
||||
p.attachTop = true
|
||||
p.attachRight = true
|
||||
p.attachBottom = true
|
||||
p.nonStretchyWidthPredicate = "(==96)" // TODO on the text field only
|
||||
}
|
||||
|
||||
func tRelayout() {
|
||||
if self.parent != nil {
|
||||
self.parent?.tRelayout()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue