Skip to content

Commit

Permalink
fix: moving some of the preferences sliders was very laggy
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 27, 2020
1 parent 8bcbc04 commit a552c4c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/ui/preferences-window/LabelAndControl.swift
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a552c4c

Please sign in to comment.