### SwiftUI MenuSection and MenuHeader - Section Labels Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Demonstrates the usage of MenuSection and MenuHeader components within SwiftUI to create organized menu structures. It shows examples of sections with and without dividers, and headers with trailing content to display supplementary information. ```swift import MacControlCenterUI import SwiftUI struct OrganizedMenu: View { @State private var connected: Bool = true var body: some View { VStack { // Basic section with divider MenuSection("Display") // Display controls here... // Section without divider MenuSection("Sound", divider: false) // Sound controls here... // Header with trailing content MenuHeader { Text("Wi-Fi") } trailing: { HStack(spacing: 4) { Circle().fill(connected ? Color.green : Color.red).frame(width: 6, height: 6) Text(connected ? "Connected" : "Disconnected").font(.system(size: 11)).opacity(0.7) } } // Wi-Fi controls here... } } } ``` -------------------------------- ### Swift Package Installation Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Adds MacControlCenterUI to your Swift package dependencies. It requires Xcode 14 and macOS 12.5 or later. ```swift // Package.swift dependencies: [ .package(url: "https://github.com/orchetect/MacControlCenterUI", from: "2.3.0") ] ``` -------------------------------- ### SwiftUI Menu Bar App with MacControlCenterUI Components Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt This Swift code defines the main application struct and a view for a menu bar application. It utilizes MacControlCenterUI for creating interactive menu items like sliders, toggles, and lists. The example manages state for brightness, volume, dark mode, and audio device selection, demonstrating a complete application flow. ```swift import MacControlCenterUI import SwiftUI @main struct ControlCenterDemoApp: App { @State var isMenuPresented: Bool = false var body: some Scene { MenuBarExtra("Control Center Demo", systemImage: "slider.horizontal.3") { CompleteMenuView(isMenuPresented: $isMenuPresented) } .menuBarExtraStyle(.window) .menuBarExtraAccess(isPresented: $isMenuPresented) Settings { SettingsView() } } } struct CompleteMenuView: View { @Environment(\.openSettings) var openSettings @Binding var isMenuPresented: Bool // State @State private var brightness: CGFloat = 0.6 @State private var volume: CGFloat = 0.75 @State private var darkMode: Bool = false @State private var nightShift: Bool = true @State private var trueTone: Bool = true @State private var wifiEnabled: Bool = true @State private var bluetoothEnabled: Bool = true // Data @State private var audioDevices: [MenuEntry] = [ MenuEntry(name: "MacBook Speakers", image: Image(systemName: "hifispeaker.fill")), MenuEntry(name: "AirPods Pro", image: Image(systemName: "airpodspro")), MenuEntry(name: "External Display", image: Image(systemName: "display")) ] @State private var selectedAudioDevice: UUID? = nil var body: some View { MacControlCenterMenu( isPresented: $isMenuPresented, activateAppOnCommandSelection: true ) { // Display Controls Section MenuSection("Display", divider: false) MenuSlider( value: $brightness, image: Image(systemName: "sun.max.fill") ) .frame(minWidth: 180) HStack { MenuCircleToggle( isOn: $darkMode, controlSize: .prominent, style: .init( image: Image(systemName: "moon.fill"), color: .blue, invertForeground: true ) ) { Text("Dark Mode") } MenuCircleToggle( isOn: $nightShift, controlSize: .prominent, style: .init( image: Image(systemName: "sun.max.fill"), color: .orange ) ) { Text("Night Shift") } MenuCircleToggle( isOn: $trueTone, controlSize: .prominent, style: .init( image: Image(systemName: "sun.max.fill"), color: .cyan ) ) { Text("True Tone") } } .frame(height: 80) // Sound Section MenuSection("Sound") MenuVolumeSlider(value: $volume) .frame(minWidth: 180) MenuCommand("Sound Settings...") { print("Opening sound settings") } // Audio Output Section MenuSection("Audio Output") MenuList(audioDevices, selection: $selectedAudioDevice) { item in MenuToggle(image: item.image) { HStack { Text(item.name) Spacer() if item.name.contains("AirPods") { HStack(spacing: 2) { Text("85%") Image(systemName: "battery.100", variableValue: 0.85) } .font(.system(size: 10)) .opacity(0.7) } } } } // Connectivity Section MenuSection("Connectivity") MenuToggle( "Wi-Fi", isOn: $wifiEnabled, image: Image(systemName: "wifi") ) MenuToggle( "Bluetooth", isOn: $bluetoothEnabled, image: Image(systemName: "bluetooth") ) Divider() // Application Commands MenuCommand { showAbout() } label: { Text("About") } MenuCommand { openSettings() } label: { Text("Settings...") } Divider() MenuCommand("Quit") { NSApp.terminate(nil) } } } func showAbout() { NSApp.sendAction( ``` -------------------------------- ### SwiftUI - Settings View Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt This snippet shows a basic SwiftUI view for settings. It demonstrates how to create a simple text-based view and apply frame modifiers. ```swift struct SettingsView: View { var body: some View { Text("Settings") .frame(width: 300, height: 200) } } ``` -------------------------------- ### Create Basic Menu Bar Application Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Demonstrates the creation of a basic menu bar application using MacControlCenterUI. It includes menu items like a slider, toggle, and quit command. It requires macOS 11.0+ and SwiftUI. ```swift import MacControlCenterUI import SwiftUI @main struct MyApp: App { @State var isMenuPresented: Bool = false @State var brightness: CGFloat = 0.5 @State var darkMode: Bool = false var body: some Scene { MenuBarExtra("MyApp", systemImage: "slider.horizontal.3") { MacControlCenterMenu(isPresented: $isMenuPresented) { MenuSection("Display", divider: false) MenuSlider( value: $brightness, image: Image(systemName: "sun.max.fill") ) MenuCircleToggle( "Dark Mode", isOn: $darkMode, controlSize: .prominent, style: .init( image: Image(systemName: "moon.fill")), color: .blue ) ) Divider() MenuCommand("Quit") { NSApp.terminate(nil) } } } .menuBarExtraStyle(.window) // Required for custom rendering .menuBarExtraAccess(isPresented: $isMenuPresented) // Required for menu control } } ``` -------------------------------- ### Create clickable menu items with MenuCommand (Swift) Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Implements traditional menu items with click actions, hover highlighting, and menu dismissal control. Supports custom labels, environment actions, and background tasks. Requires MacControlCenterUI and SwiftUI frameworks. ```swift import MacControlCenterUI import SwiftUI struct ActionsMenu: View { @Binding var isMenuPresented: Bool @Environment(\.openSettings) var openSettings var body: some View { VStack { // Basic command with string title MenuCommand("Sound Settings...") { print("Opening sound settings") // Open your settings panel here } // Command with custom label view MenuCommand { showAboutWindow() } label: { Text("About MyApp") } // Command that opens settings using environment MenuCommand { openSettings() } label: { Text("Settings...") } Divider() // Command that doesn't dismiss menu MenuCommand("Keep Menu Open", dismissesMenu: false) { print("Menu stays open") } // Command that doesn't activate app MenuCommand("Background Action", activatesApp: false) { performBackgroundTask() } Divider() // Standard quit command MenuCommand("Quit") { NSApp.terminate(nil) } } } func showAboutWindow() { NSApp.sendAction( #selector(NSApplication.orderFrontStandardAboutPanel(_:)), to: nil, from: nil ) } func performBackgroundTask() { // Background work without bringing app to front } } ``` -------------------------------- ### MenuList - List with Selection Support Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Renders a collection of menu items with single-item selection support. Works with any Hashable and Identifiable collection. Dependencies: MacControlCenterUI framework, SwiftUI. Input: Array of menu items, optional selection binding. Output: Interactive menu list with selection state management. Limitations: Requires proper item configuration and Hashable conformance. ```swift import MacControlCenterUI import SwiftUI struct MenuEntry: Identifiable, Hashable { let id = UUID() let name: String let image: Image } struct AudioOutputMenu: View { @State private var audioOutputs: [MenuEntry] = [ MenuEntry(name: "MacBook Pro Speakers", image: Image(systemName: "hifispeaker.fill")), MenuEntry(name: "AirPods Max", image: Image(systemName: "airpodspro")), MenuEntry(name: "Studio Display", image: Image(systemName: "display")), MenuEntry(name: "HDMI Output", image: Image(systemName: "tv")) ] @State private var selection: UUID? = nil var body: some View { VStack { MenuSection("Audio Output") // Simple list without selection MenuList(audioOutputs) { item in MenuToggle(image: item.image) { Text(item.name) } } // List with single selection binding MenuList(audioOutputs, selection: $selection) { item in MenuToggle(image: item.image) { Text(item.name) } } // List with custom selection handling and additional content MenuList(audioOutputs, selection: $selection) { item, isSelected, itemClicked in MenuToggle(isOn: .constant(isSelected), image: item.image) { HStack { Text(item.name) Spacer() if item.name.contains("AirPods") { HStack(spacing: 2) { Text("82%") Image(systemName: "battery.75", variableValue: 0.82) } .font(.system(size: 10)) .opacity(0.7) } } } onClick: { _ in itemClicked() print("Selected: \(item.name)") } } } } } ``` -------------------------------- ### MenuCircleButton Momentary Action Implementation Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Complete SwiftUI implementation showing MenuCircleButton usage for prominent action buttons and media controls. Demonstrates control size configuration, custom styling with system images and colors, and integration with view body structure. Suitable for creating consistent circular action buttons in macOS control center interfaces. ```swift import MacControlCenterUI import SwiftUI struct ActionButtonsMenu: View { var body: some View { VStack { // Prominent action button MenuCircleButton( controlSize: .prominent, style: .init( image: Image.systemName: "arrow.clockwise"), color: .blue ) ) { Text("Refresh") } onClick: { performRefresh() } // Row of action buttons HStack { MenuCircleButton( controlSize: .prominent, style: .init( image: Image(systemName: "play.fill"), color: .green ) ) { Text("Play") } onClick: { playMedia() } MenuCircleButton( controlSize: .prominent, style: .init( image: Image(systemName: "stop.fill"), color: .red ) ) { Text("Stop") } onClick: { stopMedia() } } } } } ``` -------------------------------- ### Build Styled Containers in SwiftUI MenuPanel Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt A container with rounded rectangles, shadows, and borders that adapts to dark/light modes automatically. Depends on MacControlCenterUI and SwiftUI. Takes view content as children and outputs a styled panel. Ideal for grouping UI elements, but styling may vary across macOS versions and requires SwiftUI compatibility. ```Swift import MacControlCenterUI import SwiftUI struct CustomControlsMenu: View { @State private var value1: CGFloat = 0.5 @State private var value2: CGFloat = 0.3 var body: some View { VStack(spacing: 12) { // Panel containing grouped controls MenuPanel { VStack(spacing: 8) { MenuSlider("Control 1", value: $value1) MenuSlider("Control 2", value: $value2) } .padding(12) } // Panel with custom content MenuPanel { HStack { VStack(alignment: .leading) { Text("Status") .font(.headline) Text("Everything is working") .font(.caption) .opacity(0.7) } Spacer() Image(systemName: "checkmark.circle.fill") .foregroundColor(.green) .font(.title2) } .padding(12) } } } } ``` -------------------------------- ### MenuToggle - Full-Width Toggle Menu Item Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Creates full-width menu items with toggle functionality. Supports custom icons, styles, and callback handlers. Works with MenuList selection. Dependencies: MacControlCenterUI framework, SwiftUI. Input: Boolean binding for state, optional image and style configuration. Output: Interactive toggle menu item. Limitations: Requires macOS 11+ and MacControlCenterUI library. ```swift import MacControlCenterUI import SwiftUI struct AppTogglesMenu: View { @State private var safari: Bool = true @State private var music: Bool = false @State private var xcode: Bool = false var body: some View { VStack { MenuSection("Applications") // Basic toggle with text label MenuToggle("Enable Feature", isOn: $safari) // Toggle with system icon MenuToggle( isOn: $music, image: Image(systemName: "music.note") ) { Text("Music") } // Toggle with custom app icon using bundle identifier MenuToggle( "Safari", isOn: $safari, style: .icon(appIcon(for: "com.apple.Safari")) ) MenuToggle( "Xcode", isOn: $xcode, style: .icon(appIcon(for: "com.apple.dt.Xcode")) ) { newValue in print("Xcode enabled: \(newValue)") } // Toggle with checkmark style (useful in nested menus) MenuToggle( isOn: $music, style: .checkmark() ) { HStack { Image(systemName: "music.note") Text("Adaptive Audio") .font(.system(size: 12)) Spacer() } } } } func appIcon(for bundleID: String) -> Image { if let path = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleID)?.path, let icon = NSWorkspace.shared.icon(forFile: path) { return Image(nsImage: icon) } return Image(systemName: "app") } } ``` -------------------------------- ### SwiftUI MenuDisclosureGroup - Expandable Sections Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Demonstrates the use of MenuDisclosureGroup for creating expandable/collapsible sections with various styles and toggle visibility options. It uses SwiftUI and MacControlCenterUI to organize nested content, including toggles and menu items. ```swift import MacControlCenterUI import SwiftUI struct NestedOptionsMenu: View { @State private var airPodsExpanded = false @State private var spatialAudio: Bool = true @State private var noiseCancellation: Bool = true @State private var transparency: Bool = false @State private var airPodsOptions: [MenuEntry] = [ MenuEntry(name: "Spatial Audio", image: Image(systemName: "music.note")), MenuEntry(name: "Noise Cancellation", image: Image(systemName: "waveform")), MenuEntry(name: "Transparency", image: Image(systemName: "ear")) ] @State private var optionSelection: UUID? = nil var body: some View { VStack { // Basic disclosure group with section style MenuDisclosureGroup( style: .section, initiallyExpanded: true, label: { Text("Advanced Options") }, content: { MenuToggle("Option 1", isOn: $spatialAudio) \nMenuToggle("Option 2", isOn: $noiseCancellation) } ) // Disclosure group with menu item style and hover-only chevron MenuDisclosureGroup( style: .menuItem, initiallyExpanded: false, toggleVisibility: .onHover, label: { HStack { Image(systemName: "airpodspro") Text("AirPods Max") Spacer() Text("82%") Image(systemName: "battery.75") } }, content: { MenuToggle("Spatial Audio", isOn: $spatialAudio) \nMenuToggle("Noise Cancellation", isOn: $noiseCancellation) \nMenuToggle("Transparency", isOn: $transparency) } ) // Complex nested disclosure with MenuList HighlightingMenuDisclosureGroup( style: .menuItem, initiallyExpanded: false, labelHeight: .controlCenterIconItem, toggleVisibility: .always, label: { MenuCircleToggle(isOn: .constant(true)) { HStack { Image(systemName: "airpodspro") Text("AirPods Max") Spacer() HStack(spacing: 2) { Text("82%") Image(systemName: "battery.75", variableValue: 0.82) } .frame(height: 10) .opacity(0.7) } } }, content: { MenuList(airPodsOptions, selection: $optionSelection) { item in MenuToggle(isOn: .constant(false), style: .checkmark()) { HStack { item.image Text(item.name).font(.system(size: 12)) Spacer() } } } ) } } } ``` -------------------------------- ### Swift - Selector Mapping Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt This snippet demonstrates how to map a selector used in macOS application structure to a nil value. It suggests using this for control interactions and SwiftUI state management. ```swift #selector(NSApplication.orderFrontStandardAboutPanel(_:)), to: nil, from: nil ``` -------------------------------- ### Create circular toggle button with MenuCircleToggle (Swift) Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Implements a circular toggle button with on/off states, supporting different sizes (.menu/.prominent) and customizable colors/images. Requires MacControlCenterUI and SwiftUI frameworks. Handles state changes through bindings. ```swift import MacControlCenterUI import SwiftUI struct SystemTogglesMenu: View { @State private var darkMode: Bool = true @State private var nightShift: Bool = false @State private var trueTone: Bool = true @State private var wifi: Bool = true var body: some View { VStack { // Single prominent toggle with label MenuCircleToggle( "Dark Mode", isOn: $darkMode, controlSize: .prominent, style: .init( image: Image(systemName: "moon.fill"), color: .blue, invertForeground: true ) ) { newValue in print("Dark mode: " + newValue) } // Row of prominent toggles HStack { MenuCircleToggle( isOn: $nightShift, controlSize: .prominent, style: .init( image: Image(systemName: "sun.max.fill"), color: .orange ) ) { Text("Night Shift") } onClick: { _ in print("Night Shift toggled") } MenuCircleToggle( isOn: $trueTone, controlSize: .prominent, style: .init( image: Image(systemName: "sun.max.fill"), color: .blue ) ) { Text("True Tone") } } .frame(height: 80) // Small menu-size toggle MenuCircleToggle( "Wi-Fi", isOn: $wifi, controlSize: .menu, style: .init(image: Image(systemName: "wifi")) ) } } } ``` -------------------------------- ### MenuSlider - Horizontal Slider Control Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Shows the usage of the MenuSlider control, including variations with static icons, text labels, dynamic icons, and disabled states. It supports both static and dynamic images. ```swift import MacControlCenterUI import SwiftUI struct DisplayControlsMenu: View { @State private var brightness: CGFloat = 0.5 @State private var volume: CGFloat = 0.75 var body: some View { VStack { // Basic slider with static icon MenuSlider( value: $brightness, image: Image(systemName: "sun.max.fill") ) .frame(minWidth: 180) // Slider with text label MenuSlider("Brightness", value: $brightness) { Image(systemName: "sun.max.fill") } .frame(minWidth: 180) // Volume slider with dynamic icon that changes based on value // Automatically switches between mute, low, medium, and high volume icons MenuVolumeSlider(value: $volume) .frame(minWidth: 180) // Disabled slider MenuSlider(value: .constant(0.3), image: Image(systemName: "speaker.fill")) .disabled(true) .frame(minWidth: 180) } } } ``` -------------------------------- ### Create Collapsible Sections in SwiftUI MenuDisclosureSection Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt This component combines section labels with disclosure functionality to create collapsible sections in macOS Control Center UI. It depends on MacControlCenterUI and SwiftUI frameworks. It takes a header string, a binding for expansion state, and view content as children, outputting a styled disclosure group. Limitations include requirement for SwiftUI environment and may not function outside macOS. ```Swift import MacControlCenterUI import SwiftUI struct NetworkMenu: View { @State private var wifiExpanded = true @State private var wifiNetworks: [MenuEntry] = [ MenuEntry(name: "Home Network", image: Image(systemName: "wifi")), MenuEntry(name: "Guest Network", image: Image(systemName: "wifi")), MenuEntry(name: "Office WiFi", image: Image(systemName: "wifi")), MenuEntry(name: "Coffee Shop", image: Image(systemName: "wifi")) ] @State private var wifiSelection: UUID? = nil var body: some View { VStack { // Disclosure section with scrollable content MenuDisclosureSection("Wi-Fi Networks", isExpanded: $wifiExpanded) { MenuScrollView(maxHeight: 135) { MenuList(wifiNetworks, selection: $wifiSelection) { item in MenuToggle(image: item.image) { Text(item.name) } } } } // Disclosure section with static content MenuDisclosureSection("Bluetooth Devices", isExpanded: .constant(false)) { MenuToggle("AirPods", isOn: .constant(true)) MenuToggle("Magic Mouse", isOn: .constant(true)) MenuToggle("Keyboard", isOn: .constant(false)) } } } } ``` -------------------------------- ### Implement Scrollable Views in SwiftUI MenuScrollView Source: https://context7.com/orchetect/maccontrolcenterui/llms.txt Provides a scrollable container with automatic chevron indicators when content overflows. Relies on MacControlCenterUI and SwiftUI. Accepts a max height parameter and view content, rendering a scrollable area with custom indicators. Suitable for lists or custom content, but chevrons only appear on overflow and may not work in all SwiftUI environments. ```Swift import MacControlCenterUI import SwiftUI struct ScrollableListMenu: View { @State private var items: [MenuEntry] = (1...20).map { MenuEntry(name: "Item \($0)", image: Image(systemName: "circle")) } @State private var selection: UUID? = nil var body: some View { VStack { MenuSection("Long List") // Scrollable list with automatic chevron indicators MenuScrollView(maxHeight: 150) { MenuList(items, selection: $selection) { item in MenuToggle(image: item.image) { Text(item.name) } } } // Scrollable custom content MenuScrollView(maxHeight: 200) { VStack(spacing: 8) { ForEach(1...30, id: \.self) { index in Text("Scrollable item \(index)") .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 8) } } } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.