39 lines
1.0 KiB
Swift
39 lines
1.0 KiB
Swift
import SwiftUI
|
|
|
|
/// The 1pt `raised` divider. Use it for every border between panels, rows and bars.
|
|
public struct Hairline: View {
|
|
var axis: Axis
|
|
|
|
/// `.horizontal` draws a line across (a row divider); `.vertical` draws a column divider.
|
|
public init(_ axis: Axis = .horizontal) {
|
|
self.axis = axis
|
|
}
|
|
|
|
public var body: some View {
|
|
Rectangle()
|
|
.fill(Palette.raised)
|
|
.frame(width: axis == .vertical ? Metrics.hairline : nil,
|
|
height: axis == .horizontal ? Metrics.hairline : nil)
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
/// Draws a hairline along one edge without changing the layout.
|
|
public func hairline(_ edge: Edge) -> some View {
|
|
overlay(alignment: edge.alignment) {
|
|
Hairline(edge == .top || edge == .bottom ? .horizontal : .vertical)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Edge {
|
|
fileprivate var alignment: Alignment {
|
|
switch self {
|
|
case .top: .top
|
|
case .bottom: .bottom
|
|
case .leading: .leading
|
|
case .trailing: .trailing
|
|
}
|
|
}
|
|
}
|