Hover edge insets
This commit is contained in:
@@ -64,6 +64,7 @@ public protocol Configuration {
|
||||
var menuItemTextColor: NSColor { get }
|
||||
var menuItemHoverTextColor: NSColor { get }
|
||||
var menuItemHoverCornerRadius: CGFloat { get }
|
||||
var menuItemHoverEdgeInsets: NSEdgeInsets { get }
|
||||
var menuItemCheckmarkColor: NSColor { get }
|
||||
var menuItemHoverCheckmarkColor: NSColor { get }
|
||||
var menuItemCheckmarkHeight: CGFloat { get }
|
||||
|
||||
@@ -30,7 +30,8 @@ class Control: NSControl {
|
||||
|
||||
override func layout() {
|
||||
super.layout()
|
||||
hoverLayer.path = CGPath(roundedRect: bounds, cornerWidth: configuration.menuItemHoverCornerRadius, cornerHeight: configuration.menuItemHoverCornerRadius, transform: nil)
|
||||
let newRect = bounds.inset(by: configuration.menuItemHoverEdgeInsets)
|
||||
hoverLayer.path = CGPath(roundedRect: newRect, cornerWidth: configuration.menuItemHoverCornerRadius, cornerHeight: configuration.menuItemHoverCornerRadius, transform: nil)
|
||||
|
||||
if let trackingArea = trackingArea, trackingAreas.contains(trackingArea) {
|
||||
removeTrackingArea(trackingArea)
|
||||
|
||||
@@ -190,3 +190,14 @@ extension CGFloat {
|
||||
/// 48 points
|
||||
static let grid6: CGFloat = 48.0
|
||||
}
|
||||
|
||||
extension NSRect {
|
||||
func inset(by insets: NSEdgeInsets) -> NSRect {
|
||||
var newRect = self
|
||||
newRect.origin.x += insets.left
|
||||
newRect.size.width -= insets.left + insets.right
|
||||
newRect.origin.y += insets.top
|
||||
newRect.size.height -= insets.top + insets.bottom
|
||||
return newRect
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ public protocol Configuration {
|
||||
var menuItemTextColor: NSColor { get }
|
||||
var menuItemHoverTextColor: NSColor { get }
|
||||
var menuItemHoverCornerRadius: CGFloat { get }
|
||||
var menuItemHoverEdgeInsets: NSEdgeInsets { get }
|
||||
var menuItemCheckmarkColor: NSColor { get }
|
||||
var menuItemHoverCheckmarkColor: NSColor { get }
|
||||
var menuItemCheckmarkHeight: CGFloat { get }
|
||||
@@ -173,6 +174,10 @@ open class MenuConfiguration: Configuration {
|
||||
return .white
|
||||
}
|
||||
|
||||
open var menuItemHoverEdgeInsets: NSEdgeInsets {
|
||||
return NSEdgeInsets.zero
|
||||
}
|
||||
|
||||
open var menuItemHoverCornerRadius: CGFloat {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user