Created
April 28, 2025 22:51
-
-
Save kopyl/a9c976a18159403f9c1dd599f4ef9dc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class TabItemView: NSView { | |
let tab: Tab | |
var onTabHover: ((Int) -> Void)? | |
private var firstColumnLabel: NSTextField | |
private var seconColumnLabel: NSTextField | |
public var swipeActionViewCenterYAnchorConstraint = NSLayoutConstraint() | |
private var isRunningFullSwipe = false | |
private var isRunningPartialFullSwipe = false | |
private var isRunningAnyAnimation = false | |
private var totalSwipeDistance: CGFloat = 0 | |
/// need to lock on swipe-to-close-tab scroll and avoid letting user to swipe vertically | |
private var isUserTryingToSwipeToCloseTab = false | |
private var textLabelForSwipeViewXConstraint = NSLayoutConstraint() | |
init(tab: Tab) { | |
self.tab = tab | |
switch appState.columnOrder { | |
case .host_title: | |
self.firstColumnLabel = NSTextField(labelWithString: tab.host) | |
self.seconColumnLabel = NSTextField(labelWithString: tab.title) | |
case .title_host: | |
self.firstColumnLabel = NSTextField(labelWithString: tab.title) | |
self.seconColumnLabel = NSTextField(labelWithString: tab.host) | |
} | |
let textLabelForSwipeView = NSTextField(labelWithString: Copy.TabsPanel.closeButtonTitle) | |
let stackView = NSStackView() | |
super.init(frame: .zero) | |
self.clipsToBounds = true | |
self.wantsLayer = true | |
self.layer?.cornerRadius = 6 | |
textLabelForSwipeView.font = .systemFont(ofSize: 13, weight: .regular) | |
textLabelForSwipeView.textColor = .white | |
firstColumnLabel.lineBreakMode = .byTruncatingTail | |
firstColumnLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) | |
firstColumnLabel.font = .systemFont(ofSize: 18) | |
firstColumnLabel.textColor = .tabFg | |
stackView.orientation = .horizontal | |
stackView.edgeInsets = .init(top: 0, left: 57, bottom: 0, right: 50) | |
stackView.addArrangedSubview(firstColumnLabel) | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
self.addSubview(stackView) | |
NSLayoutConstraint.activate([ | |
stackView.leadingAnchor.constraint(equalTo: leadingAnchor), | |
stackView.trailingAnchor.constraint(equalTo: trailingAnchor), | |
stackView.topAnchor.constraint(equalTo: topAnchor), | |
stackView.bottomAnchor.constraint(equalTo: bottomAnchor), | |
]) | |
} | |
required init(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the TabHistoryView.swift which works with this TabItemView class:
https://gist.github.com/kopyl/693773388d4e944bdc401561d665b215