1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

GH-223 Add rudimentary pinch support

This commit is contained in:
Tae Won Ha 2016-07-29 18:25:32 +02:00
parent f9a021d97d
commit da0720f169
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 33 additions and 4 deletions

View File

@ -18,10 +18,16 @@ private struct RowRun: CustomStringConvertible {
}
public class NeoVimView: NSView {
public static let minFontSize = CGFloat(4)
public static let maxFontSize = CGFloat(128)
public static let defaultFont = NSFont(name: "Menlo", size: 13)!
public let uuid = NSUUID().UUIDString
public weak var delegate: NeoVimViewDelegate?
private let fontManager = NSFontManager.sharedFontManager()
private let agent: NeoVimAgent
private let grid = Grid()
@ -78,7 +84,7 @@ public class NeoVimView: NSView {
}
override init(frame rect: NSRect = CGRect.zero) {
self._font = NSFont(name: "Menlo", size: 13)!
self._font = NeoVimView.defaultFont
self.drawer = TextDrawer(font: self._font)
self.agent = NeoVimAgent(uuid: self.uuid)
@ -520,6 +526,29 @@ extension NeoVimView: NSTextInputClient {
}
}
// MARK: - Gesture Events
extension NeoVimView {
override public func magnifyWithEvent(event: NSEvent) {
let factor = 1 + event.magnification
let targetSize = self.capFontSize(round(self._font.pointSize * factor))
self.font = self.fontManager.convertFont(self._font, toSize: targetSize)
}
private func capFontSize(size: CGFloat) -> CGFloat {
guard size >= NeoVimView.minFontSize else {
return NeoVimView.minFontSize
}
guard size <= NeoVimView.maxFontSize else {
return NeoVimView.maxFontSize
}
return size
}
}
// MARK: - Mouse Events
extension NeoVimView {

View File

@ -15,9 +15,9 @@ private class PrefKeys {
class PrefStore: Store {
private static let compatibleVersion = "38"
private static let defaultEditorFont = NSFont(name: "Menlo", size: 13)!
static let minimumEditorFontSize = CGFloat(4)
static let maximumEditorFontSize = CGFloat(128)
private static let defaultEditorFont = NeoVimView.defaultFont
static let minimumEditorFontSize = NeoVimView.maxFontSize
static let maximumEditorFontSize = NeoVimView.minFontSize
private let source: Observable<Any>
private let disposeBag = DisposeBag()