Hover edge insets

This commit is contained in:
Ivan Sapozhnik
2020-04-22 22:44:53 +02:00
parent e6801e978a
commit c71aaecd87
4 changed files with 19 additions and 1 deletions
+1
View File
@@ -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 }
+2 -1
View File
@@ -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)
+11
View File
@@ -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
}
}
+5
View File
@@ -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
}