From 75c2e90093ed8cef0fb2f564a9466b89c1c0d819 Mon Sep 17 00:00:00 2001 From: Jiun Bae Date: Thu, 19 Nov 2026 19:37:01 +0900 Subject: [PATCH] fix(menubar): a stacked chip's glyph stays in the middle of its chip; stacked by default 0.7.43 moved a covered chip's glyph into the part of the chip left in view and shrank it to fit. The glyphs then no longer sat in the middle of their chips, which is the one thing they must do. A glyph is always at its disc's centre at full size now; stacked, the chip on top covers part of the one beneath, glyph included, as a stack of avatars does. Stacked is the default spacing again (it was until 0.7.43); a spacing chosen in Settings is kept. Co-Authored-By: Claude Fable 5.2 --- Localization/Localizable.xcstrings | 4 +- RELEASE_NOTES.md | 3 + .../MenuBarClusterRenderer.swift | 72 +++------------- .../MenubucketApp/Settings/MenuBarPage.swift | 4 +- Sources/MenubucketCore/ChipAppearance.swift | 2 +- Sources/MenubucketCore/MenuBarCluster.swift | 2 +- .../ChipAppearanceTests.swift | 83 ++++++++----------- .../ChipAppearanceTests.swift | 6 +- .../MenuBarClusterTests.swift | 8 +- 9 files changed, 62 insertions(+), 122 deletions(-) diff --git a/Localization/Localizable.xcstrings b/Localization/Localizable.xcstrings index 6a36274..ecb3457 100644 --- a/Localization/Localizable.xcstrings +++ b/Localization/Localizable.xcstrings @@ -3325,12 +3325,12 @@ } } }, - "Chips overlap to save room. A covered chip shows a smaller icon in the part still in view.": { + "Chips overlap to save room, each one over the next.": { "localizations": { "ko": { "stringUnit": { "state": "translated", - "value": "칩을 겹쳐 자리를 아낍니다. 가려진 칩은 보이는 부분에 아이콘을 작게 표시합니다." + "value": "자리를 아끼도록 칩을 앞에서부터 차례로 겹쳐 놓습니다." } } } diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index aa52274..6674b49 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -3,3 +3,6 @@ > Unreleased. Requires macOS 14+ on Apple Silicon. ## Changes + +- Chips in the menu bar are stacked again by default, each one over the next, as before 0.7.43. Side by side is still there under Settings ▸ Menu Bar ▸ Chips ▸ Spacing; if you chose a spacing there, it is kept. +- A stacked chip's icon stays in the middle of its chip at full size. In 0.7.43 it was made smaller and moved into the part of the chip left in view, so the icons no longer lined up with their chips. diff --git a/Sources/MenubucketApp/MenuBarClusterRenderer.swift b/Sources/MenubucketApp/MenuBarClusterRenderer.swift index 9ac49ad..be66139 100644 --- a/Sources/MenubucketApp/MenuBarClusterRenderer.swift +++ b/Sources/MenubucketApp/MenuBarClusterRenderer.swift @@ -49,13 +49,6 @@ extension MenuBarController { /// A glyph may sit this far from its drawing's bounding-box middle, /// towards where its weight is (`GlyphCache`). static let opticalLimit: CGFloat = 1 - /// Stacked, the glyph of a covered chip keeps this much clear of - /// the edges of the part in view. - static let coverMargin: CGFloat = 1.5 - /// How quickly a chip the update wave lifts over its neighbour - /// takes the neighbour's place on top: the glyphs glide between - /// "covered" and "whole" over a quarter of the lift, not in a jump. - static let coverBlend: CGFloat = 4 /// The arc's track, barely there. static let trackAlpha: CGFloat = 0.12 static let staleAlpha = CGFloat(Fill.staleOpacity) @@ -297,9 +290,7 @@ extension MenuBarController { ) -> NSImage { let geometry = ClusterGeometry(count: chips.count, spacing: look.spacing) let dark = isDark(appearance) - // A glyph moved aside (below) still starts on a pixel of the - // coarsest display. - let pixel = 1 / max((GlyphCache.shared.scalesForTesting ?? screenScales()).min() ?? 1, 1) + let size = NSSize(width: ceil(lead + geometry.itemWidth), height: height) let image = NSImage(size: size, flipped: true) { _ in appearance.performAsCurrentDrawingAppearance { @@ -328,44 +319,10 @@ extension MenuBarController { func pillLeft(_ index: Int) -> CGFloat { (positions?[cluster: index] ?? CGFloat(geometry.collapsedX(index))) + CGFloat(ClusterGeometry.slotInset) } - // The drawn shape's edges: a disc, or the focused pill. - func leading(_ index: Int) -> CGFloat { - index == focused && focusedIsPill ? pillLeft(index) : center(index).x - m.face * scale(index) / 2 - } - func trailing(_ index: Int) -> CGFloat { - index == focused && focusedIsPill - ? pillLeft(index) + max(pillSpan, m.face * m.focusScale) - : center(index).x + m.face * scale(index) / 2 - } - // How far `over` is on top of its neighbour `under`, 0...1. - // At rest the earlier chip is on top; the focused chip is on - // top of both neighbours, and so is a chip the wave lifts - // higher than them (`coverBlend`). - func cover(_ over: Int, _ under: Int) -> CGFloat { - if under == focused { return 0 } - if over == focused { return 1 } - let ahead = min(max((lift(over) - lift(under)) * m.coverBlend, -1), 1) - return over < under ? 1 + min(ahead, 0) : max(ahead, 0) - } - // Where a chip's glyph goes: the middle of the part of the - // chip in view, smaller if that part is narrower than the - // glyph. Stacked, a glyph in the middle of its disc was cut - // in half by the chip over it. Taken from where the chips - // are drawn now, so it glides as they fold and fan. - func glyphPlace(_ index: Int) -> GlyphPlace { - let middle = center(index).x, size = scale(index) - var low = middle - m.face * size / 2, high = middle + m.face * size / 2 - if index > 0 { - low += cover(index - 1, index) * max(0, trailing(index - 1) + m.cutout - low) - } - if index < chips.count - 1 { - high -= cover(index + 1, index) * max(0, high - (leading(index + 1) - m.cutout)) - } - let free = max(high - low, 0) - guard free < m.face * size - 0.01 else { return GlyphPlace(x: middle, factor: 1) } - let x = ((low + high) / 2 / pixel).rounded() * pixel - return GlyphPlace(x: x, factor: min(1, max(0, free - m.coverMargin) / (look.glyphCircle * size))) - } + // A chip's glyph is always at the middle of its disc, at + // full size. Stacked, the chip on top covers part of the one + // beneath, glyph included, as a stack of avatars does: + // moving the glyph into the part in view put it off centre. // Folded, each chip lies over the one to its right, as a // stack of avatars does, so a chip's top-trailing corner — // where its alert dot goes — is over the chip beneath and in @@ -376,7 +333,7 @@ extension MenuBarController { for index in order { drawChip( chips[index], at: center(index), color: color(chips[index]), context: context, - scale: scale(index), glow: lift(index), look: look, dark: dark, glyph: glyphPlace(index) + scale: scale(index), glow: lift(index), look: look, dark: dark ) // With its chip, so a chip drawn later covers it as it // covers the chip, and it grows with the chip. @@ -453,17 +410,9 @@ extension MenuBarController { tinted.draw(in: fitted, from: .zero, operation: .sourceOver, fraction: alpha, respectFlipped: true, hints: nil) } - /// Where a chip's glyph is drawn when not at its disc's centre at full - /// size: `x` is its middle, `factor` how much smaller it is. - struct GlyphPlace: Equatable { - var x: CGFloat - var factor: CGFloat - } - static func drawChip( _ chip: ClusterChip, at center: NSPoint, color: NSColor, context: NSGraphicsContext, - scale: CGFloat = 1, glow: CGFloat = 0, look: ChipAppearance = ChipAppearance(), dark: Bool = true, - glyph place: GlyphPlace? = nil + scale: CGFloat = 1, glow: CGFloat = 0, look: ChipAppearance = ChipAppearance(), dark: Bool = true ) { let m = ChipMetrics.self let face = m.face * scale @@ -485,10 +434,10 @@ extension MenuBarController { let disc = circle(face) Self.paint(disc, rim: circle(face - m.rimWidth), in: disc.bounds, with: paint) - let size = scale * (place?.factor ?? 1) + let size = scale guard size > 0 else { return } drawGlyph( - chip, at: NSPoint(x: place?.x ?? center.x, y: center.y), alpha: alpha, scale: size, + chip, at: center, alpha: alpha, scale: size, look: look, ink: paint, context: context ) } @@ -698,8 +647,7 @@ final class GlyphCache: @unchecked Sendable { } /// Main actor: the key includes the attached displays' densities. - /// `scale` is the chip's (a chip in focus or in the wave is larger, a - /// covered one's glyph smaller). + /// `scale` is the chip's (a chip in focus or in the wave is larger). @MainActor func glyph(_ name: String, look: ChipAppearance = ChipAppearance(), scale: CGFloat = 1) -> NSImage? { guard let source = source(name, set: look.glyphSet) else { return nil } diff --git a/Sources/MenubucketApp/Settings/MenuBarPage.swift b/Sources/MenubucketApp/Settings/MenuBarPage.swift index 9ed9cb9..2d2ca82 100644 --- a/Sources/MenubucketApp/Settings/MenuBarPage.swift +++ b/Sources/MenubucketApp/Settings/MenuBarPage.swift @@ -161,11 +161,11 @@ struct MenuBarPage: View { "Spacing", caption: look.spacing == .apart ? "Chips sit side by side, each one whole." - : "Chips overlap to save room. A covered chip shows a smaller icon in the part still in view.", + : "Chips overlap to save room, each one over the next.", selection: chipBinding(\.spacing) ) { - Text("Apart", comment: "Chip spacing: side by side").tag(ChipAppearance.Spacing.apart) Text("Stacked", comment: "Chip spacing: overlapping").tag(ChipAppearance.Spacing.stacked) + Text("Apart", comment: "Chip spacing: side by side").tag(ChipAppearance.Spacing.apart) } } header: { Text("Chips") diff --git a/Sources/MenubucketCore/ChipAppearance.swift b/Sources/MenubucketCore/ChipAppearance.swift index b25b90c..79e6c71 100644 --- a/Sources/MenubucketCore/ChipAppearance.swift +++ b/Sources/MenubucketCore/ChipAppearance.swift @@ -49,7 +49,7 @@ public struct ChipAppearance: Codable, Equatable, Sendable { public init( style: Style = .solid, tone: Tone = .balanced, glyphSet: GlyphSet = .simple, - glyphSize: GlyphSize = .medium, spacing: Spacing = .apart + glyphSize: GlyphSize = .medium, spacing: Spacing = .stacked ) { self.style = style self.tone = tone diff --git a/Sources/MenubucketCore/MenuBarCluster.swift b/Sources/MenubucketCore/MenuBarCluster.swift index d53e4fd..4fc2461 100644 --- a/Sources/MenubucketCore/MenuBarCluster.swift +++ b/Sources/MenubucketCore/MenuBarCluster.swift @@ -284,7 +284,7 @@ public struct ClusterGeometry: Equatable, Sendable { /// The BarShelf icon's square. public static let markWidth: Double = 22 - public init(count: Int, spacing: ChipAppearance.Spacing = .apart) { + public init(count: Int, spacing: ChipAppearance.Spacing = ChipAppearance().spacing) { self.count = max(count, 0) self.collapsedStep = Self.foldedStep(for: spacing) } diff --git a/Tests/MenubucketAppTests/ChipAppearanceTests.swift b/Tests/MenubucketAppTests/ChipAppearanceTests.swift index 833acfd..09505b2 100644 --- a/Tests/MenubucketAppTests/ChipAppearanceTests.swift +++ b/Tests/MenubucketAppTests/ChipAppearanceTests.swift @@ -140,76 +140,65 @@ final class ChipAppearanceTests: XCTestCase { print(String(format: "CHIP-CENTRING apart: worst optical offset x %.3f pt, y %.3f pt; worst box offset x %.3f pt", worstX, worstY, worstBox)) } - /// Stacked, a chip lies over the one to its right. The covered chip's - /// glyph is whole, inside the part of the chip in view and in the - /// middle of it; the chip on top is as it is alone. - func testStackedACoveredGlyphIsWholeInTheMiddleOfWhatShows() throws { + /// Stacked, a chip lies over the one to its right, glyph and all. The + /// covered chip's glyph stays where it is on a chip alone, in the + /// middle of its disc at full size: what shows of it is exactly that + /// part of the glyph, not a smaller glyph moved into the part in view. + func testStackedACoveredGlyphStaysInTheMiddleOfItsDisc() throws { let m = MenuBarController.ChipMetrics.self - var worst = 0.0 + let face = Double(m.face) for set in ChipAppearance.GlyphSet.allCases { let look = ChipAppearance(glyphSet: set, spacing: .stacked) let geometry = ClusterGeometry(count: 3, spacing: .stacked) XCTAssertLessThan(geometry.collapsedStep, ClusterGeometry.disc, "the discs overlap") for trio in Self.trios { let rep = try render(chips(trio), look: look) - let face = Double(m.face) - // The chip on top. + // The chip on top is as it is alone. let top = ink(rep, from: center(0, geometry) - face / 2, to: center(0, geometry) + face / 2) - let alone = ink(try render(chips([trio[0]]), look: look), from: 0, to: ClusterGeometry.slot) - XCTAssertEqual(top.width, alone.width, accuracy: 0.3, "\(trio[0]) on top changed") - XCTAssertEqual(top.height, alone.height, accuracy: 0.3, "\(trio[0]) on top changed") + let first = ink(try render(chips([trio[0]]), look: look), from: 0, to: ClusterGeometry.slot) + XCTAssertEqual(top.width, first.width, accuracy: 0.3, "\(trio[0]) on top changed") XCTAssertEqual(top.midX, center(0, geometry), accuracy: 0.3, "\(trio[0]) on top moved") for index in 1..