Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

André J eonist

🎯
Focusing
Block or report user

Report or block eonist

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View VerticalAlignedLabel.swift
import UIKit
/**
* Example:
* let label: VerticalAlignedLabel = UILabel()
* label.contentMode = .bottom
* Ref: https://stackoverflow.com/questions/18247934/how-to-align-uilabel-text-from-bottom
* TODO: ⚠️️ Maybe we could just do sizeThatFits fitToSize etc or just us TextField?
* Todo: this is cool but its not precise enough. this is more precise: https://stackoverflow.com/a/51761518
* let size = text.size(withAttributes:[.font: UIFont.systemFont(ofSize:18.0)])
*/
@eonist
eonist / GestureHUD_ AppDelegate.swift
Created Sep 7, 2017
GestureHUD companion xcode project (AppDelegate.swift)
View GestureHUD_ AppDelegate.swift
import Cocoa
@testable import Utils
@testable import Element
@NSApplicationMain
class AppDelegate:NSObject, NSApplicationDelegate {
weak var window:NSWindow!
var win:NSWindow?/*<--The window must be a class variable, local variables doesn't work*/
var menu:Menu?
View Forced Notifications
NSUserNotificationCenter.default.delegate = self//add this in the applicationDidFinishLaunching call
extension AppDelegate:NSUserNotificationCenterDelegate{
func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
return true
}
}
@eonist
eonist / LinearPressure.swift
Created Jul 26, 2017
linearPressure for forcetouch
View LinearPressure.swift
/**
* NOTE: calculates the entire range of the stage pressures so from stage 0 to 1 the pressure goes from 0 to 0.5 and from stage 1 to 2 the linear pressure goes from 0.5 to 1 this makes it easier to scale things in a linear fashion from 0 to 1 in the entire stage range
*/
var linearPressure:CGFloat{
if event.stage == 0 {
return 0
}else if event.stage == 1{
return pressure / 2
}else /*if stage == 2*/ {
return 0.5 + (pressure / 2)
@eonist
eonist / ForceTouchHandler.swift
Last active Feb 15, 2018
ForceTouch handler
View ForceTouchHandler.swift
var prevStage = 0
override func pressureChange(with event: NSEvent) {
let curStage:Int = event.stage
if event.pressureBehavior == NSPressureBehavior.primaryDeepClick,prevStage != curStage {
switch (curStage,prevStage){
case (0,1):
Swift.print("from idle to clickStage")
case (1,0):
Swift.print("from clickStage to idle")
case (1,2):
@eonist
eonist / PressureChangeTest.swift
Created Jul 25, 2017
ForceTouch in macOS teating pressureChange
View PressureChangeTest.swift
override func pressureChange(with event: NSEvent) {
/*A value from 0.0 through 1.0 indicating the degree of pressure applied to an appropriate input device.*/
Swift.print("event.pressure: " + "\(event.pressure)")
/*The pressure behavior and progression for an event of type pressure.*/
switch event.pressureBehavior {//<-NSPressureBehavior
case .primaryAccelerator:
Swift.print("primaryAccelerator")
case .primaryDeepClick:
View ElasticZoomTest.swift
/**
*
*/
func zoomBackAndForthAnimTest(){
//Setup window 200x300,white
let winRect = CGRect(0,0,200,300)
window.size = winRect.size
window.contentView = InteractiveView2()
window.title = ""
@eonist
eonist / ProtocolAssociatedType.swift
Created Mar 27, 2017 — forked from troystribling/ProtocolAssociatedType.swift
A swift protocol with associated type used as type parameter in generic function
View ProtocolAssociatedType.swift
protocol Thing {
typealias argType
func doit(val:argType) -> argType
}
class IntThing : Thing {
func doit(val: Int) -> Int {
return val + 1
}
}
View Point.swift
//
// Point.swift
// SwiftGenericGeometry
//
// Created by Jonathan Wight on 3/29/16.
// Copyright © 2016 schwa.io. All rights reserved.
//
public protocol PointType: Equatable {
associatedtype Scalar: ScalarType
@eonist
eonist / CubicCurveUtils.swift
Created Mar 18, 2017
find y for x on a Cubic Curve segment
View CubicCurveUtils.swift
import Foundation
class CubicCurveUtils {
/**
* Returns Y given X on a CubicPath segment
* PARAM: p0: prev end point
* PARAM: c0: controllpoint 1 for prev end point
* PARAM: c1: control point 2 for end point
* PARAM: p1: end point
*/
You can’t perform that action at this time.