All Projects → BurntCaramel → Burntcocoaui

BurntCaramel / Burntcocoaui

Licence: mit
Use Swift enums and structs with NSMenu, NSPopUpButton, NSSegmentedControl

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Burntcocoaui

Googletranslate
🌐 Google 翻译 Mac 客户端
Stars: ✭ 688 (+2652%)
Mutual labels:  mac
Nuclear
Streaming music player that finds free music for you
Stars: ✭ 7,133 (+28432%)
Mutual labels:  mac
Security Growler
📡 A Mac menubar app that notifies you whenever SSH, VNC, sudo, or other auth events occur.
Stars: ✭ 829 (+3216%)
Mutual labels:  mac
Motrix
A full-featured download manager.
Stars: ✭ 29,357 (+117328%)
Mutual labels:  mac
Macapps
个人收集的一些mac使用的不易找到的app,不断更新中。
Stars: ✭ 726 (+2804%)
Mutual labels:  mac
Tf Coriander
OpenCL 1.2 implementation for Tensorflow
Stars: ✭ 775 (+3000%)
Mutual labels:  mac
Struct
Xcode projects on steroids
Stars: ✭ 684 (+2636%)
Mutual labels:  mac
Quark Shell Mac
Quark Shell for Mac helps web developers to create native-like Mac menubar app using HTML and JavaScript without writing any native code.
Stars: ✭ 917 (+3568%)
Mutual labels:  mac
Gifcapture
🏇 Gif capture app for macOS
Stars: ✭ 754 (+2916%)
Mutual labels:  mac
Echo
Echo是一款桌面端调试工具,旨在提高客户端的研发调试效率
Stars: ✭ 818 (+3172%)
Mutual labels:  mac
Open Source Mac Os Apps
🚀 Awesome list of open source applications for macOS. https://t.me/s/opensourcemacosapps
Stars: ✭ 28,908 (+115532%)
Mutual labels:  mac
Rome
Carthage cache for S3, Minio, Ceph, Google Storage, Artifactory and many others
Stars: ✭ 724 (+2796%)
Mutual labels:  mac
Mac Setup
Installing Development environment on macOS
Stars: ✭ 6,510 (+25940%)
Mutual labels:  mac
Marshal
Marshaling the typeless wild west of [String: Any]
Stars: ✭ 694 (+2676%)
Mutual labels:  mac
Infinity Dashboard Modules
Infinity Dashboard Modules
Stars: ✭ 17 (-32%)
Mutual labels:  mac
Soundcast
Cast audio from macOS to Chromecast
Stars: ✭ 684 (+2636%)
Mutual labels:  mac
Swiftui
A collaborative list of awesome SwiftUI resources. Feel free to contribute!
Stars: ✭ 774 (+2996%)
Mutual labels:  mac
Electron Widevinecdm
WidevineCDM for Electron
Stars: ✭ 24 (-4%)
Mutual labels:  mac
Blue
Easily switch bluetooth peripherals between multiple macs
Stars: ✭ 18 (-28%)
Mutual labels:  mac
Macsvg
macSVG - An open-source macOS app for designing HTML5 SVG (Scalable Vector Graphics) art and animation with a WebKit web view ➤➤➤
Stars: ✭ 789 (+3056%)
Mutual labels:  mac

BurntCocoaUI

Declarative assistants to make NSMenu, NSPopUpButton, NSSegmentedControl easier. Use Swift enums instead of creating and removing NSMenuItems and fiddling with indexes and tags.

Example

NSPopUpMenu with PopUpButtonAssistant

The choices you want to show in the menu, as an enum.

enum BaseContentTypeChoice: Int {
	case LocalHTMLPages = 1
	case Images
	case Feeds
}

Add an extension to the enum to make it conform to the UIChoiceRepresentative protocol.

extension BaseContentTypeChoice: UIChoiceRepresentative {
	var title: String {
		switch self {
		case .LocalHTMLPages:
			return "Local Pages"
		case .Images:
			return "Images"
		case .Feeds:
			return "Feeds"
		}
	}
	
	typealias UniqueIdentifier = BaseContentTypeChoice
	var uniqueIdentifier: UniqueIdentifier { return self }
}

Use PopUpButtonAssistant in View Controller, with customized menu item titles.

class ExampleViewController: NSViewController {
  
	@IBOutlet var baseContentTypeChoicePopUpButton: NSPopUpButton! // Hooked up in storyboard/nib
	var baseContentTypeChoicePopUpButtonAssistant: PopUpButtonAssistant<BaseContentTypeChoice>!

	var chosenBaseContentChoice: BaseContentTypeChoice = .LocalHTMLPages
	

	var baseContentTypeChoiceMenuItemRepresentatives: [BaseContentTypeChoice?] {
		return [
			.LocalHTMLPages,
			.Images,
			.Feeds
		]
	}
	
	func updateBaseContentTypeChoiceUI() {
		let popUpButtonAssistant = baseContentTypeChoicePopUpButtonAssistant ?? {
			let popUpButtonAssistant = PopUpButtonAssistant<BaseContentTypeChoice>(popUpButton: baseContentTypeChoicePopUpButton)
			
			let menuAssistant = popUpButtonAssistant.menuAssistant
			// Customize the title by appending a total count
			menuAssistant.customization.title = { choice in
				let baseContentType = choice.baseContentType
				let loadedURLCount = self.pageMapper?.numberOfLoadedURLsWithBaseContentType(baseContentType) ?? 0
				return "\(choice.title) (\(loadedURLCount))"
			}
			
			self.baseContentTypeChoicePopUpButtonAssistant = popUpButtonAssistant
			return popUpButtonAssistant
		}()
		
		popUpButtonAssistant.menuItemRepresentatives = baseContentTypeChoiceMenuItemRepresentatives
		popUpButtonAssistant.update()
	}
	
	@IBAction func changeBaseContentTypeFilter(sender: NSPopUpButton) {
		if let contentChoice = baseContentTypeChoicePopUpButtonAssistant.selectedItemRepresentative {
			chosenBaseContentChoice = contentChoice
			
			reloadData()
		}
	}
	
	func reloadData() {
		// Example ...
	}
}

Installation

To integrate into your Xcode project using Carthage, specify it in your Cartfile:

github "BurntCaramel/BurntCocoaUI" >= 0.3

Origin

My Mac app Lantern: http://www.burntcaramel.com/lantern/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].