Skip to content

Commit

Permalink
Merge branch 'fix/auto-scroll' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
MainasuK committed Nov 22, 2020
2 parents 4e8e85b + a37cb23 commit d31466e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Song Rating.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -776,15 +776,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_TEAM = A8K92XFF77;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Song Rating/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -804,15 +804,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_TEAM = A8K92XFF77;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Song Rating/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.2.5;
MARKETING_VERSION = 1.3.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.mainasuk.Song-Rating";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
27 changes: 17 additions & 10 deletions Song Rating/Views/AutoScrollTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,24 @@ extension AutoScrollTextField {
var transfrom = AffineTransform()
transfrom.scale(x: 1.0, y: -1.0)
transfrom.translate(x: leftMargin-offsetX, y: -bounds.height + abs(font!.descender))

path.transform(using: transfrom)

let textColor = self.textColor ?? NSColor.labelColor

let leftGradientStart = (offsetX-leftMargin) / path.bounds.width
let leftGradientEnd = offsetX / path.bounds.width

let rightGradientStart = (bounds.width - rightMargin - leftMargin + offsetX) / path.bounds.width
let rightGradientEnd = (bounds.width - leftMargin + offsetX) / path.bounds.width

let gradient = NSGradient(colorsAndLocations:
(textColor.withAlphaComponent(0), leftGradientStart),
(textColor, leftGradientEnd),
(textColor, rightGradientStart),
(textColor.withAlphaComponent(0), rightGradientEnd)
)

textColor.setFill()
gradient?.draw(in: path, angle: 0)
}
Expand All @@ -143,18 +143,25 @@ extension AutoScrollTextField {
final class BezierLayoutManager: NSLayoutManager {

var path: NSBezierPath?

// note: this method may call multiple times to show entity string
override func showCGGlyphs(_ glyphs: UnsafePointer<CGGlyph>, positions: UnsafePointer<NSPoint>, count glyphCount: Int, font: NSFont, matrix textMatrix: AffineTransform, attributes: [NSAttributedString.Key : Any] = [:], in graphicsContext: NSGraphicsContext) {

override func showCGGlyphs(
_ glyphs: UnsafePointer<CGGlyph>,
positions: UnsafePointer<CGPoint>,
count glyphCount: Int,
font: NSFont,
textMatrix: CGAffineTransform,
attributes: [NSAttributedString.Key : Any] = [:],
in CGContext: CGContext
) {
if path == nil {
path = NSBezierPath()
path?.move(to: .zero)
}

path?.append(withCGGlyphs: glyphs, count: glyphCount, in: font)
}

}

#if canImport(SwiftUI) && DEBUG
Expand Down

0 comments on commit d31466e

Please sign in to comment.