Skip to content

Commit

Permalink
AppKitBackend: Implement slider and picker
Browse files Browse the repository at this point in the history
  • Loading branch information
stackotter committed Apr 7, 2024
1 parent 337d2b8 commit 0bff1ce
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Sources/AppKitBackend/AppKitBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,64 @@ public struct AppKitBackend: AppBackend {
container.addView(widget, in: .center)
}
}

public func createSlider() -> NSView {
return NSSlider()
}

public func updateSlider(
_ slider: NSView,
minimum: Double,
maximum: Double,
decimalPlaces: Int,
onChange: @escaping (Double) -> Void
) {
// TODO: Implement decimalPlaces

Check warning on line 233 in Sources/AppKitBackend/AppKitBackend.swift

View workflow job for this annotation

GitHub Actions / swift-lint

Todo Violation: TODOs should be resolved (Implement decimalPlaces) (todo)
let slider = slider as! NSSlider
slider.minValue = minimum
slider.maxValue = maximum
slider.onAction = { slider in
let slider = slider as! NSSlider
onChange(slider.doubleValue)
}
}

public func setValue(ofSlider slider: NSView, to value: Double) {
let slider = slider as! NSSlider
slider.doubleValue = value
}

public func createPicker() -> NSView {
return NSPopUpButton()
}

public func updatePicker(
_ picker: NSView, options: [String], onChange: @escaping (Int?) -> Void
) {
let picker = picker as! NSPopUpButton
picker.addItems(withTitles: options)
picker.onAction = { picker in
let picker = picker as! NSPopUpButton
onChange(picker.indexOfSelectedItem)
}
}

public func setSelectedOption(ofPicker picker: NSView, to selectedOption: Int?) {
let picker = picker as! NSPopUpButton
if let index = selectedOption {
picker.selectItem(at: index)
} else {
picker.select(nil)
}
}

public func createStyleContainer(for child: NSView) -> NSView {
return child
}

public func setForegroundColor(ofStyleContainer container: NSView, to color: Color) {
// TODO: Implement foreground color
}
}

// Source: https://gist.github.com/sindresorhus/3580ce9426fff8fafb1677341fca4815
Expand Down

0 comments on commit 0bff1ce

Please sign in to comment.