From a552c4c43a01f188a93afd518bfdfec61b1d51ec Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Thu, 27 Aug 2020 05:36:49 +0900 Subject: [PATCH] fix: moving some of the preferences sliders was very laggy --- .../preferences-window/LabelAndControl.swift | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/ui/preferences-window/LabelAndControl.swift b/src/ui/preferences-window/LabelAndControl.swift index c53cdc93..61b37cbc 100644 --- a/src/ui/preferences-window/LabelAndControl.swift +++ b/src/ui/preferences-window/LabelAndControl.swift @@ -70,10 +70,6 @@ class LabelAndControl: NSObject { slider.minValue = minValue slider.maxValue = maxValue slider.stringValue = value -// slider.numberOfTickMarks = numberOfTickMarks -// slider.allowsTickMarkValuesOnly = allowsTickMarkValuesOnly -// slider.tickMarkPosition = .below - // TODO: update suffix continuously, but only trigger action on mouse release slider.isContinuous = true return makeLabelWithProvidedControl(labelText, rawName, slider, suffixText) } @@ -107,11 +103,16 @@ class LabelAndControl: NSObject { static func controlWasChanged(_ senderControl: NSControl, _ controlId: String?) { if let newValue = LabelAndControl.getControlValue(senderControl, controlId) { - LabelAndControl.updateControlExtras(senderControl, newValue) + if senderControl is NSSlider { + updateSuffixWithValue(senderControl as! NSSlider, newValue) + } Preferences.set(senderControl.identifier!.rawValue, newValue) } // some preferences require re-creating some components - if ["iconSize", "fontHeight", "theme", "titleTruncation"].contains(where: { (pref: String) -> Bool in pref == senderControl.identifier!.rawValue }) { + if (!(senderControl is NSSlider) || (NSEvent.pressedMouseButtons & (1 << 0)) == 0) && + (["iconSize", "fontHeight", "theme", "titleTruncation"].contains { (pref: String) -> Bool in + pref == senderControl.identifier!.rawValue + }) { (App.shared as! App).resetPreferencesDependentComponents() } } @@ -156,12 +157,6 @@ class LabelAndControl: NSObject { } } - static func updateControlExtras(_ control: NSControl, _ value: String) { - if control is NSSlider { - updateSuffixWithValue(control as! NSSlider, value) - } - } - private static func updateSuffixWithValue(_ control: NSControl, _ value: String) { let suffixIdentifierPredicate = { (view: NSView) -> Bool in view.identifier?.rawValue == control.identifier!.rawValue + ControlIdentifierDiscriminator.SUFFIX.rawValue