mirror of https://github.com/mpv-player/mpv
mac/touchbar: optimise constraint calculation
This commit is contained in:
parent
ef82ef0bb5
commit
d7cc5cdec1
|
@ -266,12 +266,10 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
|
|||
|
||||
func applyConstraintFrom(string: String, identifier: NSTouchBarItem.Identifier) {
|
||||
guard let text = configs[identifier]?.view as? NSTextField else { return }
|
||||
let fString = string.components(separatedBy: .decimalDigits).joined(separator: "0")
|
||||
let textField = NSTextField(labelWithString: fString)
|
||||
let size = textField.frame.size
|
||||
|
||||
let fullString = string.components(separatedBy: .decimalDigits).joined(separator: "0")
|
||||
let textField = NSTextField(labelWithString: fullString)
|
||||
let con = NSLayoutConstraint(item: text, attribute: .width, relatedBy: .equal, toItem: nil,
|
||||
attribute: .notAnAttribute, multiplier: 1.0, constant: ceil(size.width * 1.1))
|
||||
attribute: .notAnAttribute, multiplier: 1.1, constant: ceil(textField.frame.size.width))
|
||||
text.addConstraint(con)
|
||||
configs[identifier]?.constraint = con
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue