mirror of
https://github.com/qvacua/vimr.git
synced 2025-01-01 10:16:24 +03:00
GH-436 Add repaint()
This commit is contained in:
parent
dd412985e3
commit
ae6a6bcf94
@ -104,6 +104,11 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
|
||||
self.addViews()
|
||||
}
|
||||
|
||||
func repaint() {
|
||||
self.layer!.backgroundColor = self.theme.toolbarBackground.cgColor
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
self.theme.separator.set()
|
||||
let bottomSeparatorRect = self.bottomSeparatorRect()
|
||||
|
@ -26,6 +26,11 @@ class ProxyWorkspaceBar: NSView {
|
||||
self.layer?.backgroundColor = self.theme.background.cgColor
|
||||
}
|
||||
|
||||
func repaint() {
|
||||
self.layer?.backgroundColor = self.theme.background.cgColor
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
let path = NSBezierPath(rect: self.bounds)
|
||||
path.lineWidth = 4
|
||||
|
@ -217,6 +217,12 @@ extension Workspace {
|
||||
// MARK: - Layout
|
||||
extension Workspace {
|
||||
|
||||
fileprivate func repaint() {
|
||||
self.bars.values.forEach { $0.repaint() }
|
||||
self.proxyBar.repaint()
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
fileprivate func relayout() {
|
||||
// FIXME: I did not investigate why toggleButtons does not work correctly if we store all constraints in an array
|
||||
// and remove them here by self.removeConstraints(${all constraints). The following seems to work...
|
||||
|
@ -90,7 +90,7 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
|
||||
self.configureForAutoLayout()
|
||||
|
||||
self.wantsLayer = true
|
||||
self.layer!.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
||||
self.layer!.backgroundColor = self.theme.barBackground.cgColor
|
||||
|
||||
self.proxyBar.container = self
|
||||
}
|
||||
@ -120,6 +120,12 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func repaint() {
|
||||
self.layer!.backgroundColor = self.theme.barBackground.cgColor
|
||||
self.tools.forEach { $0.repaint() }
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
func relayout() {
|
||||
self.removeConstraints(self.layoutConstraints)
|
||||
self.removeAllSubviews()
|
||||
|
@ -138,6 +138,13 @@ class WorkspaceTool: NSView {
|
||||
self.delegate?.toggle(self)
|
||||
}
|
||||
|
||||
func repaint() {
|
||||
self.button.repaint()
|
||||
self.innerToolbar?.repaint()
|
||||
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
fileprivate func addViews() {
|
||||
let view = self.view
|
||||
self.addSubview(view)
|
||||
|
@ -10,7 +10,9 @@ class WorkspaceToolButton: NSView, NSDraggingSource {
|
||||
static fileprivate let titlePadding = CGSize(width: 8, height: 2)
|
||||
static fileprivate let dummyButton = WorkspaceToolButton(title: "Dummy")
|
||||
|
||||
fileprivate let title: NSAttributedString
|
||||
fileprivate var isHighlighted = false
|
||||
|
||||
fileprivate let title: NSMutableAttributedString
|
||||
fileprivate var trackingArea = NSTrackingArea()
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
@ -54,21 +56,40 @@ class WorkspaceToolButton: NSView, NSDraggingSource {
|
||||
}
|
||||
|
||||
init(title: String) {
|
||||
self.title = NSAttributedString(string: title, attributes: [
|
||||
NSFontAttributeName: NSFont.systemFont(ofSize: 11)
|
||||
self.title = NSMutableAttributedString(string: title, attributes: [
|
||||
NSFontAttributeName: NSFont.systemFont(ofSize: 11),
|
||||
])
|
||||
|
||||
super.init(frame: CGRect.zero)
|
||||
super.init(frame: .zero)
|
||||
self.configureForAutoLayout()
|
||||
|
||||
self.title.addAttribute(NSForegroundColorAttributeName,
|
||||
value: self.theme.foreground,
|
||||
range: NSRange(location: 0, length: self.title.length))
|
||||
|
||||
self.wantsLayer = true
|
||||
}
|
||||
|
||||
func repaint() {
|
||||
if self.isHighlighted {
|
||||
self.highlight()
|
||||
} else {
|
||||
self.dehighlight()
|
||||
}
|
||||
|
||||
self.title.setAttributes([NSForegroundColorAttributeName: self.theme.foreground],
|
||||
range: NSRange(location: 0, length: self.title.length))
|
||||
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
func highlight() {
|
||||
self.isHighlighted = true
|
||||
self.layer?.backgroundColor = self.theme.barButtonHighlight.cgColor
|
||||
}
|
||||
|
||||
func dehighlight() {
|
||||
self.isHighlighted = false
|
||||
self.layer?.backgroundColor = self.theme.barButtonBackground.cgColor
|
||||
}
|
||||
}
|
||||
@ -130,7 +151,7 @@ extension WorkspaceToolButton {
|
||||
pasteboardItem.setString(self.tool!.uuid, forType: WorkspaceToolButton.toolUti)
|
||||
|
||||
let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem)
|
||||
draggingItem.setDraggingFrame(self.bounds, contents:self.snapshot())
|
||||
draggingItem.setDraggingFrame(self.bounds, contents: self.snapshot())
|
||||
|
||||
self.beginDraggingSession(with: [draggingItem], event: event, source: self)
|
||||
return
|
||||
@ -181,12 +202,12 @@ extension WorkspaceToolButton {
|
||||
// MARK: - NSDraggingSource
|
||||
extension WorkspaceToolButton {
|
||||
|
||||
@objc(draggingSession:sourceOperationMaskForDraggingContext:)
|
||||
@objc(draggingSession: sourceOperationMaskForDraggingContext:)
|
||||
func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor ctc: NSDraggingContext) -> NSDragOperation {
|
||||
return .move
|
||||
}
|
||||
|
||||
@objc(draggingSession:endedAtPoint:operation:)
|
||||
@objc(draggingSession: endedAtPoint:operation:)
|
||||
func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
|
||||
guard let pointInWindow = self.window?.convertFromScreen(CGRect(origin: screenPoint, size: .zero)) else {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user