mirror of
https://github.com/qvacua/vimr.git
synced 2024-09-11 17:15:34 +03:00
Make use of automatic conversion between CGFloat and Double
This commit is contained in:
parent
7f0b7936c5
commit
1e9fe40f9c
@ -7,12 +7,6 @@ import Foundation
|
||||
|
||||
public func identity<T>(_ input: T) -> T { input }
|
||||
|
||||
public extension BinaryFloatingPoint {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
var cgf: CGFloat { CGFloat(self) }
|
||||
}
|
||||
|
||||
public extension FixedWidthInteger {
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
|
@ -24,14 +24,14 @@ public class NvimView: NSView,
|
||||
|
||||
public static let rpcEventName = "com.qvacua.NvimView"
|
||||
|
||||
public static let minFontSize = 4.cgf
|
||||
public static let maxFontSize = 128.cgf
|
||||
public static let minFontSize = 4.0
|
||||
public static let maxFontSize = 128.0
|
||||
public static let defaultFont = NSFont.userFixedPitchFont(ofSize: 12)!
|
||||
public static let defaultLinespacing = 1.cgf
|
||||
public static let defaultCharacterspacing = 1.cgf
|
||||
public static let defaultLinespacing = 1.0
|
||||
public static let defaultCharacterspacing = 1.0
|
||||
|
||||
public static let minLinespacing = 0.5.cgf
|
||||
public static let maxLinespacing = 8.cgf
|
||||
public static let minLinespacing = 0.5
|
||||
public static let maxLinespacing = 8.0
|
||||
|
||||
public weak var delegate: NvimViewDelegate?
|
||||
|
||||
|
@ -346,12 +346,12 @@ extension AppearancePref {
|
||||
}
|
||||
|
||||
func linespacingAction() {
|
||||
let newLinespacing = self.cappedLinespacing(self.linespacingField.floatValue)
|
||||
let newLinespacing = self.cappedLinespacing(self.linespacingField.doubleValue)
|
||||
self.emit(.setLinespacing(newLinespacing))
|
||||
}
|
||||
|
||||
private func cappedLinespacing(_ linespacing: Float) -> CGFloat {
|
||||
let cgfLinespacing = linespacing.cgf
|
||||
private func cappedLinespacing(_ linespacing: Double) -> CGFloat {
|
||||
let cgfLinespacing = linespacing
|
||||
|
||||
guard cgfLinespacing >= NvimView.minLinespacing else { return NvimView.defaultLinespacing }
|
||||
guard cgfLinespacing <= NvimView.maxLinespacing else { return NvimView.maxLinespacing }
|
||||
@ -360,16 +360,14 @@ extension AppearancePref {
|
||||
}
|
||||
|
||||
func characterspacingAction() {
|
||||
let newCharacterspacing = self.cappedCharacterspacing(self.characterspacingField.floatValue)
|
||||
let newCharacterspacing = self.cappedCharacterspacing(self.characterspacingField.doubleValue)
|
||||
self.emit(.setCharacterspacing(newCharacterspacing))
|
||||
}
|
||||
|
||||
private func cappedCharacterspacing(_ characterspacing: Float) -> CGFloat {
|
||||
let cgfCharacterspacing = characterspacing.cgf
|
||||
private func cappedCharacterspacing(_ characterspacing: Double) -> Double {
|
||||
guard characterspacing >= 0.0 else { return NvimView.defaultCharacterspacing }
|
||||
|
||||
guard cgfCharacterspacing >= 0.0 else { return NvimView.defaultCharacterspacing }
|
||||
|
||||
return cgfCharacterspacing
|
||||
return characterspacing
|
||||
}
|
||||
|
||||
private func cappedFontSize(_ size: Int) -> CGFloat {
|
||||
|
@ -72,15 +72,15 @@ extension MainWindow {
|
||||
|
||||
case .setLinespacing:
|
||||
guard params.count == 1 else { return }
|
||||
guard let linespacing = params[0].floatValue else { return }
|
||||
guard let linespacing = params[0].doubleValue else { return }
|
||||
|
||||
self.emit(self.uuidAction(for: .setLinespacing(linespacing.cgf)))
|
||||
self.emit(self.uuidAction(for: .setLinespacing(linespacing)))
|
||||
|
||||
case .setCharacterspacing:
|
||||
guard params.count == 1 else { return }
|
||||
guard let characterspacing = params[0].floatValue else { return }
|
||||
guard let characterspacing = params[0].doubleValue else { return }
|
||||
|
||||
self.emit(self.uuidAction(for: .setCharacterspacing(characterspacing.cgf)))
|
||||
self.emit(self.uuidAction(for: .setCharacterspacing(characterspacing)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,6 @@ extension MainWindow {
|
||||
}
|
||||
}
|
||||
|
||||
private let repIconToTitleGap = 4.0.cgf
|
||||
private let repIconToTitleGap = 4.0
|
||||
private let titleBarHeight
|
||||
= CGFloat(ProcessInfo.processInfo.operatingSystemVersion.majorVersion >= 11 ? 28 : 22)
|
||||
|
@ -429,7 +429,7 @@ class MainWindow: NSObject,
|
||||
self.neoVimView.isRightOptionMeta = state.isRightOptionMeta
|
||||
|
||||
if self.neoVimView.trackpadScrollResistance
|
||||
!= state.trackpadScrollResistance.cgf
|
||||
!= state.trackpadScrollResistance
|
||||
{
|
||||
self.neoVimView.trackpadScrollResistance = CGFloat(
|
||||
state.trackpadScrollResistance
|
||||
|
@ -67,8 +67,8 @@ class PrefUtils {
|
||||
return editorFont
|
||||
}
|
||||
|
||||
static func saneLinespacing(_ fLinespacing: Float) -> CGFloat {
|
||||
let linespacing = fLinespacing.cgf
|
||||
static func saneLinespacing(_ fLinespacing: Double) -> Double {
|
||||
let linespacing = fLinespacing
|
||||
guard linespacing >= NvimView.minLinespacing, linespacing <= NvimView.maxLinespacing else {
|
||||
return NvimView.defaultLinespacing
|
||||
}
|
||||
@ -76,8 +76,8 @@ class PrefUtils {
|
||||
return linespacing
|
||||
}
|
||||
|
||||
static func saneCharacterspacing(_ fCharacterspacing: Float) -> CGFloat {
|
||||
let characterspacing = fCharacterspacing.cgf
|
||||
static func saneCharacterspacing(_ fCharacterspacing: Double) -> Double {
|
||||
let characterspacing = fCharacterspacing
|
||||
guard characterspacing >= 0.0 else {
|
||||
return NvimView.defaultCharacterspacing
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ struct AppearanceState: Codable {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
if let fontName = try container.decodeIfPresent(String.self, forKey: .editorFontName),
|
||||
let fontSize = try container.decodeIfPresent(Float.self, forKey: .editorFontSize),
|
||||
let font = NSFont(name: fontName, size: fontSize.cgf)
|
||||
let fontSize = try container.decodeIfPresent(Double.self, forKey: .editorFontSize),
|
||||
let font = NSFont(name: fontName, size: fontSize)
|
||||
{
|
||||
self.font = font
|
||||
} else {
|
||||
@ -207,13 +207,12 @@ struct AppearanceState: Codable {
|
||||
}
|
||||
|
||||
self
|
||||
.linespacing = (try container.decodeIfPresent(Float.self, forKey: .editorLinespacing) ?? 1.0)
|
||||
.cgf
|
||||
.linespacing = (try container.decodeIfPresent(Double.self, forKey: .editorLinespacing) ?? 1.0)
|
||||
self
|
||||
.characterspacing = (
|
||||
try container
|
||||
.decodeIfPresent(Float.self, forKey: .editorCharacterspacing) ?? 1.0
|
||||
).cgf
|
||||
.decodeIfPresent(Double.self, forKey: .editorCharacterspacing) ?? 1.0
|
||||
)
|
||||
self.usesLigatures = try container
|
||||
.decodeIfPresent(Bool.self, forKey: .editorUsesLigatures) ?? true
|
||||
|
||||
@ -477,7 +476,7 @@ struct WorkspaceToolState: Codable {
|
||||
self.dimension = try container.decode(
|
||||
forKey: .dimension,
|
||||
default: WorkspaceToolState.default.dimension
|
||||
).cgf
|
||||
)
|
||||
self.open = try container.decode(
|
||||
forKey: .open,
|
||||
default: WorkspaceToolState.default.open
|
||||
|
Loading…
Reference in New Issue
Block a user