Compare commits

..

3 Commits

Author SHA1 Message Date
tommaso a963a19bf3 add new divider block kind 2026-07-12 21:29:57 +02:00
tommaso aa241148ef add support for vertical padding in styles 2026-07-12 21:29:42 +02:00
tommaso 07a05e5470 rename views 2026-07-12 21:11:55 +02:00
7 changed files with 48 additions and 8 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
} }
} }
@@ -10,7 +10,7 @@ struct PHThemeStyle: Decodable {
name: "_default", name: "_default",
foreground: .init(color: "#000000", alpha: nil), foreground: .init(color: "#000000", alpha: nil),
background: .init(color: "#ffffff", alpha: nil), background: .init(color: "#ffffff", alpha: nil),
padding: .init(leading: 12, trailing: 12), padding: .init(top: 0, bottom: 0, leading: 12, trailing: 12),
corner: nil corner: nil
) )
}() }()
@@ -1,8 +1,12 @@
struct PHThemeStylePadding: Decodable { struct PHThemeStylePadding: Decodable {
let top: Double?
let bottom: Double?
let leading: Double? let leading: Double?
let trailing: Double? let trailing: Double?
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case top
case bottom
case leading = "left" case leading = "left"
case trailing = "right" case trailing = "right"
} }
+8 -4
View File
@@ -13,9 +13,11 @@ struct BarView: View {
ForEach(bar.arrangedBlocks) { block in ForEach(bar.arrangedBlocks) { block in
switch block.kind { switch block.kind {
case .text: case .text:
TextBlockView(block: block) TextView(block: block)
case .space: case .space:
SpaceBlockView(block: block) SpaceView(block: block)
case .divider:
DividerView(block: block)
} }
} }
} }
@@ -24,9 +26,11 @@ struct BarView: View {
ForEach(bar.centeredBlocks) { block in ForEach(bar.centeredBlocks) { block in
switch block.kind { switch block.kind {
case .text: case .text:
TextBlockView(block: block) TextView(block: block)
case .space: case .space:
SpaceBlockView(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)
}
}
@@ -1,6 +1,6 @@
import SwiftUI import SwiftUI
struct SpaceBlockView: View { struct SpaceView: View {
@ObservedObject var block: PHBlock @ObservedObject var block: PHBlock
var width: CGFloat? { var width: CGFloat? {
@@ -1,6 +1,6 @@
import SwiftUI import SwiftUI
struct TextBlockView: View { struct TextView: View {
@EnvironmentObject private var bar: BarController @EnvironmentObject private var bar: BarController
@ObservedObject var block: PHBlock @ObservedObject var block: PHBlock
@@ -33,6 +33,8 @@ struct TextBlockView: View {
} }
.padding(.trailing, block.style.padding?.trailing ?? 0) .padding(.trailing, block.style.padding?.trailing ?? 0)
.padding(.leading, block.style.padding?.leading ?? 0) .padding(.leading, block.style.padding?.leading ?? 0)
.padding(.top, block.style.padding?.top ?? 0)
.padding(.bottom, block.style.padding?.bottom ?? 0)
} }
.fixedSize(horizontal: true, vertical: false) .fixedSize(horizontal: true, vertical: false)
.border(block.debug ? .red : .clear) .border(block.debug ? .red : .clear)