diff options
Diffstat (limited to 'Sources/phbar/Views')
| -rw-r--r-- | Sources/phbar/Views/BarView.swift | 29 | ||||
| -rw-r--r-- | Sources/phbar/Views/BarWindow.swift | 29 | ||||
| -rw-r--r-- | Sources/phbar/Views/BlockView.swift | 13 | ||||
| -rw-r--r-- | Sources/phbar/Views/CellView.swift | 13 |
4 files changed, 84 insertions, 0 deletions
diff --git a/Sources/phbar/Views/BarView.swift b/Sources/phbar/Views/BarView.swift new file mode 100644 index 0000000..7ad7c4c --- /dev/null +++ b/Sources/phbar/Views/BarView.swift @@ -0,0 +1,29 @@ +import SwiftUI + +struct BarView: View { + private let left: [Block] + private let right: [Block] + + init(blocks: [Block]) { + self.left = blocks.filter { $0.placement == .left } + self.right = blocks.filter { $0.placement == .right } + } + + var body: some View { + HStack(spacing: 0) { + ForEach(left) { block in + BlockView(block: block) + } + + Spacer() + + ForEach(right) { block in + BlockView(block: block) + } + } + .font(Config.font) + .foregroundStyle(Config.foreground) + .frame(maxWidth: .infinity, maxHeight: Config.height) + .background(Config.background) + } +} diff --git a/Sources/phbar/Views/BarWindow.swift b/Sources/phbar/Views/BarWindow.swift new file mode 100644 index 0000000..83bbcc2 --- /dev/null +++ b/Sources/phbar/Views/BarWindow.swift @@ -0,0 +1,29 @@ +import AppKit + +// A non-activating panel: clicking it (e.g. a workspace cell) runs the action +// without stealing focus from the app you're working in. +final class BarWindow: NSPanel { + init(contentRect: NSRect) { + super.init( + contentRect: contentRect, + styleMask: [.nonactivatingPanel], + backing: .buffered, + defer: false + ) + + isFloatingPanel = true + isOpaque = false + backgroundColor = .clear + hasShadow = false + hidesOnDeactivate = false + isReleasedWhenClosed = false + isMovable = false + becomesKeyOnlyIfNeeded = true + level = .floating + collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary] + animationBehavior = .none + } + + override var canBecomeKey: Bool { true } + override var canBecomeMain: Bool { false } +} diff --git a/Sources/phbar/Views/BlockView.swift b/Sources/phbar/Views/BlockView.swift new file mode 100644 index 0000000..b7c0e7f --- /dev/null +++ b/Sources/phbar/Views/BlockView.swift @@ -0,0 +1,13 @@ +import SwiftUI + +struct BlockView: View { + @ObservedObject var block: Block + + var body: some View { + HStack(spacing: 0) { + ForEach(block.cells.indices, id: \.self) { index in + CellView(text: block.cells[index]) + } + } + } +} diff --git a/Sources/phbar/Views/CellView.swift b/Sources/phbar/Views/CellView.swift new file mode 100644 index 0000000..494667c --- /dev/null +++ b/Sources/phbar/Views/CellView.swift @@ -0,0 +1,13 @@ +import SwiftUI + +struct CellView: View { + var text: String + + var body: some View { + VStack { + Text(text) + } + .frame(height: Config.height) + .background(Color.cyan) + } +} |
