move files around

This commit is contained in:
2026-07-12 15:06:51 +02:00
parent a6a7f80cce
commit 24c53eb51d
35 changed files with 27 additions and 27 deletions
+3 -3
View File
@@ -32,11 +32,11 @@ let package = Package(
.target(name: "phbarEvents"), .target(name: "phbarEvents"),
], ],
exclude: [ exclude: [
"Models/Event/README.md" "Models/PHEvent/README.md"
], ],
resources: [ resources: [
.process("Models/Config/config.toml"), .process("Models/PHConfig/config.toml"),
.process("Models/Theme/theme.toml"), .process("Models/PHTheme/theme.toml"),
] ]
), ),
.testTarget( .testTarget(
@@ -1,8 +1,8 @@
struct PHThemeStyle: Decodable { struct PHThemeStyle: Decodable {
let name: String let name: String
let foreground: PHThemeColor? let foreground: PHThemeStyleColor?
let background: PHThemeColor? let background: PHThemeStyleColor?
let padding: PHThemePadding? let padding: PHThemeStylePadding?
static let `default`: Self = { static let `default`: Self = {
PHThemeStyle( PHThemeStyle(
@@ -1,6 +1,6 @@
import SwiftUI import SwiftUI
struct PHThemeColor: Decodable, ShapeStyle { struct PHThemeStyleColor: Decodable, ShapeStyle {
typealias Resolved = SwiftUI.Color typealias Resolved = SwiftUI.Color
let color: String let color: String
@@ -1,4 +1,4 @@
struct PHThemePadding: Decodable { struct PHThemeStylePadding: Decodable {
let trailing: Double? let trailing: Double?
let leading: Double? let leading: Double?
@@ -8,13 +8,13 @@ struct PHThemeWindow: Decodable {
/// Window height in points. /// Window height in points.
var height: Double? = 30 var height: Double? = 30
/// Window width: a point value or a percentage of the screen width. /// Window width: a point value or a percentage of the screen width.
var width: PHThemeDimension? = .percentage(1.0) var width: PHThemeWindowDimension? = .percentage(1.0)
/// Semantic placement within the screen. /// Semantic placement within the screen.
var anchor: PHThemeAnchor? = .top var anchor: PHThemeWindowAnchor? = .top
/// Insets from the anchored edges. /// Insets from the anchored edges.
var margin: PHThemeMargin? = .init() var margin: PHThemeWindowMargin? = .init()
/// Absolute origin. Overrides `anchor` and `margin` when set. /// Absolute origin. Overrides `anchor` and `margin` when set.
var origin: PHThemePoint? var origin: PHThemeWindowPoint?
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case name case name
@@ -6,7 +6,7 @@ import Foundation
/// Single-edge anchors (`top`, `bottom`, `leading`, `trailing`) pin to that /// Single-edge anchors (`top`, `bottom`, `leading`, `trailing`) pin to that
/// edge and center along the opposite axis. Corner anchors pin to two edges. /// edge and center along the opposite axis. Corner anchors pin to two edges.
/// `center` centers the window on both axes. /// `center` centers the window on both axes.
enum PHThemeAnchor: String, Decodable { enum PHThemeWindowAnchor: String, Decodable {
case top, bottom, leading, trailing case top, bottom, leading, trailing
case topLeading = "top-leading" case topLeading = "top-leading"
case topTrailing = "top-trailing" case topTrailing = "top-trailing"
@@ -15,14 +15,14 @@ enum PHThemeAnchor: String, Decodable {
case center case center
} }
extension PHThemeAnchor { extension PHThemeWindowAnchor {
/// Compute the top-left origin (in screen coordinates) of a window of `size` /// Compute the top-left origin (in screen coordinates) of a window of `size`
/// placed against this anchor within `screen`, offset by `margin` along the /// placed against this anchor within `screen`, offset by `margin` along the
/// anchored edges. /// anchored edges.
/// ///
/// Edges the anchor does not reference are ignored, so margins only affect /// Edges the anchor does not reference are ignored, so margins only affect
/// the relevant sides. /// the relevant sides.
func origin(in screen: CGRect, size: CGSize, margin: PHThemeMargin) -> CGPoint { func origin(in screen: CGRect, size: CGSize, margin: PHThemeWindowMargin) -> CGPoint {
let top = margin.top ?? 0 let top = margin.top ?? 0
let bottom = margin.bottom ?? 0 let bottom = margin.bottom ?? 0
let leading = margin.leading ?? 0 let leading = margin.leading ?? 0
@@ -6,7 +6,7 @@ import Foundation
/// ///
/// Decoded from either a number (`width = 400`) or a percentage string /// Decoded from either a number (`width = 400`) or a percentage string
/// (`width = "100%"`). /// (`width = "100%"`).
enum PHThemeDimension: Decodable, Equatable { enum PHThemeWindowDimension: Decodable, Equatable {
case points(Double) case points(Double)
case percentage(Double) case percentage(Double)
@@ -4,7 +4,7 @@ import Foundation
/// ///
/// Only the edges referenced by the anchor are consumed; the rest are ignored, /// Only the edges referenced by the anchor are consumed; the rest are ignored,
/// so a margin only affects the relevant sides of the placement. /// so a margin only affects the relevant sides of the placement.
struct PHThemeMargin: Decodable, Equatable { struct PHThemeWindowMargin: Decodable, Equatable {
let top: Double? let top: Double?
let bottom: Double? let bottom: Double?
let leading: Double? let leading: Double?
@@ -4,7 +4,7 @@ import Foundation
/// ///
/// When set on a window, it overrides anchor/margin placement entirely the /// When set on a window, it overrides anchor/margin placement entirely the
/// window appears at exactly these coordinates. /// window appears at exactly these coordinates.
struct PHThemePoint: Decodable, Equatable { struct PHThemeWindowPoint: Decodable, Equatable {
let x: Double let x: Double
let y: Double let y: Double
} }
+9 -9
View File
@@ -456,7 +456,7 @@ private final class FakeEventSource: PHEventSource {
// MARK: - PHThemeDimension // MARK: - PHThemeDimension
private struct DimensionWrapper: Decodable { private struct DimensionWrapper: Decodable {
let v: PHThemeDimension let v: PHThemeWindowDimension
} }
@Test func dimensionDecodesPoints() throws { @Test func dimensionDecodesPoints() throws {
@@ -479,8 +479,8 @@ private struct DimensionWrapper: Decodable {
} }
@Test func dimensionResolvesAgainstLength() { @Test func dimensionResolvesAgainstLength() {
#expect(PHThemeDimension.points(250).resolve(against: 1000) == 250) #expect(PHThemeWindowDimension.points(250).resolve(against: 1000) == 250)
#expect(PHThemeDimension.percentage(0.25).resolve(against: 1000) == 250) #expect(PHThemeWindowDimension.percentage(0.25).resolve(against: 1000) == 250)
} }
// MARK: - PHThemeAnchor geometry // MARK: - PHThemeAnchor geometry
@@ -488,21 +488,21 @@ private struct DimensionWrapper: Decodable {
@Test func anchorPlacesAtTopEdge() { @Test func anchorPlacesAtTopEdge() {
let screen = CGRect(x: 0, y: 0, width: 1000, height: 800) let screen = CGRect(x: 0, y: 0, width: 1000, height: 800)
let size = CGSize(width: 1000, height: 30) let size = CGSize(width: 1000, height: 30)
let origin = PHThemeAnchor.top.origin(in: screen, size: size, margin: .init()) let origin = PHThemeWindowAnchor.top.origin(in: screen, size: size, margin: .init())
#expect(origin == CGPoint(x: 0, y: 770)) #expect(origin == CGPoint(x: 0, y: 770))
} }
@Test func anchorRespectsTopMargin() { @Test func anchorRespectsTopMargin() {
let screen = CGRect(x: 0, y: 0, width: 1000, height: 800) let screen = CGRect(x: 0, y: 0, width: 1000, height: 800)
let size = CGSize(width: 1000, height: 30) let size = CGSize(width: 1000, height: 30)
let origin = PHThemeAnchor.top.origin(in: screen, size: size, margin: .init(top: 10)) let origin = PHThemeWindowAnchor.top.origin(in: screen, size: size, margin: .init(top: 10))
#expect(origin == CGPoint(x: 0, y: 760)) #expect(origin == CGPoint(x: 0, y: 760))
} }
@Test func anchorPlacesBottomLeadingCorner() { @Test func anchorPlacesBottomLeadingCorner() {
let screen = CGRect(x: 0, y: 0, width: 1000, height: 800) let screen = CGRect(x: 0, y: 0, width: 1000, height: 800)
let size = CGSize(width: 200, height: 40) let size = CGSize(width: 200, height: 40)
let origin = PHThemeAnchor.bottomLeading.origin( let origin = PHThemeWindowAnchor.bottomLeading.origin(
in: screen, size: size, margin: .init(bottom: 8, leading: 12) in: screen, size: size, margin: .init(bottom: 8, leading: 12)
) )
#expect(origin == CGPoint(x: 12, y: 8)) #expect(origin == CGPoint(x: 12, y: 8))
@@ -511,7 +511,7 @@ private struct DimensionWrapper: Decodable {
@Test func anchorTrailingCentersVertically() { @Test func anchorTrailingCentersVertically() {
let screen = CGRect(x: 0, y: 0, width: 1000, height: 800) let screen = CGRect(x: 0, y: 0, width: 1000, height: 800)
let size = CGSize(width: 200, height: 40) let size = CGSize(width: 200, height: 40)
let origin = PHThemeAnchor.trailing.origin( let origin = PHThemeWindowAnchor.trailing.origin(
in: screen, size: size, margin: .init(trailing: 20) in: screen, size: size, margin: .init(trailing: 20)
) )
#expect(origin == CGPoint(x: 780, y: 380)) #expect(origin == CGPoint(x: 780, y: 380))
@@ -520,7 +520,7 @@ private struct DimensionWrapper: Decodable {
@Test func anchorCentersOnBothAxesIgnoringMargin() { @Test func anchorCentersOnBothAxesIgnoringMargin() {
let screen = CGRect(x: 0, y: 0, width: 1000, height: 800) let screen = CGRect(x: 0, y: 0, width: 1000, height: 800)
let size = CGSize(width: 200, height: 40) let size = CGSize(width: 200, height: 40)
let origin = PHThemeAnchor.center.origin(in: screen, size: size, margin: .init(top: 999)) let origin = PHThemeWindowAnchor.center.origin(in: screen, size: size, margin: .init(top: 999))
#expect(origin == CGPoint(x: 400, y: 380)) #expect(origin == CGPoint(x: 400, y: 380))
} }
@@ -641,7 +641,7 @@ private func makeBlocksConfigDir() throws -> URL {
@Test func computeFrameUsesAbsoluteOriginOverAnchor() throws { @Test func computeFrameUsesAbsoluteOriginOverAnchor() throws {
let screen = try #require(NSScreen.main) let screen = try #require(NSScreen.main)
let theme = PHTheme( let theme = PHTheme(
windows: [PHThemeWindow(name: "abs", anchor: .bottom, origin: PHThemePoint(x: 100, y: 200))], windows: [PHThemeWindow(name: "abs", anchor: .bottom, origin: PHThemeWindowPoint(x: 100, y: 200))],
texts: nil, texts: nil,
styles: nil styles: nil
) )