editor tool fixes
This commit is contained in:
@@ -26,6 +26,7 @@ final class EditorWindowController: NSWindowController, NSWindowDelegate,
|
||||
private var toolButtons: [ToolKind: NSButton] = [:]
|
||||
private var deleteButton: NSButton?
|
||||
private let currentColorWell = NSColorWell()
|
||||
private let fillColorWell = NSColorWell()
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
@@ -221,16 +222,30 @@ final class EditorWindowController: NSWindowController, NSWindowDelegate,
|
||||
delete.heightAnchor.constraint(equalToConstant: 28).isActive = true
|
||||
deleteButton = delete
|
||||
|
||||
// Current colour, shown the way an editor shows its foreground swatch.
|
||||
// Line and fill colour, the way an editor shows foreground and background swatches.
|
||||
currentColorWell.color = Configuration.shared.editorLineColor
|
||||
currentColorWell.target = self
|
||||
currentColorWell.action = #selector(currentColorChanged)
|
||||
currentColorWell.toolTip = "Current colour"
|
||||
currentColorWell.toolTip = "Line colour"
|
||||
currentColorWell.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
currentColorWell.widthAnchor.constraint(equalToConstant: 44),
|
||||
currentColorWell.heightAnchor.constraint(equalToConstant: 26)
|
||||
])
|
||||
|
||||
fillColorWell.color = Configuration.shared.editorFillColor
|
||||
fillColorWell.target = self
|
||||
fillColorWell.action = #selector(fillColorChanged)
|
||||
fillColorWell.toolTip = "Fill colour"
|
||||
fillColorWell.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
for well in [currentColorWell, fillColorWell] {
|
||||
NSLayoutConstraint.activate([
|
||||
well.widthAnchor.constraint(equalToConstant: 26),
|
||||
well.heightAnchor.constraint(equalToConstant: 24)
|
||||
])
|
||||
}
|
||||
|
||||
let wells = NSStackView(views: [currentColorWell, fillColorWell])
|
||||
wells.orientation = .horizontal
|
||||
wells.spacing = 4
|
||||
wells.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
var swatchRows: [[NSView]] = []
|
||||
var swatchPair: [NSView] = []
|
||||
@@ -259,7 +274,7 @@ final class EditorWindowController: NSWindowController, NSWindowDelegate,
|
||||
EditorWindowController.railDivider(),
|
||||
delete,
|
||||
EditorWindowController.railDivider(),
|
||||
currentColorWell,
|
||||
wells,
|
||||
swatchGrid,
|
||||
spacer])
|
||||
stack.orientation = .vertical
|
||||
@@ -392,6 +407,12 @@ final class EditorWindowController: NSWindowController, NSWindowDelegate,
|
||||
apply(color: currentColorWell.color)
|
||||
}
|
||||
|
||||
@objc private func fillColorChanged() {
|
||||
let color = fillColorWell.color
|
||||
Configuration.shared.editorFillColor = color
|
||||
canvas.applyStyleToSelection { $0.fillColor = color }
|
||||
}
|
||||
|
||||
private func apply(color: NSColor) {
|
||||
// The highlighter has its own colour field; everything else uses the line colour.
|
||||
let isHighlight = canvas.tool == .highlight || surface.selection is HighlightElement
|
||||
@@ -423,9 +444,12 @@ final class EditorWindowController: NSWindowController, NSWindowDelegate,
|
||||
}
|
||||
styleBar.update(capabilities: capabilities,
|
||||
style: style,
|
||||
showCrop: surface.cropElement != nil)
|
||||
showCrop: surface.cropElement != nil,
|
||||
toolName: canvas.tool.title)
|
||||
deleteButton?.isEnabled = surface.selection != nil
|
||||
currentColorWell.color = capabilities.contains(.highlightColor) ? style.highlightColor : style.lineColor
|
||||
fillColorWell.color = style.fillColor
|
||||
fillColorWell.isEnabled = capabilities.contains(.fillColor)
|
||||
}
|
||||
|
||||
private func capabilitiesForTool(_ tool: ToolKind) -> StyleCapabilities {
|
||||
|
||||
Reference in New Issue
Block a user