summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-03-17 22:58:26 +0100
committerder richter <der.richter@gmx.de>2024-03-18 20:29:27 +0100
commitbe49f4fe205bed7af4cc39a48f50af8a2691ce50 (patch)
tree396ef99406109b318c0456f3e0c349d3fe69ce5a
parent647bf5d0badbe09002bb05a7c3a7c3fe316a62a1 (diff)
downloadmpv-be49f4fe205bed7af4cc39a48f50af8a2691ce50.tar.bz2
mpv-be49f4fe205bed7af4cc39a48f50af8a2691ce50.tar.xz
mac/touchbar: simplify update items logic
-rw-r--r--osdep/mac/touch_bar.swift35
1 files changed, 8 insertions, 27 deletions
diff --git a/osdep/mac/touch_bar.swift b/osdep/mac/touch_bar.swift
index 9ee312fa7a..13bdbfa6f6 100644
--- a/osdep/mac/touch_bar.swift
+++ b/osdep/mac/touch_bar.swift
@@ -208,14 +208,9 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
guard let config = configs[.seekBar], let slider = config.view as? NSSlider else { return }
if !(config.item?.isVisible ?? false) { return }
- if duration <= 0 {
- slider.isEnabled = false
- slider.doubleValue = 0
- } else {
- slider.isEnabled = true
- if (!slider.isHighlighted) {
- slider.doubleValue = (position / duration) * 100
- }
+ slider.isEnabled = duration > 0
+ if !slider.isHighlighted {
+ slider.doubleValue = slider.isEnabled ? (position / duration) * 100 : 0
}
}
@@ -224,14 +219,9 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
if !(config.item?.isVisible ?? false) { return }
removeConstraintFor(identifier: .timeLeft)
- if duration <= 0 {
- text.stringValue = ""
- } else {
- let left = Int(floor(duration) - floor(position))
- let leftFormat = format(time: left)
- let durationFormat = format(time: Int(duration))
- text.stringValue = "-\(leftFormat)"
- applyConstraintFrom(string: "-\(durationFormat)", identifier: .timeLeft)
+ text.stringValue = duration > 0 ? "-" + format(time: Int(floor(duration) - floor(position))) : ""
+ if !text.stringValue.isEmpty {
+ applyConstraintFrom(string: "-" + format(time: Int(duration)), identifier: .timeLeft)
}
}
@@ -241,22 +231,13 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate {
text.stringValue = format(time: Int(floor(position)))
removeConstraintFor(identifier: .currentPosition)
- if duration <= 0 {
- applyConstraintFrom(string: format(time: Int(position)), identifier: .currentPosition)
- } else {
- applyConstraintFrom(string: format(time: Int(duration)), identifier: .currentPosition)
- }
+ applyConstraintFrom(string: format(time: Int(duration > 0 ? duration : position)), identifier: .currentPosition)
}
func updatePlayButton() {
guard let config = configs[.play], let button = config.view as? NSButton else { return }
if !isVisible || !(config.item?.isVisible ?? false) { return }
-
- if isPaused {
- button.image = configs[.play]?.imageAlt
- } else {
- button.image = configs[.play]?.image
- }
+ button.image = isPaused ? configs[.play]?.imageAlt : configs[.play]?.image
}
@objc func buttonAction(_ button: NSButton) {