Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Interactive playground demo
//: Playground - noun: a place where people can play
import Cocoa
import PlaygroundSupport
@testable import MyFramework
@testable import Utils
@testable import Element
ArrayParser.difference([1,2,3,4], [1])
class View: NSView {
override var isFlipped:Bool {return true}/*Organizes your view from top to bottom*/
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)//<--maybe: MTLSystemCreateDefaultDevice()
self.wantsLayer = true/*if true then view is layer backed*/
layer = CALayer()/*needs to be layer-hosted so that we dont get clipping of children*/
let progress:CGFloat = 0.8
let bgColor = NSColor.purple.blended(withFraction: progress,of: NSColor.cyan)!
layer?.backgroundColor = bgColor.cgColor
layer!.masksToBounds = false
let w = frame.size.width
let h = frame.size.height
let sliderW:CGFloat = 100
let sliderH:CGFloat = 20
let container = addSubView(Container(frame.size.width,frame.size.height))
let volumeSlider = container.addSubView(VolumeSlider(sliderW,sliderH,20,0,container))
func onVolumeSliderChange(event: Event) {
if(event.assert(SliderEvent.change, volumeSlider)){
let volumSliderProgress = (event as! SliderEvent).progress
let newColor = NSColor.purple.blended(withFraction: volumSliderProgress,of: NSColor.cyan)!
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
layer?.backgroundColor = newColor.cgColor
Swift.print("volumSliderProgress: " + "\(volumSliderProgress)")
volumeSlider.event = onVolumeSliderChange
required init(coder: NSCoder) {fatalError("init(coder:) has not been implemented") }
let view: View = View(frame:NSRect(x: 0, y: 0, width: 200, height: 200))
PlaygroundPage.current.liveView = view
//PlaygroundPage.current.needsIndefiniteExecution = true

This comment has been minimized.

Copy link
Owner Author

@eonist eonist commented Jan 19, 2017


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.