Skip to content

Commit

Permalink
Merge pull request #15 from yuzawa-san/use-system-font
Browse files Browse the repository at this point in the history
use system font size
  • Loading branch information
yuzawa-san authored Dec 28, 2022
2 parents 034a88b + c98934e commit 0865c9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions Polyhedra/PolyhedraFullLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PolyhedraFullLayer: CALayer {
private var rotation: Int = .zero
private var frameNumber: Int = .zero

public init(size: CGSize, fps: Int) {
public init(size: CGSize, fps: Int, isPreview: Bool) {
let settings = PolyhedraSettings()
self.polyhedraLayer = CALayer()
self.polyhedraLayer.isOpaque = true
Expand All @@ -41,15 +41,16 @@ class PolyhedraFullLayer: CALayer {
super.init()
self.isOpaque = true
addSublayer(polyhedraLayer)
if settings.shouldShowPolyhedronName() {
let fontSize: CGFloat = CGFloat(radius) * 0.15
if !isPreview && settings.shouldShowPolyhedronName() {
// configure text
let font = NSFont.systemFont(ofSize: fontSize)
let font = NSFont.menuBarFont(ofSize: -1)
let fontSize = font.pointSize
let textLayer = CATextLayer()
textLayer.contentsScale = Polyhedron.scale
let name = polyhedron.name
let stringSize = name.size(withAttributes: [.font: font])
textLayer.frame = CGRect(origin: CGPoint(x: fontSize, y: fontSize), size: stringSize)
let textOffset = CGFloat(radius) * 0.1
textLayer.frame = CGRect(origin: CGPoint(x: textOffset, y: textOffset), size: stringSize)
textLayer.font = font
textLayer.fontSize = fontSize
textLayer.alignmentMode = .left
Expand Down
2 changes: 1 addition & 1 deletion Polyhedra/PolyhedraScreenSaverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PolyhedraScreenSaverView: ScreenSaverView {
override func startAnimation() {
let fps = PolyhedraScreenSaverView.calculateFramesPerSecond()
animationTimeInterval = 1.0 / Double(fps)
let polyhedronScreenSaverLayer = PolyhedraFullLayer(size: frame.size, fps: fps)
let polyhedronScreenSaverLayer = PolyhedraFullLayer(size: frame.size, fps: fps, isPreview: isPreview)
layer?.drawsAsynchronously = true
layer?.isOpaque = true
layer?.addSublayer(polyhedronScreenSaverLayer)
Expand Down

0 comments on commit 0865c9e

Please sign in to comment.