Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inket/mbpopup
macOS status bar popups done right 😎
https://github.com/inket/mbpopup
carthage cocoapods framework macos popup status-bar swift
Last synced: about 1 month ago
JSON representation
macOS status bar popups done right 😎
- Host: GitHub
- URL: https://github.com/inket/mbpopup
- Owner: inket
- License: mit
- Created: 2016-08-25T06:59:24.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-08T04:04:02.000Z (over 1 year ago)
- Last Synced: 2024-11-10T23:04:15.283Z (2 months ago)
- Topics: carthage, cocoapods, framework, macos, popup, status-bar, swift
- Language: Swift
- Homepage:
- Size: 104 KB
- Stars: 109
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## MBPopup
![](https://img.shields.io/badge/Swift-5.8-orange.svg) ![](https://img.shields.io/badge/SwiftPM-supported-brightgreen.svg)MBPopup is a macOS framework for easily adding a customizable status bar popup to your apps.
MBPopup is based on [Popup by shpakovski](https://github.com/shpakovski/Popup),
after it had been used in [HAPU](https://mahdi.jp/apps/hapu) for 3+ years and incrementally improved on,
and is now rewritten for Swift and improved for the Swift era.More importantly, multiple parts have been rewritten in order to replicate the behavior of system menu bar items:
- Opens with the right event
- Closes on escape
- Allows peeking (hold click to open then release to close)
- Opens in the correct screen when clicked from a different (in)active screen
- Changes focus as expected
- etc.While also,
- Reacting to Auto Layout constraints as expected
- Providing callbacks for user actions
- Allowing for different states when modifier keys are usedMBPopup is App Store-approved and is currently being used in the app [stts](https://itunes.apple.com/app/stts/id1187772509?ls=1&mt=12):
### Usage
(For more examples, check the __Example__ project, or [stts' source](https://github.com/inket/stts))
1. Add MBPopup via Swift Package Manager
2. Use MBPopup in your app:
```swift
import MBPopuplet myView = NSView(frame: CGRect(x: 0, y: 0, width: 200, height: 300))
let popupController = MBPopupController(contentView: myView)// Use popupController.statusItem to customize the NSStatusItem, set a title or an image
popupController.statusItem.button?.title = "Test"
popupController.statusItem.length = 70// Use popupController.backgroundView to customize the popup's background
popupController.backgroundView.backgroundColor = NSColor.windowBackgroundColor // Default value// Customize animations, view sizes
popupController.openDuration = 0.15 // Default value
popupController.closeDuration = 0.2 // Default value
popupController.arrowSize = CGSize(width: 12, height: 8) // Default value
popupController.contentInset = 1 // Default value// Use callbacks to user actions (optional)
popupController.shouldOpenPopup = { keys in return true }
popupController.willOpenPopup = { keys in debugPrint("Will open popup!") }
popupController.didOpenPopup = { debugPrint("Opened popup!") }
popupController.willClosePopup = { debugPrint("Will close popup!") }
popupController.didClosePopup = { debugPrint("Closed popup!") }// Resize your popup to your liking
popupController.resizePopup(width: 300, height: 400)
```#### Contact
[@inket](https://github.com/inket) / [@inket](https://mastodon.social/inket) on Mastodon / [mahdi.jp](https://mahdi.jp)