Skip to content

Update/solid outline #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- TextAnnotation (0.5.0)
- TextAnnotation (0.6.2)

DEPENDENCIES:
- TextAnnotation (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
TextAnnotation: bfdd0de6ce6475cc721148f7957b97ae392dd7d3
TextAnnotation: 5cf7e9f5862e50c22bf0a4e8365226041fb18353

PODFILE CHECKSUM: 24794d4a45470042cf26e82d16c0c9132fcdefde

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/TextAnnotation.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

484 changes: 249 additions & 235 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Screen Shot 2020-09-09 at 5.43.19 PM.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Screen Shot 2020-09-09 at 5.40.22 PM.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Screen Shot 2020-09-09 at 5.41.50 PM.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Screen Shot 2020-09-09 at 5.33.41 PM.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 98 additions & 5 deletions Example/TextAnnotation/Previews/TextContainerView_Preview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,115 @@ import SwiftUI

@available(OSX 10.15.0, *)
struct TextContainerViewPreview: NSViewRepresentable {
let attributes: [NSAttributedString.Key: Any]?
let color: NSColor?
init(attributes: [NSAttributedString.Key: Any]? = nil,
color: NSColor? = nil) {
self.attributes = attributes
self.color = color
}
func makeNSView(context: Context) -> TextContainerView {
TextContainerView(frame: .zero,
text: "Text Annotation",
color: .defaultColor())
color: color?.textColor ?? .defaultColor(),
textAttributes: attributes)
}

func updateNSView(_ view: TextContainerView, context: Context) {
}
}

struct ExampleScreenshots {
static var github = #imageLiteral(resourceName: "github_screenshot")
static var landingPage = #imageLiteral(resourceName: "browser_screenshot")
static var browserApp = #imageLiteral(resourceName: "browser_app_screenshot")
static var figma = #imageLiteral(resourceName: "figma_screenshot")
}

struct TextParams {
var font = "HelveticaNeue-Bold"
var fontSize = 30.0
var strokeWidth = 3.0
var outlineWidth = -2.5
var outlineColor = NSColor.white
var shadowColor = NSColor.white
var shadowOffsetX = 1.5
var shadowOffsetY = 1.5
var shadowBlur = 2.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulian-onua I added this stub for a parameter struct that makes clear which options we have.
We should make it easy to wire this up with a settings interface and be able to serialize it.
The current way the parameters are passed in is a bit hard to understand - for example I didn't understand how the font color and separate color param is different.
If we can just use a simple struct like this and make it the public interface of the package that would make it easy to customize.

I'm thinking we should allow passing in an optional params struct like this which can also be used in the Annotations module to serialize to JSON. This way we can easily construct JSON-based examples for different scenarios in the Annotations module.
We might even decide to let Zappy users tweak these parameters in an advanced settings section later.

Let's add these params the public interface of this lib and then move the SwiftUI previews into the Annotations package.

}

@available(OSX 10.15.0, *)
struct TextContainerView_Previews: PreviewProvider {
static var previews: some View {
TextContainerViewPreview()
.background(Color.gray)
.previewLayout(.fixed(width: 300.0, height: 300.0))

// a color to use in all previews if no custom color is passed
static var defaultColor: NSColor? = NSColor.color(from: TextColor.orange)



static var previews: some View {
Group {

preview(with: nil) // current default settings

preview(with: TextAttributes.shadow(color: .white,
offsetX: 4.0,
offsetY: 0.0,
blur: 3.0))

preview(with: TextAttributes.outlineWithShadow(outlineWidth: -2.5,
outlineColor: .white,
shadowColor: .white,
shadowOffsetX: 1.5,
shadowOffsetY: 1.5,
shadowBlur: 2.0))

preview(with: TextAttributes.outline(outlineWidth: -5.0,
outlineColor: .white))

preview(with: TextAttributes.outline(outlineWidth: -5.0,
outlineColor: .white),
color: NSColor.color(from: TextColor.violet))

preview(with: TextAttributes.outline(outlineWidth: -5.0,
outlineColor: .black))

preview(with: TextAttributes.outlineWithShadow(outlineWidth: -2.5,
outlineColor: .black,
shadowColor: .white,
shadowOffsetX: -2.0,
shadowOffsetY: -0.5,
shadowBlur: 3.0))

preview(with: TextAttributes.outlineWithShadow(outlineWidth: -2.5,
outlineColor: .blue,
shadowColor: .systemBlue,
shadowOffsetX: 2.5,
shadowOffsetY: 0.5,
shadowBlur: 5.0),
color: .yellow)

preview(with: [.font: NSFont(name: "Apple Chancery", size: 30.0) as Any,
.strokeColor: NSColor.white,
.strokeWidth: -2.5],
color: NSColor.color(from: TextColor.violet))
}
}

static func preview(with attributes: [NSAttributedString.Key: Any]?,
color: NSColor? = defaultColor) -> some View {

TextContainerViewPreview(attributes: attributes, color: color)
.background(Image(nsImage: ExampleScreenshots.landingPage))
.previewLayout(.fixed(width: 300.0, height: 200.0))
}
}
#endif

extension NSColor {
func color(from textColor: TextColor) -> NSColor {
return NSColor(red: textColor.red,
green: textColor.green,
blue: textColor.blue,
alpha: textColor.alpha)
}
}
52 changes: 52 additions & 0 deletions TextAnnotation/Classes/Attributes/TextAttributes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import AppKit

public struct TextAttributes {

// outline attributes
public static func outline(outlineWidth: CGFloat, outlineColor: NSColor) -> [NSAttributedString.Key: Any] {
[
NSAttributedString.Key.strokeColor: outlineColor,
NSAttributedString.Key.strokeWidth: outlineWidth,
]
}

// shadow attributes with all available shadow settings
public static func shadow(color: NSColor,
offsetX: CGFloat,
offsetY: CGFloat,
blur: CGFloat) -> [NSAttributedString.Key: Any] {
let textShadow = NSShadow()
textShadow.shadowColor = color
textShadow.shadowOffset = NSMakeSize(offsetX, offsetY)
textShadow.shadowBlurRadius = blur
return [
NSAttributedString.Key.shadow: textShadow,
]
}

// outline attributes plus shadow attributes with all available shadow settings
public static func outlineWithShadow(outlineWidth: CGFloat,
outlineColor: NSColor,
shadowColor: NSColor,
shadowOffsetX: CGFloat,
shadowOffsetY: CGFloat,
shadowBlur: CGFloat
) -> [NSAttributedString.Key: Any] {
let shadow = NSShadow()
shadow.shadowColor = shadowColor
shadow.shadowOffset = NSSize(width: shadowOffsetX,
height: shadowOffsetY)
shadow.shadowBlurRadius = shadowBlur

return [
.strokeColor: outlineColor,
.strokeWidth: outlineWidth,
.shadow: shadow
]
}

// currently used in the app
public static func defaultOutlineAttributes() -> [NSAttributedString.Key: Any] {
outline(outlineWidth: -1.5, outlineColor: NSColor.white)
}
}
33 changes: 33 additions & 0 deletions TextAnnotation/Classes/TextColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,36 @@ public struct TextColor: Codable, Equatable {
alpha: 1.0)
}
}

// colors from Zappy app
extension TextColor {
public static let orange: TextColor = {
return .colorFromRelative(red: 255.0, green: 74.0, blue: 1.0)
}()

public static let yellow: TextColor = {
return .colorFromRelative(red: 255.0, green: 196.0, blue: 62.0)
}()

public static let green: TextColor = {
return .colorFromRelative(red: 19.0, green: 208.0, blue: 171.0)
}()

public static let fuschia: TextColor = {
return .colorFromRelative(red: 252.0, green: 28.0, blue: 116.0)
}()

public static let violet: TextColor = {
return .colorFromRelative(red: 96.0, green: 97.0, blue: 237.0)
}()

static func colorFromRelative(red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat = 1.0) -> TextColor {
return TextColor(red: red / 255.0,
green: green / 255.0,
blue: blue / 255.0,
alpha: alpha)
}
}
Loading