Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout overflow issue of popover #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions SpotMenu/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private enum Constants {
static let statusItemIconLength: CGFloat = 30
static let statusItemLength: CGFloat = 250
static let menubarHeight: CGFloat = 22
}

// MARK: - Properties
Expand Down Expand Up @@ -311,13 +312,27 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}

private func showPopover(_: AnyObject?) {

let popoverWidth = PopOverViewController.Constants.width
let popoverHeight = PopOverViewController.Constants.height

let rect = statusItem.button?.window?.convertToScreen((statusItem.button?.frame)!)
let menubarHeight = rect?.height ?? 22
let height = hiddenController?.window?.frame.height ?? 300
let xOffset = UserPreferences.fixPopoverToTheRight ? ((hiddenController?.window?.contentView?.frame.minX)! - (statusItem.button?.frame.minX)!) : ((hiddenController?.window?.contentView?.frame.midX)! - (statusItem.button?.frame.midX)!)
let x = (rect?.origin.x)! - xOffset
let menubarHeight = rect?.height ?? Constants.menubarHeight
let height = hiddenController?.window?.frame.height ?? popoverHeight
let xOffset = UserPreferences.fixPopoverToTheRight
? ((hiddenController?.window?.contentView?.frame.minX)! - (statusItem.button?.frame.minX)!)
: ((hiddenController?.window?.contentView?.frame.midX)! - (statusItem.button?.frame.midX)!)
var x = (rect?.origin.x)! - xOffset
let y = (rect?.origin.y)! // - (hiddenController?.contentViewController?.view.frame.maxY)!

if let screen = NSScreen.main {
let width = x + popoverWidth
let maxWidth = screen.frame.size.width
if width > maxWidth {
x = maxWidth - popoverWidth
}
}

hiddenController?.window?.setFrameOrigin(NSPoint(x: x, y: y-height+menubarHeight))
hiddenController?.showWindow(self)
eventMonitor?.start()
Expand Down
10 changes: 9 additions & 1 deletion SpotMenu/PopOver/PopOverVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ final class PopOverViewController: NSViewController {
@IBOutlet private var rightTime: NSTextField!
@IBOutlet private var musicPlayerButton: NSButton!

public enum Constants {
static let width: CGFloat = 300
static let height: CGFloat = 300
}

// MARK: - Lifecycle methods

override func viewDidLoad() {
super.viewDidLoad()

defaultImage = artworkImageView.image
preferredContentSize = NSSize(width: 300, height: 300)
preferredContentSize = NSSize(
width: Constants.width,
height: Constants.height
)

if #available(OSX 10.13, *) {
view.layer?.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
Expand Down