mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-25 06:06:21 +03:00
53 lines
1.5 KiB
Swift
53 lines
1.5 KiB
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Cocoa
|
|
|
|
extension NeoVimView {
|
|
|
|
override public func setFrameSize(_ newSize: NSSize) {
|
|
super.setFrameSize(newSize)
|
|
|
|
// initial resizing is done when grid has data
|
|
guard self.grid.hasData else {
|
|
return
|
|
}
|
|
|
|
if self.inLiveResize || self.currentlyResizing {
|
|
// TODO: Turn off live resizing for now.
|
|
// self.resizeNeoVimUi(to: newSize)
|
|
return
|
|
}
|
|
|
|
// There can be cases where the frame is resized not by live resizing,
|
|
// eg when the window is resized by window management tools.
|
|
// Thus, we make sure that the resize call is made when this happens.
|
|
self.resizeNeoVimUi(to: newSize)
|
|
}
|
|
|
|
override public func viewDidEndLiveResize() {
|
|
super.viewDidEndLiveResize()
|
|
self.resizeNeoVimUi(to: self.bounds.size)
|
|
}
|
|
|
|
func discreteSize(size: CGSize) -> Size {
|
|
return Size(width: Int(floor(size.width / self.cellSize.width)),
|
|
height: Int(floor(size.height / self.cellSize.height)))
|
|
}
|
|
|
|
func resizeNeoVimUi(to size: CGSize) {
|
|
self.currentEmoji = self.randomEmoji()
|
|
|
|
let discreteSize = self.discreteSize(size: size)
|
|
if discreteSize == self.grid.size {
|
|
return
|
|
}
|
|
|
|
self.xOffset = floor((size.width - self.cellSize.width * CGFloat(discreteSize.width)) / 2)
|
|
self.yOffset = floor((size.height - self.cellSize.height * CGFloat(discreteSize.height)) / 2)
|
|
|
|
self.agent.resize(toWidth: Int32(discreteSize.width), height: Int32(discreteSize.height))
|
|
}
|
|
} |