add new divider block kind

This commit is contained in:
2026-07-12 21:29:57 +02:00
parent aa241148ef
commit a963a19bf3
3 changed files with 35 additions and 1 deletions
@@ -1,10 +1,11 @@
enum PHBlockKind: String { enum PHBlockKind: String {
case text, space case text, space, divider
} }
extension PHBlock { extension PHBlock {
var kind: PHBlockKind { var kind: PHBlockKind {
if name.starts(with: "_space") { return .space } if name.starts(with: "_space") { return .space }
if name.starts(with: "_divider") { return .divider }
return .text return .text
} }
} }
+4
View File
@@ -16,6 +16,8 @@ struct BarView: View {
TextView(block: block) TextView(block: block)
case .space: case .space:
SpaceView(block: block) SpaceView(block: block)
case .divider:
DividerView(block: block)
} }
} }
} }
@@ -27,6 +29,8 @@ struct BarView: View {
TextView(block: block) TextView(block: block)
case .space: case .space:
SpaceView(block: block) SpaceView(block: block)
case .divider:
DividerView(block: block)
} }
} }
} }
+29
View File
@@ -0,0 +1,29 @@
import SwiftUI
struct DividerView: View {
@ObservedObject var block: PHBlock
var width: CGFloat {
guard let arg = block.name.split(separator: " ").last else { return 1 }
guard let width = Double(arg) else { return 1 }
return CGFloat(width)
}
var body: some View {
ZStack {
Rectangle()
.fill(block.style.background?.uiColor ?? .clear)
Rectangle()
.fill(block.style.foreground?.uiColor ?? .clear)
.frame(width: width)
.padding(.trailing, block.style.padding?.trailing ?? 0)
.padding(.leading, block.style.padding?.leading ?? 0)
.padding(.top, block.style.padding?.top ?? 0)
.padding(.bottom, block.style.padding?.bottom ?? 0)
.border(block.debug ? .blue : .clear)
}
.fixedSize(horizontal: true, vertical: false)
.border(block.debug ? .red : .clear)
}
}