Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/StableBar/ThemeCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ struct ThemeSampleBar: View {
.padding(.top, look.defaults.paddingTop ?? appearance.paddingVertical)
.padding(.bottom, look.defaults.paddingBottom ?? appearance.paddingVertical)
.background {
if focused && workspace?.indicator != .underline {
// As on the bar: no indicator means the background one, and `none` leaves the focused label alone.
if focused && (workspace?.indicator ?? .background) == .background {
RoundedRectangle(cornerRadius: style.cornerRadius ?? max(appearance.cornerRadius - 4, 0))
.fill(style.background?.shapeStyle ?? AnyShapeStyle(appearance.accent))
}
Expand Down
29 changes: 29 additions & 0 deletions Tests/StableBarTests/ThemeCardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ final class ThemeCardTests: XCTestCase {
}
}

@MainActor func testSampleBarFillsTheFocusedWorkspaceOnlyForTheBackgroundIndicator() throws {
let fixture = try ThemeGalleryFixture()
defer { fixture.close() }
// Only the accent is magenta, so magenta pixels can only come from the focused workspace's fill.
for (indicator, fills) in [(#""indicator":"none","#, false), (#""indicator":"background","#, true), ("", true)] {
let choice = try fixture.theme(##"""
{"defaults":{"foreground":"#ffffff","accent":"#ff00ff","accentText":"#00ff00"},
"workspaceDefaults":{\##(indicator)"style":{"states":{"focused":{"foreground":"#00ff00"}}}}}
"""##, install: false)
let look = try ThemePreview(choice: choice, themesDirectory: fixture.themes).configuration(for: .dark)
let renderer = ImageRenderer(content: ThemeSampleBar(look: look).frame(width: 580))
let bitmap = NSBitmapImageRep(cgImage: try XCTUnwrap(renderer.cgImage))
var accentPixels = 0
for y in 0..<bitmap.pixelsHigh {
for x in 0..<bitmap.pixelsWide {
if let color = bitmap.colorAt(x: x, y: y), color.alphaComponent > 0.8,
color.redComponent > 0.8 && color.blueComponent > 0.8 && color.greenComponent < 0.2 {
accentPixels += 1
}
}
}
if fills {
XCTAssertGreaterThan(accentPixels, 50, "The \(indicator.isEmpty ? "default" : indicator) indicator fills the focused workspace")
} else {
XCTAssertEqual(accentPixels, 0, "A text-only focused workspace has nothing behind it, as on the bar")
}
}
}

@MainActor func testEveryBundledThemeCardFitsTheProposedWidth() throws {
let fixture = try ThemeGalleryFixture()
defer { fixture.close() }
Expand Down
6 changes: 6 additions & 0 deletions scenes/settings-theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../scene.schema.json",
"configuration": "../Resources/config.json",
"draw": "settings",
"section": "theme"
}
Loading