From 1333e266ccd167a2c8862d0ec691363b35a67fc1 Mon Sep 17 00:00:00 2001 From: Rafa Lucena Date: Mon, 19 Feb 2018 11:48:40 +0100 Subject: [PATCH 1/3] Hide close button feature --- LYTabBarView Demo/ViewController.swift | 7 ++++++- LYTabView/LYTabBarView.swift | 3 +++ LYTabView/LYTabItemView.swift | 4 +++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/LYTabBarView Demo/ViewController.swift b/LYTabBarView Demo/ViewController.swift index 4f5ff73..6cded64 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,9 @@ class ViewController: NSViewController { tabBarView?.addNewTabButtonAction = #selector(addNewTab) } self.tabBarView.addNewTabButtonTarget = self + + self.tabBarView.showCloseButton = false + } override func viewWillAppear() { diff --git a/LYTabView/LYTabBarView.swift b/LYTabView/LYTabBarView.swift index 5d10027..5f1884f 100644 --- a/LYTabView/LYTabBarView.swift +++ b/LYTabView/LYTabBarView.swift @@ -100,6 +100,8 @@ public class LYTabBarView: NSView { resetHeight() } } + + public var showCloseButton: Bool = true var status: BarStatus { let isWindowActive = self.isWindowActive @@ -564,6 +566,7 @@ public class LYTabBarView: NSView { private func createLYTabItemView(_ item: NSTabViewItem) -> LYTabItemView { let tabItemView = LYTabItemView(tabViewItem: item) tabItemView.tabBarView = self + tabItemView.showCloseButton = self.showCloseButton tabItemView.translatesAutoresizingMaskIntoConstraints = false tabItemView.setContentCompressionResistancePriority(NSLayoutConstraint.Priority.defaultLow, for: .horizontal) return tabItemView diff --git a/LYTabView/LYTabItemView.swift b/LYTabView/LYTabItemView.swift index 22ce486..671912c 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? { @@ -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) { From e90370d05f2782de77a270976c6374642293db3c Mon Sep 17 00:00:00 2001 From: Rafa Lucena Date: Mon, 19 Feb 2018 13:40:23 +0100 Subject: [PATCH 2/3] Change colors --- LYTabBarView Demo/ViewController.swift | 1 + LYTabView/LYTabBarView.swift | 35 +++++++++++++++++++++++++- LYTabView/LYTabItemView.swift | 4 +-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/LYTabBarView Demo/ViewController.swift b/LYTabBarView Demo/ViewController.swift index 6cded64..1376e95 100644 --- a/LYTabBarView Demo/ViewController.swift +++ b/LYTabBarView Demo/ViewController.swift @@ -53,6 +53,7 @@ class ViewController: NSViewController { self.tabBarView.showCloseButton = false + } override func viewWillAppear() { diff --git a/LYTabView/LYTabBarView.swift b/LYTabView/LYTabBarView.swift index 5f1884f..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() @@ -131,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 { @@ -567,6 +593,13 @@ public class LYTabBarView: NSView { 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 671912c..933769d 100644 --- a/LYTabView/LYTabItemView.swift +++ b/LYTabView/LYTabItemView.swift @@ -37,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) ] @@ -384,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 From 9f73be0b78756c82a44cae590ba1cd8053ac5a19 Mon Sep 17 00:00:00 2001 From: Rafa Lucena Date: Mon, 19 Feb 2018 13:44:46 +0100 Subject: [PATCH 3/3] Version number --- LYTabView/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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