From f7df2fa2deb7651da65efa85a5fe295af986e821 Mon Sep 17 00:00:00 2001 From: phranck Date: Wed, 28 Jan 2026 22:43:15 +0100 Subject: [PATCH] feat(Menu): Add appearance-based selection highlighting - Block appearance uses background highlight for selected items - Other appearances use arrow indicator prefix - Selected item in block appearance swaps foreground/background colors --- Sources/TUIKit/Views/Menu.swift | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Sources/TUIKit/Views/Menu.swift b/Sources/TUIKit/Views/Menu.swift index 4013dbf..7513926 100644 --- a/Sources/TUIKit/Views/Menu.swift +++ b/Sources/TUIKit/Views/Menu.swift @@ -200,10 +200,12 @@ extension Menu: Renderable { // Menu items let currentSelection = selectionBinding?.wrappedValue ?? selectedIndex + let appearance = context.environment.appearance + let isBlockAppearance = appearance.id == .block + for (index, item) in items.enumerated() { let isSelected = index == currentSelection - let prefix = isSelected ? selectionIndicator : String(repeating: " ", count: selectionIndicator.count) - + // Build the label with optional shortcut let labelText: String if let shortcut = item.shortcut { @@ -212,13 +214,28 @@ extension Menu: Renderable { labelText = " \(item.label)" } - let fullText = " " + prefix + labelText + // For block appearance: no indicator, use background highlight + // For other appearances: use indicator prefix + let fullText: String + if isBlockAppearance { + fullText = " " + labelText + } else { + let prefix = isSelected ? selectionIndicator : String(repeating: " ", count: selectionIndicator.count) + fullText = " " + prefix + labelText + } // Apply styling var style = TextStyle() if isSelected { style.isBold = true - style.foregroundColor = selectedColor ?? Color.theme.accent + if isBlockAppearance { + // Block appearance: use background highlight + style.foregroundColor = Color.theme.background + style.backgroundColor = selectedColor ?? Color.theme.accent + } else { + // Other appearances: just change foreground color + style.foregroundColor = selectedColor ?? Color.theme.accent + } } else { // Use theme foreground color if no custom itemColor is set style.foregroundColor = itemColor ?? Color.theme.foreground