Album art theme on web and iOS, roomier player bar
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0c9cae5b11
commit
8e57b9d0cd
8 files changed
+116
-10
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
extension Color {
|
||||
init(hex: UInt32, alpha: Double = 1) {
|
||||
@@ -84,3 +85,44 @@ private struct ThemedRow: ViewModifier {
|
||||
content.listRowBackground(grouped ? p.cell : p.bg).listRowSeparatorTint(p.separator)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- album art theme ----------------------------------------------------------------------------
|
||||
|
||||
/// One hue taken from the album art (see vibrant in NowPlayingScreen).
|
||||
struct ArtHue: Equatable { var h, s, v: CGFloat }
|
||||
|
||||
@MainActor
|
||||
func artHue(_ thumb: String?) async -> ArtHue? {
|
||||
guard let url = AppGraph.shared.plex.artUrl(thumb, px: 120) else { return nil }
|
||||
let img: UIImage? = if let c = ArtLoader.shared.cached(url) { c } else { await ArtLoader.shared.image(url) }
|
||||
guard let cg = img?.cgImage else { return nil }
|
||||
return await Task.detached { () -> ArtHue? in
|
||||
guard let (h, s, v) = vibrant(cg), s >= 0.12 else { return nil }
|
||||
return ArtHue(h: h, s: s, v: v)
|
||||
}.value
|
||||
}
|
||||
|
||||
extension Palette {
|
||||
/// The theme recoloured around the art's hue: lightly tinted surfaces and an accent in the art's colour.
|
||||
/// Black keeps its true-black background for OLED.
|
||||
func art(_ a: ArtHue, mode: ThemeMode) -> Palette {
|
||||
var c = self
|
||||
let s = min(a.s, 0.9), t = min(s * 0.5, 0.3)
|
||||
func hsb(_ sat: CGFloat, _ b: CGFloat) -> Color { Color(hue: a.h, saturation: sat, brightness: b) }
|
||||
switch mode {
|
||||
case .White:
|
||||
c.bg = hsb(t * 0.25, 1); c.groupedBg = hsb(t * 0.45, 0.965); c.cell = hsb(t * 0.2, 1)
|
||||
c.fill = hsb(t * 0.5, 0.94); c.fillStrong = hsb(t * 0.6, 0.89); c.separator = hsb(t * 0.6, 0.86)
|
||||
c.accent = hsb(max(s, 0.6), min(max(a.v, 0.5), 0.62))
|
||||
case .Dark:
|
||||
c.bg = hsb(t, 0.11); c.groupedBg = c.bg; c.cell = hsb(t, 0.17)
|
||||
c.fill = c.cell; c.fillStrong = hsb(t, 0.27); c.separator = hsb(t, 0.22)
|
||||
c.accent = hsb(max(s, 0.5), max(a.v, 0.85))
|
||||
case .Black:
|
||||
c.cell = hsb(t, 0.11); c.fill = c.cell; c.fillStrong = hsb(t, 0.22); c.separator = hsb(t, 0.17)
|
||||
c.accent = hsb(max(s, 0.5), max(a.v, 0.85))
|
||||
}
|
||||
c.placeholder = c.fill
|
||||
return c
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user