From cc5902a43df48774db81b2c45adad94c53b85f57 Mon Sep 17 00:00:00 2001 From: Roy Natian Date: Tue, 10 Feb 2026 03:01:22 -0500 Subject: [PATCH] normalized spacing in menu popup Signed-off-by: Roy Natian --- Sources/CodexBar/MenuCardView.swift | 23 +++----- .../CodexBar/StatusItemController+Menu.swift | 56 ++++++++----------- 2 files changed, 32 insertions(+), 47 deletions(-) diff --git a/Sources/CodexBar/MenuCardView.swift b/Sources/CodexBar/MenuCardView.swift index 5c0bb2d9b..953915156 100644 --- a/Sources/CodexBar/MenuCardView.swift +++ b/Sources/CodexBar/MenuCardView.swift @@ -166,8 +166,8 @@ struct UsageMenuCardView: View { } } .padding(.horizontal, 16) - .padding(.top, 2) - .padding(.bottom, 2) + .padding(.top, 8) + .padding(.bottom, 6) .frame(width: self.width, alignment: .leading) } @@ -363,21 +363,14 @@ private struct MetricRow: View { struct UsageMenuCardHeaderSectionView: View { let model: UsageMenuCardView.Model - let showDivider: Bool let width: CGFloat var body: some View { - VStack(alignment: .leading, spacing: 6) { - UsageMenuCardHeaderView(model: self.model) - - if self.showDivider { - Divider() - } - } - .padding(.horizontal, 16) - .padding(.top, 2) - .padding(.bottom, self.model.subtitleStyle == .error ? 2 : 0) - .frame(width: self.width, alignment: .leading) + UsageMenuCardHeaderView(model: self.model) + .padding(.horizontal, 16) + .padding(.top, 8) + .padding(.bottom, 8) + .frame(width: self.width, alignment: .leading) } } @@ -408,7 +401,7 @@ struct UsageMenuCardUsageSectionView: View { } } .padding(.horizontal, 16) - .padding(.top, 10) + .padding(.top, 8) .padding(.bottom, self.bottomPadding) .frame(width: self.width, alignment: .leading) } diff --git a/Sources/CodexBar/StatusItemController+Menu.swift b/Sources/CodexBar/StatusItemController+Menu.swift index 259d2bd5b..e953328e4 100644 --- a/Sources/CodexBar/StatusItemController+Menu.swift +++ b/Sources/CodexBar/StatusItemController+Menu.swift @@ -292,7 +292,6 @@ extension StatusItemController { UsageMenuCardView(model: model, width: context.menuWidth), id: "menuCard", width: context.menuWidth)) - menu.addItem(.separator()) } else { for (index, model) in cards.enumerated() { menu.addItem(self.makeMenuCardItem( @@ -303,9 +302,6 @@ extension StatusItemController { menu.addItem(.separator()) } } - if !cards.isEmpty { - menu.addItem(.separator()) - } } return false } @@ -332,7 +328,6 @@ extension StatusItemController { if context.currentProvider == .codex, model.creditsText != nil { menu.addItem(self.makeBuyCreditsItem()) } - menu.addItem(.separator()) return false } @@ -355,7 +350,6 @@ extension StatusItemController { _ = self.addCostHistorySubmenu(to: menu, provider: currentProvider) } } - menu.addItem(.separator()) } private func addActionableSections(_ sections: [MenuDescriptor.Section], to menu: NSMenu) { @@ -366,6 +360,9 @@ extension StatusItemController { } } for (index, section) in actionableSections.enumerated() { + // Add a separator before each section group with a spacer for consistent padding + menu.addItem(.separator()) + self.addMenuSpacer(to: menu, height: 4) for entry in section.entries { switch entry { case let .text(text, style): @@ -404,12 +401,19 @@ extension StatusItemController { menu.addItem(.separator()) } } - if index < actionableSections.count - 1 { - menu.addItem(.separator()) - } + // Add trailing spacer after each section group for consistent padding + self.addMenuSpacer(to: menu, height: 4) } } + private func addMenuSpacer(to menu: NSMenu, height: CGFloat) { + let spacerView = NSView(frame: NSRect(x: 0, y: 0, width: 1, height: height)) + let spacerItem = NSMenuItem() + spacerItem.view = spacerView + spacerItem.isEnabled = false + menu.addItem(spacerItem) + } + func makeMenu(for provider: UsageProvider?) -> NSMenu { let menu = NSMenu() menu.autoenablesItems = false @@ -658,22 +662,20 @@ extension StatusItemController { let hasCredits = model.creditsText != nil let hasExtraUsage = model.providerCost != nil let hasCost = model.tokenUsage != nil - let bottomPadding = CGFloat(hasCredits ? 4 : 6) - let sectionSpacing = CGFloat(6) - let usageBottomPadding = bottomPadding - let creditsBottomPadding = bottomPadding + let sectionPadding = CGFloat(6) + let sectionSpacing = CGFloat(8) let headerView = UsageMenuCardHeaderSectionView( model: model, - showDivider: hasUsageBlock, width: width) menu.addItem(self.makeMenuCardItem(headerView, id: "menuCardHeader", width: width)) if hasUsageBlock { + menu.addItem(.separator()) let usageView = UsageMenuCardUsageSectionView( model: model, showBottomDivider: false, - bottomPadding: usageBottomPadding, + bottomPadding: sectionPadding, width: width) let usageSubmenu = self.makeUsageSubmenu( provider: provider, @@ -686,19 +688,13 @@ extension StatusItemController { submenu: usageSubmenu)) } - if hasCredits || hasExtraUsage || hasCost { - menu.addItem(.separator()) - } - if hasCredits { - if hasExtraUsage || hasCost { - menu.addItem(.separator()) - } + menu.addItem(.separator()) let creditsView = UsageMenuCardCreditsSectionView( model: model, showBottomDivider: false, topPadding: sectionSpacing, - bottomPadding: creditsBottomPadding, + bottomPadding: sectionPadding, width: width) let creditsSubmenu = webItems.hasCreditsHistory ? self.makeCreditsHistorySubmenu() : nil menu.addItem(self.makeMenuCardItem( @@ -711,13 +707,11 @@ extension StatusItemController { } } if hasExtraUsage { - if hasCredits { - menu.addItem(.separator()) - } + menu.addItem(.separator()) let extraUsageView = UsageMenuCardExtraUsageSectionView( model: model, topPadding: sectionSpacing, - bottomPadding: bottomPadding, + bottomPadding: sectionPadding, width: width) menu.addItem(self.makeMenuCardItem( extraUsageView, @@ -725,13 +719,11 @@ extension StatusItemController { width: width)) } if hasCost { - if hasCredits || hasExtraUsage { - menu.addItem(.separator()) - } + menu.addItem(.separator()) let costView = UsageMenuCardCostSectionView( model: model, topPadding: sectionSpacing, - bottomPadding: bottomPadding, + bottomPadding: sectionPadding, width: width) let costSubmenu = webItems.hasCostHistory ? self.makeCostHistorySubmenu(provider: provider) : nil menu.addItem(self.makeMenuCardItem( @@ -891,7 +883,7 @@ extension StatusItemController { RoundedRectangle(cornerRadius: 6, style: .continuous) .fill(MenuHighlightStyle.selectionBackground(true)) .padding(.horizontal, 6) - .padding(.vertical, 2) + .padding(.vertical, 1) } } .overlay(alignment: .topTrailing) {