Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Interactive playground demo
//: Playground - noun: a place where people can play
import Cocoa
import PlaygroundSupport
@testable import MyFramework
//Temp.test()
@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
StyleManager.addStylesByURL("~/Desktop/ElCapitan/explorer.css")
StyleManager.addStyle("Container{margin-left:\((w/2)-(sliderW/2))px;margin-top:\((h/2)-(sliderH/2))px;}")
let container = addSubView(Container(frame.size.width,frame.size.height))
let volumeSlider = container.addSubView(VolumeSlider(sliderW,sliderH,20,0,container))
volumeSlider.setProgressValue(progress)
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.begin()
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
layer?.backgroundColor = newColor.cgColor
CATransaction.commit()
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
@eonist

This comment has been minimized.

Copy link
Owner Author

@eonist eonist commented Jan 19, 2017

img

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.