1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 10:02:36 +03:00

GH-436 Use theme struct when drawing

This commit is contained in:
Tae Won Ha 2017-06-24 17:58:21 +02:00
parent 3cc03cf403
commit dd412985e3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
7 changed files with 34 additions and 10 deletions

View File

@ -67,6 +67,10 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
}
}
var theme: WorkspaceTheme {
return self.tool?.theme ?? WorkspaceTheme.default
}
weak var tool: WorkspaceTool? {
didSet {
self.titleField.stringValue = self.tool?.title ?? ""
@ -95,18 +99,19 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
// Because other views also want layer, this view also must want layer. Otherwise the z-index ordering is not set
// correctly: views w/ wantsLayer = false are behind views w/ wantsLayer = true even when added later.
self.wantsLayer = true
self.layer?.backgroundColor = InnerToolBar.backgroundColor.cgColor
self.layer?.backgroundColor = self.theme.toolbarBackground.cgColor
self.addViews()
}
override func draw(_ dirtyRect: NSRect) {
InnerToolBar.separatorColor.set()
self.theme.separator.set()
let bottomSeparatorRect = self.bottomSeparatorRect()
if dirtyRect.intersects(bottomSeparatorRect) {
NSRectFill(bottomSeparatorRect)
}
self.theme.toolbarForeground.set()
let innerSeparatorRect = self.innerSeparatorRect()
if dirtyRect.intersects(innerSeparatorRect) {
NSRectFill(innerSeparatorRect)

View File

@ -11,6 +11,8 @@ import PureLayout
*/
class ProxyWorkspaceBar: NSView {
var theme = WorkspaceTheme.default
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@ -21,13 +23,13 @@ class ProxyWorkspaceBar: NSView {
// Because other views also want layer, this view also must want layer. Otherwise the z-index ordering is not set
// correctly: views w/ wantsLayer = false are behind views w/ wantsLayer = true even when added later.
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
self.layer?.backgroundColor = self.theme.background.cgColor
}
override func draw(_ dirtyRect: NSRect) {
let path = NSBezierPath(rect: self.bounds)
path.lineWidth = 4
NSColor.selectedControlColor.set()
self.theme.barFocusRing.set()
path.stroke()
}
}

View File

@ -60,6 +60,7 @@ class Workspace: NSView, WorkspaceBarDelegate {
let mainView: NSView
let bars: [WorkspaceBarLocation: WorkspaceBar]
let config: Config
var theme = WorkspaceTheme.default
weak var delegate: WorkspaceDelegate?

View File

@ -46,7 +46,6 @@ fileprivate class ProxyBar: NSView {
class WorkspaceBar: NSView, WorkspaceToolDelegate {
static fileprivate let separatorColor = NSColor.controlShadowColor
static fileprivate let separatorThickness = CGFloat(1)
fileprivate(set) var tools = [WorkspaceTool]()
@ -77,6 +76,10 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
}
var dimensionConstraint = NSLayoutConstraint()
var theme: WorkspaceTheme {
return self.workspace?.theme ?? WorkspaceTheme.default
}
weak var delegate: WorkspaceBarDelegate?
weak var workspace: Workspace?
@ -469,7 +472,7 @@ extension WorkspaceBar {
}
fileprivate func drawInnerSeparator(_ dirtyRect: NSRect) {
WorkspaceBar.separatorColor.set()
self.theme.separator.set()
let innerLineRect = self.innerSeparatorRect()
if dirtyRect.intersects(innerLineRect) {
@ -478,7 +481,7 @@ extension WorkspaceBar {
}
fileprivate func drawOuterSeparator(_ dirtyRect: NSRect) {
WorkspaceBar.separatorColor.set()
self.theme.separator.set()
let outerLineRect = self.outerSeparatorRect()
if dirtyRect.intersects(outerLineRect) {

View File

@ -50,6 +50,10 @@ class WorkspaceTool: NSView {
}
}
var theme: WorkspaceTheme {
return self.bar?.theme ?? WorkspaceTheme.default
}
weak var delegate: WorkspaceToolDelegate?
weak var bar: WorkspaceBar?

View File

@ -33,6 +33,10 @@ class WorkspaceToolButton: NSView, NSDraggingSource {
return self.tool?.isSelected ?? false
}
var theme: WorkspaceTheme {
return self.tool?.theme ?? WorkspaceTheme.default
}
weak var tool: WorkspaceTool?
static func dimension() -> CGFloat {
@ -61,11 +65,11 @@ class WorkspaceToolButton: NSView, NSDraggingSource {
}
func highlight() {
self.layer?.backgroundColor = NSColor.controlShadowColor.cgColor
self.layer?.backgroundColor = self.theme.barButtonHighlight.cgColor
}
func dehighlight() {
self.layer?.backgroundColor = NSColor.clear.cgColor
self.layer?.backgroundColor = self.theme.barButtonBackground.cgColor
}
}
@ -165,7 +169,7 @@ extension WorkspaceToolButton {
result.size = rect.size
result.lockFocus()
NSColor.controlShadowColor.set()
self.theme.barButtonHighlight.set()
NSRectFill(rect)
image.draw(in: rect)
result.unlockFocus()

View File

@ -7,12 +7,17 @@ import Cocoa
struct WorkspaceTheme {
static let `default` = WorkspaceTheme()
var foreground = NSColor.black
var background = NSColor.white
var separator = NSColor.controlShadowColor
var barBackground = NSColor.windowBackgroundColor
var barFocusRing = NSColor.selectedControlColor
var barButtonBackground = NSColor.clear
var barButtonHighlight = NSColor.controlShadowColor
var toolbarForeground = NSColor.darkGray