This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction public func onThicknesssliderChanged(_ sender: UISlider) { | |
let step: Float = 0.25 // using 0.1 causes text render backwards & slanted! Very weird SKLabel internal bug | |
let roundedValue = roundf(sender.value / step) * step | |
sender.value = roundedValue // force it to jump in increments | |
updatePreviewFromThicknessChange() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction public func onThicknesssliderChanged(_ sender: UISlider) { | |
let step: Float = 0.25 // using 0.1 causes text render backwards & slanted! Very weird SKLabel internal bug | |
let roundedValue = roundf(sender.value / step) * step | |
sender.value = roundedValue // force it to jump in increments | |
updatePreviewFromThicknessChange() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func updatePreviewFromThicknessChange() { | |
if thicknessAdjuster.value != lineWidth { | |
thicknessSwatch.setNeedsDisplay() // refresh assuming value adjusted | |
lineWidth = thicknessAdjuster.value | |
textStyle.drawStyle = textStyle.drawStyle.butWith( | |
lineWidthTenths: Int(lineWidth*10)) | |
updateFontStyling() | |
updateFontDisplay() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static func makeManyTextVaryingOutlines(workNum: UInt32) -> tgTouchgram { | |
let fc = tgColor(systemColor: .red) | |
let ec = tgColor(systemColor: .yellow) | |
let pt: UInt16 = 48 | |
let lw:[CGFloat] = Array(stride(from: 0.0, through: 4.0, by: 0.5)) | |
return tgTouchgram(title: "Lots of Text Varying Outlines", scenes: [ | |
tgScene(background: tgColorBackground(fill: tgColor(systemColor: .blue)), | |
triggers: [], | |
nodes: tgNodeList(nodes: [ | |
tgSimpleTextNode(position: tgNodePosition(anchored: .topLeft, paddingPixels: 8), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created by Andy Dent on 9/2/22. | |
// Copyright © 2022 Touchgram Pty Ltd. All rights reserved. | |
import Foundation | |
import UIKit | |
/// portions showing how the sizing works | |
class SimpleTextNodeDetailViewController: UIViewController { | |
@IBOutlet var labelEntryWidthToOverall: NSLayoutConstraint! | |
@IBOutlet var labelEntryWidthToPreview: NSLayoutConstraint! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shows how C++11 can implement the "defer" introduced in Swift 2.0 | |
#include <iostream> | |
using simpleClosure = std::function<void()>; // new typedef syntax used for closure | |
// class only needs to be declared once then used all over to wrap closures | |
// see http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization | |
class deferRAII { | |
public: | |
deferRAII(simpleClosure cl) : runOnDestruction(cl) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the Swift direct equivalent of the F# gist https://gist.github.com/AndyDentFree/46ac476a31b07d103a03 | |
import Darwin | |
enum Shape { | |
case Circle (radius:Double) | |
case Rectangle (width:Double, height:Double) | |
case Triangle (tbase:Double, height:Double) | |
} | |
func area(shape:Shape) -> Double { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Microsoft.FSharp.Math | |
type Shape = | |
| Circle of radius:float | |
| Rectangle of width:float * height:float // tuple of float, float | |
| Triangle of tbase:float * height:float | |
let area shape = | |
match shape with | |
| Circle radius -> Math.PI * radius * radius | |
| Rectangle (width, height) -> width * height |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Sometimes in iOS code, you need to be able to walk up the chain of parent views, especially if working on legacy code. | |
This has been hardcoded in the past with horrible assumptions like this, which broke again in iOS 8: | |
if (IS_IOS7_AND_UP) { | |
spdVC = (SuperDuperViewController*)[(UITableView*)self.superview.superview.superview.superview.superview delegate]; | |
} else { | |
spdVC = (SuperDuperViewController*)[(UITableView*)self.superview.superview.superview delegate]; | |
} |