diff --git a/LYTabBarView Demo/ViewController.swift b/LYTabBarView Demo/ViewController.swift index 4f5ff73..1376e95 100644 --- a/LYTabBarView Demo/ViewController.swift +++ b/LYTabBarView Demo/ViewController.swift @@ -28,7 +28,9 @@ class ViewController: NSViewController { addViewWithLabel("View", aTabBarView: self.tabBarView, fromTabView: true) self.tabBarView.minTabHeight = 28 self.tabBarView.minTabItemWidth = 120 - + + + tabView21.tabBarView.hideIfOnlyOneTabExists = false tabView22.tabBarView.hideIfOnlyOneTabExists = false tabView23.tabBarView.hideIfOnlyOneTabExists = false @@ -48,6 +50,10 @@ class ViewController: NSViewController { tabBarView?.addNewTabButtonAction = #selector(addNewTab) } self.tabBarView.addNewTabButtonTarget = self + + self.tabBarView.showCloseButton = false + + } override func viewWillAppear() { diff --git a/LYTabView/Info.plist b/LYTabView/Info.plist index c36963a..7d37aa1 100644 --- a/LYTabView/Info.plist +++ b/LYTabView/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.27 + 0.28 CFBundleSignature ???? CFBundleVersion diff --git a/LYTabView/LYTabBarView.swift b/LYTabView/LYTabBarView.swift index 5d10027..bc951d0 100644 --- a/LYTabView/LYTabBarView.swift +++ b/LYTabView/LYTabBarView.swift @@ -56,7 +56,6 @@ public class LYTabBarView: NSView { public var needAnimation: Bool = true public var isActive: Bool = true { didSet { - self.needsDisplay = true for view in self.tabItemViews() { view.updateColors() @@ -100,6 +99,8 @@ public class LYTabBarView: NSView { resetHeight() } } + + public var showCloseButton: Bool = true var status: BarStatus { let isWindowActive = self.isWindowActive @@ -129,6 +130,33 @@ public class LYTabBarView: NSView { .windowInactive: NSColor(white: 0.86, alpha: 1), .inactive: NSColor(white: 0.71, alpha: 1) ] + + public var backgroundItemColor: ColorConfig = [ + .active: NSColor(white: 0.77, alpha: 1), + .windowInactive: NSColor(white: 0.86, alpha: 1), + .inactive: NSColor(white: 0.70, alpha: 1) + ] + + public var hoverItemBackgroundColor: ColorConfig = [ + .active: NSColor(white: 0.75, alpha: 1), + .windowInactive: NSColor(white: 0.94, alpha: 1), + .inactive: NSColor(white: 0.68, alpha: 1) + ] + + public var selectedBackgroundColor: ColorConfig = [ + .active: NSColor(white: 0.86, alpha: 1), + .windowInactive: NSColor(white: 0.96, alpha: 1), + .inactive: NSColor(white: 0.76, alpha: 1) + ] + + public var selectedTextColor: ColorConfig = [ + .active: NSColor.textColor, + .windowInactive: NSColor(white: 0.4, alpha: 1), + .inactive: NSColor(white: 0.4, alpha: 1) + ] + + public var unselectedForegroundColor = NSColor(white: 0.4, alpha: 1) + public var closeButtonHoverBackgroundColor = NSColor(white: 0.55, alpha: 0.3) public var showAddNewTabButton: Bool = true { didSet { @@ -564,6 +592,14 @@ public class LYTabBarView: NSView { private func createLYTabItemView(_ item: NSTabViewItem) -> LYTabItemView { let tabItemView = LYTabItemView(tabViewItem: item) tabItemView.tabBarView = self + tabItemView.showCloseButton = self.showCloseButton + tabItemView.backgroundColor = self.backgroundColor + tabItemView.hoverBackgroundColor = self.hoverItemBackgroundColor + tabItemView.selectedTextColor = self.selectedTextColor + tabItemView.selectedBackgroundColor = self.selectedBackgroundColor + tabItemView.unselectedForegroundColor = self.unselectedForegroundColor + tabItemView.closeButtonHoverBackgroundColor = self.closeButtonHoverBackgroundColor + tabItemView.translatesAutoresizingMaskIntoConstraints = false tabItemView.setContentCompressionResistancePriority(NSLayoutConstraint.Priority.defaultLow, for: .horizontal) return tabItemView diff --git a/LYTabView/LYTabItemView.swift b/LYTabView/LYTabItemView.swift index 22ce486..933769d 100644 --- a/LYTabView/LYTabItemView.swift +++ b/LYTabView/LYTabItemView.swift @@ -13,6 +13,8 @@ class LYTabItemView: NSButton { fileprivate let titleView = NSTextField(frame: .zero) fileprivate var closeButton: LYHoverButton! + public var showCloseButton: Bool = true + var tabBarView: LYTabBarView! var tabLabelObserver: NSKeyValueObservation? var tabViewItem: NSTabViewItem? { @@ -35,7 +37,7 @@ class LYTabItemView: NSButton { var ypadding: CGFloat = 2 var closeButtonSize = NSSize(width: 16, height: 16) var backgroundColor: ColorConfig = [ - .active: NSColor(white: 0.77, alpha: 1), + .active: NSColor(white: 0.07, alpha: 1), .windowInactive: NSColor(white: 0.94, alpha: 1), .inactive: NSColor(white: 0.70, alpha: 1) ] @@ -248,7 +250,7 @@ class LYTabItemView: NSButton { if !shouldDrawInHighLight { self.animatorOrNot(needAnimation).realBackgroundColor = hoverBackgroundColor[status]! } - closeButton.animatorOrNot(needAnimation).isHidden = false + closeButton.animatorOrNot(needAnimation).isHidden = !showCloseButton } override func mouseExited(with theEvent: NSEvent) { @@ -382,7 +384,7 @@ extension LYTabItemView: NSDraggingSource { func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) { dragOffset = nil isDragging = false - closeButton.isHidden = false + closeButton.isHidden = !showCloseButton self.titleView.isHidden = false self.draggingView?.removeFromSuperview() self.draggingViewLeadingConstraint = nil