diff --git a/cocoa/NSMenuItem.go b/cocoa/NSMenuItem.go index 44413051..01194428 100644 --- a/cocoa/NSMenuItem.go +++ b/cocoa/NSMenuItem.go @@ -79,6 +79,12 @@ func (i NSMenuItem) SetTitle(s string) { i.Set("title:", core.String(s)) } +// SetAttributedTitle sets a custom string for the menu item's title. +// https://developer.apple.com/documentation/appkit/nsmenuitem/1514860-attributedtitle?language=objc +func (i NSMenuItem) SetAttributedTitle(s string) { + i.Set("attributedTitle:", core.NSAttributedString_FromString(s)) +} + // Image returns the menu item’s image. // https://developer.apple.com/documentation/appkit/nsmenuitem/1514819-image?language=objc func (i NSMenuItem) Image() NSImage { diff --git a/core/NSAttributedString.go b/core/NSAttributedString.go new file mode 100644 index 00000000..60e6d66c --- /dev/null +++ b/core/NSAttributedString.go @@ -0,0 +1,25 @@ +package core + +import ( + "github.com/progrium/macdriver/objc" +) + +// Wrapper for NSAttributedString +// https://developer.apple.com/documentation/foundation/nsattributedstring?language=objc +type NSAttributedString struct { + objc.Object +} + +var nsAttributedString = objc.Get("NSAttributedString") + +// NSAttributedString_FromString returns an initialized NSAttributedString +// https://developer.apple.com/documentation/foundation/nsattributedstring/1407481-initwithstring?language=objc +func NSAttributedString_FromString(str string) NSAttributedString { + nsstr := NSString_FromString(str) + obj := nsAttributedString.Alloc().Send("initWithString:", nsstr) + return NSAttributedString_FromObject(obj) +} + +func NSAttributedString_FromObject(obj objc.Object) NSAttributedString { + return NSAttributedString{obj} +} diff --git a/core/NSString.go b/core/NSString.go index e99ecf2e..53eb0089 100644 --- a/core/NSString.go +++ b/core/NSString.go @@ -11,7 +11,7 @@ const ( NSUTF8StringEncoding = 4 ) -// Wrapper for NSPasteboard +// Wrapper for NSString // https://developer.apple.com/documentation/foundation/nsstring?language=occ type NSString struct { objc.Object