2020-11-22 13:41:33 +03:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// TabsSupport
|
|
|
|
//
|
|
|
|
// Created by Tae Won Ha on 22.11.20.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
2020-11-22 17:03:37 +03:00
|
|
|
import PureLayout
|
2020-11-22 13:41:33 +03:00
|
|
|
import Tabs
|
|
|
|
|
|
|
|
@main
|
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
@IBOutlet var window: NSWindow!
|
|
|
|
|
2020-11-22 17:03:37 +03:00
|
|
|
override init() {
|
2020-11-28 17:58:12 +03:00
|
|
|
self.tabBar = TabBar(withTheme: .default)
|
2020-11-22 17:03:37 +03:00
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
|
2020-11-22 13:41:33 +03:00
|
|
|
func applicationDidFinishLaunching(_: Notification) {
|
2020-11-22 17:03:37 +03:00
|
|
|
let contentView = self.window.contentView!
|
|
|
|
contentView.addSubview(self.tabBar)
|
2020-12-06 18:50:49 +03:00
|
|
|
|
2020-12-06 23:23:23 +03:00
|
|
|
let tb = self.tabBar
|
|
|
|
tb.autoPinEdge(toSuperviewEdge: .top)
|
|
|
|
tb.autoPinEdge(toSuperviewEdge: .left)
|
|
|
|
tb.autoPinEdge(toSuperviewEdge: .right)
|
|
|
|
tb.autoSetDimension(.height, toSize: Theme().tabBarHeight)
|
2020-12-24 19:48:27 +03:00
|
|
|
tb.selectHandler = { [weak self] _, selectedEntry, _ in
|
2020-12-06 23:23:23 +03:00
|
|
|
self?.tabEntries.enumerated().forEach { index, entry in
|
|
|
|
self?.tabEntries[index].isSelected = (entry == selectedEntry)
|
|
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
Swift.print("select: \(self!.tabEntries)")
|
|
|
|
self?.tabBar.update(tabRepresentatives: self?.tabEntries ?? [])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tb.reorderHandler = { [weak self] index, reorderedEntry, entries in
|
|
|
|
self?.tabEntries = entries
|
|
|
|
self?.tabEntries.enumerated().forEach { index, entry in
|
|
|
|
self?.tabEntries[index].isSelected = (entry == reorderedEntry)
|
|
|
|
}
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
Swift.print("reorder: \(entries)")
|
|
|
|
self?.tabBar.update(tabRepresentatives: self?.tabEntries ?? [])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.tabEntries = [
|
2020-12-06 18:50:49 +03:00
|
|
|
DummyTabEntry(title: "Test 1"),
|
|
|
|
DummyTabEntry(title: "Test 2"),
|
|
|
|
DummyTabEntry(title: "Test 3"),
|
|
|
|
DummyTabEntry(title: "Very long long long title, and some more text!"),
|
2020-12-06 23:23:23 +03:00
|
|
|
]
|
|
|
|
self.tabEntries[0].isSelected = true
|
|
|
|
self.tabBar.update(tabRepresentatives: self.tabEntries)
|
2020-11-22 13:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func applicationWillTerminate(_: Notification) {
|
|
|
|
// Insert code here to tear down your application
|
|
|
|
}
|
2020-11-22 17:03:37 +03:00
|
|
|
|
2020-12-06 18:08:12 +03:00
|
|
|
private let tabBar: TabBar<DummyTabEntry>
|
2020-12-06 23:23:23 +03:00
|
|
|
private var tabEntries = [DummyTabEntry]()
|
2020-12-06 18:08:12 +03:00
|
|
|
}
|
|
|
|
|
2020-12-06 18:50:49 +03:00
|
|
|
struct DummyTabEntry: Hashable, TabRepresentative {
|
2020-12-06 18:08:12 +03:00
|
|
|
var title: String
|
2020-12-06 18:50:49 +03:00
|
|
|
var isSelected = false
|
2020-11-22 13:41:33 +03:00
|
|
|
}
|