1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-24 22:33:52 +03:00

Refactor slightly

This commit is contained in:
Tae Won Ha 2020-11-28 14:19:20 +01:00
parent 25e73ddb52
commit 63b8ea2ecd
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 24 additions and 10 deletions

View File

@ -3,12 +3,13 @@
* See LICENSE
*/
import Foundation
import Cocoa
public enum Dimensions {
public enum Defs {
public static let tabHeight = CGFloat(28)
public static let tabMinWidth = CGFloat(100)
public static let tabMaxWidth = CGFloat(400)
public static let tabTitleFont = NSFont.systemFont(ofSize: 11)
public static let tabPadding = CGFloat(0)

View File

@ -6,9 +6,16 @@
import Cocoa
public class Tab: NSView {
public var title: String
public init() {
public init(withTitle title: String) {
self.title = title
self.attributedTitle = NSAttributedString(string: title, attributes: [
.font: Defs.tabTitleFont
])
super.init(frame: .zero)
self.configureForAutoLayout()
self.wantsLayer = true
@ -16,7 +23,7 @@ public class Tab: NSView {
self.layer?.backgroundColor = NSColor.cyan.cgColor
#endif
self.autoSetDimensions(to: CGSize(width: 200, height: Dimensions.tabHeight))
self.autoSetDimensions(to: CGSize(width: 200, height: Defs.tabHeight))
}
public override func mouseDown(with event: NSEvent) {
@ -27,6 +34,12 @@ public class Tab: NSView {
Swift.print("mouse up in tab")
}
public override func draw(_ dirtyRect: NSRect) {
self.attributedTitle.draw(in: self.bounds)
}
@available(*, unavailable)
required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") }
private var attributedTitle: NSAttributedString
}

View File

@ -44,14 +44,14 @@ public class TabBar: NSView {
self.stackView.autoPinEdge(toSuperviewEdge: .left)
self.stackView.autoPinEdge(toSuperviewEdge: .bottom)
self.stackView.spacing = Dimensions.tabPadding
self.stackView.spacing = Defs.tabPadding
}
private func addTestTabs() {
let tab1 = Tab()
let tab2 = Tab()
let tab3 = Tab()
let tab4 = Tab()
let tab1 = Tab(withTitle: "Test 1")
let tab2 = Tab(withTitle: "Test 2")
let tab3 = Tab(withTitle: "Test 3")
let tab4 = Tab(withTitle: "Test 4")
tab1.layer?.backgroundColor = NSColor.red.cgColor
tab2.layer?.backgroundColor = NSColor.blue.cgColor

View File

@ -24,7 +24,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.tabBar.autoPinEdge(toSuperviewEdge: .top)
self.tabBar.autoPinEdge(toSuperviewEdge: .left)
self.tabBar.autoPinEdge(toSuperviewEdge: .right)
self.tabBar.autoSetDimension(.height, toSize: Dimensions.tabBarHeight)
self.tabBar.autoSetDimension(.height, toSize: Defs.tabBarHeight)
}
func applicationWillTerminate(_: Notification) {