fix: moving some of the preferences sliders was very laggy

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-08-27 22:44:40 +09:00
1 parent 8bcbc04164
commit a552c4c43a
1 file changed
+7 -12
@@ -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