| | |
| | | var id: String { name } |
| | | let name: String |
| | | let colorIndex: Int |
| | | let customColor: TagCustomColor? |
| | | } |
| | | |
| | | struct TagNavigationView: NSViewRepresentable { |
| | |
| | | let appDragModeActive: Bool |
| | | let appDropTargetID: String? |
| | | let onActivate: (String) -> Void |
| | | let onDoubleActivate: (String) -> Void |
| | | let onHoverChange: (String, Bool) -> Void |
| | | let canReorder: (String) -> Bool |
| | | let canAcceptAppDrop: (String) -> Bool |
| | |
| | | appDragModeActive: appDragModeActive, |
| | | appDropTargetID: appDropTargetID, |
| | | onActivate: onActivate, |
| | | onDoubleActivate: onDoubleActivate, |
| | | onHoverChange: onHoverChange, |
| | | canReorder: canReorder, |
| | | canAcceptAppDrop: canAcceptAppDrop, |
| | |
| | | appDragModeActive: appDragModeActive, |
| | | appDropTargetID: appDropTargetID, |
| | | onActivate: onActivate, |
| | | onDoubleActivate: onDoubleActivate, |
| | | onHoverChange: onHoverChange, |
| | | canReorder: canReorder, |
| | | canAcceptAppDrop: canAcceptAppDrop, |
| | |
| | | appDragModeActive: Bool, |
| | | appDropTargetID: String?, |
| | | onActivate: @escaping (String) -> Void, |
| | | onDoubleActivate: @escaping (String) -> Void, |
| | | onHoverChange: @escaping (String, Bool) -> Void, |
| | | canReorder: @escaping (String) -> Bool, |
| | | canAcceptAppDrop: @escaping (String) -> Bool, |
| | |
| | | appDragModeActive: appDragModeActive, |
| | | appDropTargetID: appDropTargetID, |
| | | onActivate: onActivate, |
| | | onDoubleActivate: onDoubleActivate, |
| | | onHoverChange: onHoverChange, |
| | | canReorder: canReorder, |
| | | canAcceptAppDrop: canAcceptAppDrop, |
| | |
| | | private var appDragModeActive = false |
| | | private var appDropTargetID: String? |
| | | private var onActivate: (String) -> Void = { _ in } |
| | | private var onDoubleActivate: (String) -> Void = { _ in } |
| | | private var onHoverChange: (String, Bool) -> Void = { _, _ in } |
| | | private var canReorder: (String) -> Bool = { _ in false } |
| | | private var canAcceptAppDrop: (String) -> Bool = { _ in false } |
| | |
| | | appDragModeActive: Bool, |
| | | appDropTargetID: String?, |
| | | onActivate: @escaping (String) -> Void, |
| | | onDoubleActivate: @escaping (String) -> Void, |
| | | onHoverChange: @escaping (String, Bool) -> Void, |
| | | canReorder: @escaping (String) -> Bool, |
| | | canAcceptAppDrop: @escaping (String) -> Bool, |
| | |
| | | self.appDragModeActive = appDragModeActive |
| | | self.appDropTargetID = appDropTargetID |
| | | self.onActivate = onActivate |
| | | self.onDoubleActivate = onDoubleActivate |
| | | self.onHoverChange = onHoverChange |
| | | self.canReorder = canReorder |
| | | self.canAcceptAppDrop = canAcceptAppDrop |
| | |
| | | buttons = items.map { item in |
| | | let button = TagNavigationButton(item: item, orientation: orientation) |
| | | button.onActivate = { [weak self] tagID in self?.onActivate(tagID) } |
| | | button.onDoubleActivate = { [weak self] tagID in self?.onDoubleActivate(tagID) } |
| | | button.onHoverChange = { [weak self] tagID, active in self?.onHoverChange(tagID, active) } |
| | | button.canReorder = { [weak self] tagID in self?.canReorder(tagID) ?? false } |
| | | button.onReorderBegan = { [weak self] tagID in self?.onReorderBegan(tagID) } |
| | |
| | | |
| | | final class TagNavigationButton: NSButton, AppDropTargetReceivingView { |
| | | var onActivate: (String) -> Void = { _ in } |
| | | var onDoubleActivate: (String) -> Void = { _ in } |
| | | var onHoverChange: (String, Bool) -> Void = { _, _ in } |
| | | var canReorder: (String) -> Bool = { _ in false } |
| | | var onReorderBegan: (String) -> Void = { _ in } |
| | |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | self.item = TagNavigationItem(name: "", colorIndex: 0) |
| | | self.item = TagNavigationItem(name: "", colorIndex: 0, customColor: nil) |
| | | self.orientation = .horizontal |
| | | super.init(coder: coder) |
| | | } |
| | |
| | | } |
| | | |
| | | override func mouseDown(with event: NSEvent) { |
| | | if event.clickCount >= 2 { |
| | | onDoubleActivate(item.id) |
| | | return |
| | | } |
| | | |
| | | guard canReorder(item.id) else { |
| | | onActivate(item.id) |
| | | return |
| | |
| | | } |
| | | |
| | | private func updateAppearance() { |
| | | let background = TagColor.nsColor(for: item.colorIndex) |
| | | let background = TagColor.nsColor(for: item.colorIndex, customColor: item.customColor) |
| | | let dragScale: CGFloat = isDragging ? 1.04 : 1.0 |
| | | layer?.backgroundColor = background.cgColor |
| | | layer?.cornerRadius = orientation == .horizontal ? 7 : 6 |
| | |
| | | layer?.setAffineTransform(CGAffineTransform(scaleX: dragScale, y: dragScale)) |
| | | alphaValue = dragModeActive ? (isDragging ? 1.0 : 0.62) : 1.0 |
| | | |
| | | let textColor: NSColor = (item.colorIndex == 0 || item.colorIndex == 5) ? .labelColor : .white |
| | | let textColor: NSColor = TagColor.prefersDarkText(for: background) ? .labelColor : .white |
| | | let paragraph = NSMutableParagraphStyle() |
| | | paragraph.alignment = alignment |
| | | if orientation == .vertical { |