mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 03:25:03 +03:00
Add SOME_NUMBER.cgf
This commit is contained in:
parent
24e1dc529d
commit
fa15b4cea3
@ -9,7 +9,10 @@ import CocoaMarkdown
|
||||
extension NSColor {
|
||||
|
||||
static var random: NSColor {
|
||||
return NSColor(calibratedRed: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0)
|
||||
return NSColor(calibratedRed: CGFloat.random(in: 0...1),
|
||||
green: CGFloat.random(in: 0...1),
|
||||
blue: CGFloat.random(in: 0...1),
|
||||
alpha: 1.0)
|
||||
}
|
||||
|
||||
var hex: String {
|
||||
|
@ -316,7 +316,7 @@ extension AppearancePref {
|
||||
}
|
||||
|
||||
private func cappedLinespacing(_ linespacing: Float) -> CGFloat {
|
||||
let cgfLinespacing = CGFloat(linespacing)
|
||||
let cgfLinespacing = linespacing.cgf
|
||||
|
||||
guard cgfLinespacing >= NvimView.minLinespacing else {
|
||||
return NvimView.defaultLinespacing
|
||||
@ -330,7 +330,7 @@ extension AppearancePref {
|
||||
}
|
||||
|
||||
private func cappedFontSize(_ size: Int) -> CGFloat {
|
||||
let cgfSize = CGFloat(size)
|
||||
let cgfSize = size.cgf
|
||||
|
||||
guard cgfSize >= NvimView.minFontSize else {
|
||||
return NvimView.defaultFont.pointSize
|
||||
|
@ -179,7 +179,7 @@ extension BuffersList {
|
||||
}
|
||||
|
||||
self.bufferList.tableColumns[0].width = max(
|
||||
self.bufferList.tableColumns[0].width, cellWidth + CGFloat(10)
|
||||
self.bufferList.tableColumns[0].width, cellWidth + 10.cgf
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ class FileOutlineView: NSOutlineView,
|
||||
}
|
||||
private let treeController = NSTreeController()
|
||||
|
||||
private var cachedColumnWidth = CGFloat(20)
|
||||
private var cachedColumnWidth = 20.cgf
|
||||
private var usesTheme: Bool
|
||||
private var lastFileSystemUpdateMark = Token()
|
||||
private var showsFileIcon: Bool
|
||||
@ -555,7 +555,7 @@ extension FileOutlineView {
|
||||
return
|
||||
}
|
||||
|
||||
let level = CGFloat(self.level(forRow: row))
|
||||
let level = self.level(forRow: row).cgf
|
||||
let width = level * self.indentationPerLevel + cellWidth
|
||||
+ columnWidthRightPadding
|
||||
self.cachedColumnWidth = max(self.cachedColumnWidth, width)
|
||||
@ -667,5 +667,5 @@ private extension NSTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
private let columnWidthRightPadding = CGFloat(40)
|
||||
private let triangleImageSize = CGFloat(18)
|
||||
private let columnWidthRightPadding = 40.cgf
|
||||
private let triangleImageSize = 18.cgf
|
||||
|
@ -17,7 +17,7 @@ class ImageAndTextTableCell: NSTableCellView {
|
||||
|
||||
// MARK: - API
|
||||
static let font = NSFont.systemFont(ofSize: 12)
|
||||
static let widthWithoutText = CGFloat(2 + 16 + 4 + 2)
|
||||
static let widthWithoutText = (2 + 16 + 4 + 2).cgf
|
||||
|
||||
static func width(with text: String) -> CGFloat {
|
||||
let attrStr = NSAttributedString(string: text, attributes: [NSAttributedString.Key.font: ImageAndTextTableCell.font])
|
||||
|
@ -61,7 +61,7 @@ extension MainWindow {
|
||||
guard params.count == 2 else { return }
|
||||
guard let fontName = params[0].stringValue,
|
||||
let fontSize = params[1].integerValue,
|
||||
let font = NSFont(name: fontName, size: CGFloat(fontSize))
|
||||
let font = NSFont(name: fontName, size: fontSize.cgf)
|
||||
else {
|
||||
return
|
||||
}
|
||||
@ -72,7 +72,7 @@ extension MainWindow {
|
||||
guard params.count == 1 else { return }
|
||||
guard let linespacing = params[0].floatValue else { return }
|
||||
|
||||
self.emit(self.uuidAction(for: .setLinespacing(CGFloat(linespacing))))
|
||||
self.emit(self.uuidAction(for: .setLinespacing(linespacing.cgf)))
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -149,4 +149,4 @@ extension MainWindow {
|
||||
}
|
||||
}
|
||||
|
||||
private let repIconToTitleGap = CGFloat(4.0)
|
||||
private let repIconToTitleGap = (4.0).cgf
|
||||
|
@ -97,14 +97,17 @@ class MainWindow: NSObject,
|
||||
}
|
||||
|
||||
if state.activeTools[.htmlPreview] == true {
|
||||
self.htmlPreview = HtmlPreviewTool(source: source, emitter: emitter, state: state)
|
||||
self.htmlPreview = HtmlPreviewTool(source: source,
|
||||
emitter: emitter,
|
||||
state: state)
|
||||
let htmlPreviewConfig = WorkspaceTool.Config(
|
||||
title: "HTML",
|
||||
view: self.htmlPreview!,
|
||||
customToolbar: self.htmlPreview!.innerCustomToolbar
|
||||
)
|
||||
self.htmlPreviewContainer = WorkspaceTool(htmlPreviewConfig)
|
||||
self.htmlPreviewContainer!.dimension = state.tools[.htmlPreview]?.dimension ?? 250
|
||||
self.htmlPreviewContainer!.dimension = state.tools[.htmlPreview]?
|
||||
.dimension ?? 250
|
||||
tools[.htmlPreview] = self.htmlPreviewContainer
|
||||
}
|
||||
|
||||
@ -318,7 +321,8 @@ class MainWindow: NSObject,
|
||||
.andThen {
|
||||
if state.preview.status == .markdown
|
||||
&& state.previewTool.isReverseSearchAutomatically
|
||||
&& state.preview.previewPosition.hasDifferentMark(as: self.previewPosition) {
|
||||
&& state.preview.previewPosition
|
||||
.hasDifferentMark(as: self.previewPosition) {
|
||||
|
||||
self.previewPosition = state.preview.previewPosition
|
||||
return self.neoVimView.cursorGo(
|
||||
@ -387,8 +391,11 @@ class MainWindow: NSObject,
|
||||
self.neoVimView.isLeftOptionMeta = state.isLeftOptionMeta
|
||||
self.neoVimView.isRightOptionMeta = state.isRightOptionMeta
|
||||
|
||||
if self.neoVimView.trackpadScrollResistance != CGFloat(state.trackpadScrollResistance) {
|
||||
self.neoVimView.trackpadScrollResistance = CGFloat(state.trackpadScrollResistance)
|
||||
if self.neoVimView.trackpadScrollResistance
|
||||
!= state.trackpadScrollResistance.cgf {
|
||||
self.neoVimView.trackpadScrollResistance = CGFloat(
|
||||
state.trackpadScrollResistance
|
||||
)
|
||||
}
|
||||
|
||||
if self.neoVimView.usesLiveResize != state.useLiveResize {
|
||||
|
@ -93,7 +93,7 @@ class PrefUtils {
|
||||
}
|
||||
|
||||
static func saneLinespacing(_ fLinespacing: Float) -> CGFloat {
|
||||
let linespacing = CGFloat(fLinespacing)
|
||||
let linespacing = fLinespacing.cgf
|
||||
guard linespacing >= NvimView.minLinespacing && linespacing <= NvimView.maxLinespacing else {
|
||||
return NvimView.defaultLinespacing
|
||||
}
|
||||
|
@ -193,13 +193,13 @@ struct AppearanceState: Codable {
|
||||
|
||||
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: CGFloat(fontSize)) {
|
||||
let font = NSFont(name: fontName, size: fontSize.cgf) {
|
||||
self.font = font
|
||||
} else {
|
||||
self.font = NvimView.defaultFont
|
||||
}
|
||||
|
||||
self.linespacing = CGFloat(try container.decodeIfPresent(Float.self, forKey: .editorLinespacing) ?? 1.0)
|
||||
self.linespacing = (try container.decodeIfPresent(Float.self, forKey: .editorLinespacing) ?? 1.0).cgf
|
||||
self.usesLigatures = try container.decodeIfPresent(Bool.self, forKey: .editorUsesLigatures) ?? true
|
||||
|
||||
self.usesTheme = try container.decodeIfPresent(Bool.self, forKey: .usesTheme) ?? true
|
||||
@ -414,15 +414,24 @@ struct WorkspaceToolState: Codable {
|
||||
}
|
||||
|
||||
var location = WorkspaceBarLocation.left
|
||||
var dimension = CGFloat(200)
|
||||
var dimension = 200.cgf
|
||||
var open = false
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
self.location = try container.decode(forKey: .location, default: WorkspaceToolState.default.location)
|
||||
self.dimension = CGFloat(try container.decode(forKey: .dimension, default: WorkspaceToolState.default.dimension))
|
||||
self.open = try container.decode(forKey: .open, default: WorkspaceToolState.default.open)
|
||||
self.location = try container.decode(
|
||||
forKey: .location,
|
||||
default: WorkspaceToolState.default.location
|
||||
)
|
||||
self.dimension = try container.decode(
|
||||
forKey: .dimension,
|
||||
default: WorkspaceToolState.default.dimension
|
||||
).cgf
|
||||
self.open = try container.decode(
|
||||
forKey: .open,
|
||||
default: WorkspaceToolState.default.open
|
||||
)
|
||||
}
|
||||
|
||||
// Use generated encode(to:)
|
||||
|
@ -9,6 +9,20 @@ func identity<T>(_ input: T) -> T {
|
||||
return input
|
||||
}
|
||||
|
||||
extension BinaryFloatingPoint {
|
||||
|
||||
var cgf: CGFloat {
|
||||
return CGFloat(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension FixedWidthInteger {
|
||||
|
||||
var cgf: CGFloat {
|
||||
return CGFloat(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
|
||||
func without(prefix: String) -> String {
|
||||
|
@ -67,7 +67,7 @@ class ThemedTableCell: NSTableCellView {
|
||||
|
||||
// MARK: - API
|
||||
static let font = NSFont.systemFont(ofSize: 12)
|
||||
static let widthWithoutText = CGFloat(2 + 16 + 4 + 2)
|
||||
static let widthWithoutText = (2 + 16 + 4 + 2).cgf
|
||||
|
||||
// static func width(with text: String) -> CGFloat {
|
||||
// let attrStr = NSAttributedString(string: text, attributes: [NSAttributedString.Key.font: ThemedTableCell.font])
|
||||
|
@ -23,8 +23,8 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
|
||||
|
||||
// MARK: - API
|
||||
static let toolbarHeight = InnerToolBar.iconDimension
|
||||
static let iconDimension = CGFloat(18)
|
||||
static let itemPadding = CGFloat(4)
|
||||
static let iconDimension = 18.cgf
|
||||
static let itemPadding = 4.cgf
|
||||
|
||||
static func configureToStandardIconButton(
|
||||
button: NSButton,
|
||||
@ -138,7 +138,7 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private static let separatorThickness = CGFloat(1)
|
||||
private static let separatorThickness = 1.cgf
|
||||
private static let height = InnerToolBar.iconDimension + 2 + 2 + InnerToolBar.separatorThickness
|
||||
|
||||
private let titleField = NSTextField(forAutoLayout: ())
|
||||
|
@ -51,14 +51,14 @@ private class ProxyBar: NSView {
|
||||
|
||||
class WorkspaceBar: NSView, WorkspaceToolDelegate {
|
||||
|
||||
static private let separatorThickness = CGFloat(1)
|
||||
static private let separatorThickness = 1.cgf
|
||||
|
||||
fileprivate(set) var tools = [WorkspaceTool]()
|
||||
|
||||
private weak var selectedTool: WorkspaceTool?
|
||||
|
||||
private var isMouseDownOngoing = false
|
||||
private var dragIncrement = CGFloat(1)
|
||||
private var dragIncrement = 1.cgf
|
||||
|
||||
private var layoutConstraints = [NSLayoutConstraint]()
|
||||
|
||||
@ -69,7 +69,7 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
|
||||
}
|
||||
|
||||
// MARK: - API
|
||||
static let minimumDimension = CGFloat(50)
|
||||
static let minimumDimension = 50.cgf
|
||||
|
||||
let location: WorkspaceBarLocation
|
||||
var isButtonVisible = true {
|
||||
@ -567,7 +567,7 @@ extension WorkspaceBar {
|
||||
|
||||
private func resizeRect() -> CGRect {
|
||||
let separatorRect = self.outerSeparatorRect()
|
||||
let clickDimension = CGFloat(4)
|
||||
let clickDimension = 4.cgf
|
||||
|
||||
switch self.location {
|
||||
case .top:
|
||||
|
Loading…
Reference in New Issue
Block a user