EnlightenPopover
open class EnlightenPopover : NSPopover, NSPopoverDelegate
A sizeable, detachable, and fitting, popover that renders a Markdown string.
-
The view relative to which the popover should be positioned.
Declaration
Swift
public weak var positioningView: NSView?
-
The edge of
positioningView
the popover should prefer to be anchored to.Declaration
Swift
public var preferredEdge: NSRectEdge?
-
Whether the popover is fitted within
positioningView
‘s window.Declaration
Swift
public var fitInWindow: Bool
-
The padding between the popover and window frame when
fitInWindow
is true.Declaration
Swift
public var windowInnerPadding: CGFloat
-
Whether the popover is detachable.
Declaration
Swift
public var canDetach: Bool
-
The maximum width of the popover.
Declaration
Swift
public var maxWidth: CGFloat { get set }
-
The popover’s content view controller.
Declaration
Swift
public var popoverContentViewController: EnlightenPopoverContentViewController { get }
-
The popover’s
EnlightenPopoverDelegate
delegate.Declaration
Swift
public var enlightenPopoverDelegate: EnlightenPopoverDelegate? { get set }
-
The maximum height of the popover.
Scrolling is enabled if the
EnlightenDownView
exceeds the maximum height.Declaration
Swift
public var maxHeight: CGFloat { get set }
-
Whether the Markdown content should be center aligned.
Declaration
Swift
public var doesCenterAlignContent: Bool { get set }
-
Initializes a newly allocated Enlighten popover.
Throws
Throws aDownErrors
if loading the Markdown string fails.Declaration
Swift
public init(markdownString: String, maxWidth: CGFloat, maxHeight: CGFloat = 500) throws
Parameters
markdownString
The Markdown string rendered in the popover.
maxWidth
The maximum width of the popover.
maxHeight
The maximum height of the popover.
-
Undocumented
Declaration
Swift
public convenience init(maxWidth: CGFloat, maxHeight: CGFloat = 500)
-
Undocumented
Declaration
Swift
public required init?(coder: NSCoder)
-
Resets the width of the popover’s
EnlightenDownView
.Used during a Markdown string update.
Declaration
Swift
open func resetDownViewWidth()
-
Resets the width of the popover’s content and
EnlightenDownView
to the original maximum width.Used during a Markdown string update.
Declaration
Swift
open func resetWidth()
-
Resizes the popover’s content size so that it is the minimum size needed to contain its
EnlightenDownView
.If the
fitInWindow
property is true, this method will attempt to fit theEnlightenDownView
within the window frame.Declaration
Swift
open func sizeToFit()
-
Updates the positioning rectangle of a shown popover.
Note: The popover’s position only needs to be updated programmatically if
show(relativeTo:in:preferredEdge:)
was used to present the popover.Declaration
Swift
open func updatePositionIfShown(to positioningRect: NSRect)
Parameters
positioningRect
The new positioning rectangle for the popover.
-
Presents the popover if needed.
This is determined by the
needsToShowPopover
property and ensures the Markdown has finished loading.Declaration
Swift
open func showPopoverIfNeeded()
-
Shows the popover anchored to the specified view. Uses a heuristic method to determine the best anchoring edge.
Declaration
Swift
open func show(relativeTo positioningView: NSView)
Parameters
positioningView
The anchoring view.
-
Shows the popover anchored to a positioning frame in a content view.
If the popover’s Markdown content is not loaded, will wait for it to finish before showing the popover.
Declaration
Swift
open func show(relativeTo positioningRectInWindow: NSRect, in contentView: NSView, preferredEdge: NSRectEdge)
Parameters
positioningRectInWindow
The rectangle within
contentView
relative to which the popover should be positioned.contentView
The window content view relative to which the popover should be positioned.
preferredEdge
The edge of
positioningRectInWindow
the popover should prefer to be anchored to. -
Shows the popover anchored to the specified view.
Unlike the other presentation methods, this one shows the popover regardless of the popover’s content loading state .
Declaration
Swift
open func showLoaded(relativeTo positioningRect: NSRect, of positioningView: NSView, preferredEdge: NSRectEdge)
Parameters
positioningRect
The rectangle within positioningView relative to which the popover should be positioned.
positioningView
The view relative to which the popover should be positioned.
preferredEdge
The edge of positioningView the popover should prefer to be anchored to.
-
Renders the given CommonMark Markdown string into HTML, updates the
EnlightenDownView
while keeping the style intact, and resizes the popover’s content size.Important
Errors thrown during the loading of the Markdown string are passed to the delegate’s
EnlightenPopoverDelegate.enlightenPopoverFailedToLoad(downError:)
method.Declaration
Swift
open func update(markdownString: String, shouldCenterAlign: Bool = false, newMaxWidth: CGFloat? = nil, waitForPopoverClosure: Bool = false)
Parameters
markdownString
A string containing CommonMark Markdown.
shouldCenterAlign
Whether the Markdown content should be center aligned.
newMaxWidth
The new max width of the popover.
waitForPopoverClosure
Whether to wait for the popover to close before updating. The default value is
false
.
-
A heuristic method for determining the best anchor edge for a view.
The window quadrant the view is located in is used to determine the best edge.
Declaration
Swift
open func bestEdge(for view: NSView) -> NSRectEdge
Parameters
view
The anchoring view.
Return Value
The best anchoring edge for the view.
-
Undocumented
Declaration
Swift
open func popoverShouldDetach(_ popover: NSPopover) -> Bool
-
Undocumented
Declaration
Swift
open func popoverWillShow(_ notification: Notification)
-
Undocumented
Declaration
Swift
open func popoverDidClose(_ notification: Notification)
-
Shows the popover anchored to the specified view.
If the popover’s Markdown content is not loaded, will wait for it to finish before showing the popover.
Declaration
Swift
override open func show(relativeTo positioningRect: NSRect, of positioningView: NSView, preferredEdge: NSRectEdge)
Parameters
positioningRect
The rectangle within positioningView relative to which the popover should be positioned.
positioningView
The view relative to which the popover should be positioned.
preferredEdge
The edge of positioningView the popover should prefer to be anchored to.
-
Undocumented
Declaration
Swift
override open func close()